1 /** 2 Copyright: Copyright (c) 2017-2018 Andrey Penechko. 3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0). 4 Authors: Andrey Penechko. 5 */ 6 module voxelman.container.hash.set; 7 8 import std.experimental.allocator.gc_allocator; 9 import voxelman.container.hash.hashtableparts; 10 import voxelman.container.hash.keybucket; 11 12 struct HashSet(Key, Key emptyKey, Key deletedKey, Alloc = GCAllocator) 13 { 14 mixin HashTablePart!(KeyBucket!(Key, emptyKey, deletedKey), false); 15 } 16 17 struct HashSet(Key, Alloc = GCAllocator) 18 { 19 mixin HashTablePart!(MetaKeyBucket!(Key), false); 20 } 21 22 unittest { 23 void test(M)() 24 { 25 M map; 26 map.put(2); // placed in bucket 0 27 map.reserve(1); // capacity 2 -> 4, must be placed in bucket 2 28 assert(map[2]); 29 } 30 31 test!(HashSet!(ushort, ushort.max, ushort.max-1)); 32 test!(HashSet!(ushort)); 33 } 34 35 unittest { 36 import std.string; 37 void test(M)() 38 { 39 M map; 40 ushort[] keys = [140,268,396,524,652,780,908,28,156,284, 41 412,540,668,796,924,920,792,664,536,408,280,152,24]; 42 43 foreach (i, ushort key; keys) { 44 assert(map.length == i); 45 map.put(key); 46 } 47 48 foreach (i, ushort key; keys) { 49 assert(map.length == keys.length - i); 50 map.remove(key); 51 } 52 53 foreach (i, ushort key; keys) { 54 assert(map.length == i); 55 map.put(key); 56 } 57 } 58 59 import std.stdio; 60 61 test!(HashSet!(ushort, ushort.max, ushort.max-1)); 62 test!(HashSet!(ushort)); 63 }