1 /** 2 * Templates for container node types. 3 * Copyright: © 2015 Economic Modeling Specialists, Intl. 4 * Authors: Brian Schott 5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) 6 */ 7 module containers.internal.node; 8 9 template fatNodeCapacity(size_t bytesPerItem, size_t pointerCount, 10 T, size_t cacheLineSize = 64) 11 { 12 enum size_t optimistic = (cacheLineSize 13 - ((void*).sizeof * pointerCount) - T.sizeof) / bytesPerItem; 14 static if (optimistic > 0) 15 enum fatNodeCapacity = optimistic; 16 else 17 enum fatNodeCapacity = 1; 18 } 19 20 // Double linked fat node of int with bookkeeping in a uint should be able to 21 // hold 11 ints per node. 22 // 64 - 16 - 4 = 4 * 11 23 version (X86_64) 24 static assert (fatNodeCapacity!(int.sizeof, 2, uint) == 11); 25 26 template shouldNullSlot(T) 27 { 28 import std.traits; 29 enum shouldNullSlot = isPointer!T || is (T == class); 30 } 31 32 template shouldAddGCRange(T) 33 { 34 import std.traits; 35 enum shouldAddGCRange = isPointer!T || hasIndirections!T || is (T == class); 36 } 37 38 static assert (shouldAddGCRange!string); 39 static assert (!shouldAddGCRange!int); 40 41 template fullBits(size_t n, size_t c = 0) 42 { 43 static if (c >= (n - 1)) 44 enum fullBits = (1 << c); 45 else 46 enum fullBits = (1 << c) | fullBits!(n, c + 1); 47 } 48 49 static assert (fullBits!1 == 1); 50 static assert (fullBits!2 == 3); 51 static assert (fullBits!3 == 7); 52 static assert (fullBits!4 == 15);