Convenience function to create and setup a MutexedAA instance in one go. MutexedAA.setup need as such not be called.
Convenience helper to instantiate a RehashingAA instance with an existing associative array.
Simple buffer/queue for storing and fetching items of any type T. Does not use manual memory allocation.
Simple circular-ish buffer for storing items of type T that discards elements when the maximum size is reached. Does not use manual memory allocation.
An associative array and a Mutex. Wraps associative array operations in mutex locks.
A wrapper around a native associative array that you can controllably set to automatically rehash as entries are added.
1 { 2 Buffer!string buffer; 3 4 buffer.put("abc"); 5 buffer.put("def"); 6 assert(!buffer.empty); 7 assert(buffer.front == "abc"); 8 buffer.popFront(); 9 assert(buffer.front == "def"); 10 buffer.popFront(); 11 assert(buffer.empty); 12 } 13 { 14 Buffer!(char, Yes.dynamic, 3) buffer; 15 16 assert(!buffer.buf.length); 17 buffer ~= 'a'; 18 assert(buffer.buf.length == 3); 19 buffer ~= 'b'; 20 buffer ~= 'c'; 21 assert(buffer.length == 3); 22 buffer ~= 'd'; 23 assert(buffer.buf.length > 3); 24 assert(buffer[0..5] == "abcd"); 25 buffer.clear(); 26 assert(buffer.empty); 27 } 28 { 29 CircularBuffer!(int, Yes.dynamic) buf; 30 buf.resize(3); 31 buf.put(1); 32 buf.put(2); 33 buf.put(3); 34 but.put(4); 35 assert(buf.front == 4); 36 assert(buf.buf == [ 4, 2, 3 ]); 37 }} 38 { 39 RehashingAA!(int[string]) aa; 40 aa.minimumNeededForRehash = 2; 41 42 aa["abc"] = 123; 43 aa["def"] = 456; 44 assert((aa.newKeysSinceLastRehash == 2), aa.newKeysSinceLastRehash.to!string); 45 assert((aa.numRehashes == 0), aa.numRehashes.to!string); 46 aa["ghi"] = 789; 47 assert((aa.numRehashes == 1), aa.numRehashes.to!string); 48 assert((aa.newKeysSinceLastRehash == 0), aa.newKeysSinceLastRehash.to!string); 49 aa.rehash(); 50 assert((aa.numRehashes == 2), aa.numRehashes.to!string); 51 52 auto realAA = cast(int[string])aa; 53 assert("abc" in realAA); 54 assert("def" in realAA); 55 56 auto alsoRealAA = aa.aaOf; 57 assert("ghi" in realAA); 58 assert("jkl" !in realAA); 59 60 auto aa2 = aa.dup; 61 aa2["jkl"] = 123; 62 assert("jkl" in aa2); 63 assert("jkl" !in aa); 64 } 65 { 66 MutexedAA!(string[int]) aa; 67 aa.setup(); // important! 68 69 aa[1] = "one"; 70 aa[2] = "two"; 71 aa[3] = "three"; 72 73 auto hasOne = aa.has(1); 74 assert(hasOne); 75 assert(aa[1] == "one"); 76 77 assert(aa[2] == "two"); 78 79 auto three = aa.get(3); 80 assert(three == "three"); 81 82 auto four = aa.get(4, "four"); 83 assert(four == "four"); 84 85 auto five = aa.require(5, "five"); 86 assert(five == "five"); 87 assert(aa[5] == "five"); 88 89 auto keys = aa.keys; 90 assert(keys.canFind(1)); 91 assert(keys.canFind(5)); 92 assert(!keys.canFind(6)); 93 94 auto values = aa.values; 95 assert(values.canFind("one")); 96 assert(values.canFind("four")); 97 assert(!values.canFind("six")); 98 99 aa.rehash(); 100 }
Containers of varying quality.