vibe.utils.array 51/346(14%) line coverage

      
10
20
30
40
50
60
70
80
90
100
110
120
130
140
150
160
170
180
190
200
210
220
230
240
250
260
270
280
290
300
310
320
330
340
350
360
370
380
390
400
410
420
430
440
450
460
470
480
490
500
510
5213
530
5413
5513
5613
570
580
590
600
6113
620
630
640
650
660
670
680
690
700
710
720
730
740
750
760
770
780
7913
8013
8113
8213
8313
840
8513
860
870
880
890
900
910
920
930
940
950
960
970
980
990
1000
1010
10213
1030
1040
1050
1060
10712
1086
1096
1100
1110
1120
1130
11433
11526
11626
1170
1180
1190
1200
1210
1220
12326
1240
1250
1260
1270
1280
1290
1300
1310
1320
1330
1340
1350
1360
1370
1380
1390
1400
1410
1420
1430
1440
1450
1460
1470
1480
1490
1500
1510
1520
1530
1540
1550
1560
1570
1580
1590
1600
1610
1620
1630
1640
1650
1660
1670
1680
1690
1700
1710
17239
1730
17413
17513
17613
1770
17813
1790
1800
1810
1820
1830
1840
1850
1860
1870
1880
1890
1900
1910
1920
1930
1940
1950
1960
1970
1980
1990
2000
2010
2020
2030
2040
2050
2060
2070
2080
2090
2100
2110
2120
2130
2140
2150
2160
2170
2180
2190
2200
2210
2220
2230
2240
2250
2260
2270
2280
2290
2300
2310
2320
2330
2340
2350
2360
2370
2380
2390
2400
2410
2420
2430
2440
2450
2460
2470
2480
2490
2500
2510
2520
2530
2540
2550
2560
2570
2580
2590
2600
2610
2620
2630
2640
2650
2660
2670
2680
2690
2700
2710
2720
2730
2740
2750
2760
2770
2780
2790
2800
2810
2820
2830
2840
2850
2860
2870
2880
2890
2900
2910
2920
2930
2940
2950
2960
2970
2980
2990
3000
3010
3020
3030
3040
3050
3060
3070
3080
3090
3100
3110
3120
3130
3140
3150
3160
3170
3180
3190
3200
3210
3220
3230
3240
3250
3260
3270
3280
3290
3300
3310
3320
3330
3340
3350
3360
3370
3380
3390
3400
3410
3420
3430
3440
3450
3460
3470
3480
3490
3500
3510
3520
3530
3540
3550
3560
3570
3580
3590
3600
3610
3620
3630
3640
3650
3660
3670
3680
3690
3700
3710
3720
3730
3740
3750
3760
3770
3780
3790
3800
3810
3820
3830
3840
3850
3860
3870
3880
3890
3900
3910
3920
3930
3940
3950
3960
3970
3980
3990
4000
4010
4020
4030
4040
4050
4060
4070
4080
4090
4100
4110
4120
4130
4140
4150
4160
4170
4180
4190
4200
4210
4220
4230
4240
4250
4260
4270
4280
4290
4300
4310
4320
4330
4340
4350
4360
4370
4380
4390
4400
4410
4420
4430
4440
4450
4460
4470
4480
4490
4500
4510
4520
4530
4540
4550
4560
4570
4580
4590
4600
4610
4620
4630
4640
4650
4660
4670
4680
4690
4700
4710
4720
4730
4740
4750
4760
4770
4780
4790
4800
4810
4820
4830
4840
4850
4860
4870
4880
4890
4900
4910
4920
4930
4940
4950
4960
4970
4980
4990
5000
5010
5020
5030
5040
5050
5060
5070
5080
5090
5100
5110
5120
5130
5140
5150
5160
5170
5180
5190
5200
5210
5220
5230
5240
5250
5260
5270
5280
5290
5300
5310
5320
5330
5340
5350
5360
5370
5380
5390
5400
5410
5420
5430
5440
5450
5460
5470
5480
5490
5500
5510
5520
5530
5540
5550
5560
5570
5580
5590
5600
5610
5620
5630
5640
5650
5660
5670
5680
5690
5700
5710
5720
5730
5740
5750
5760
5770
5780
5790
5800
5810
5820
5830
5840
5852
5860
5870
5880
5890
5900
5910
5920
5930
5940
5950
5960
5970
5980
5990
6000
6010
6020
6030
6040
6050
6060
6070
6080
6090
6100
6110
6120
6130
6140
6150
6160
6170
6180
6190
6200
6210
6220
6230
6240
6250
6260
6270
6280
6290
6300
6310
6320
6330
6340
6350
6360
6370
6380
6391
6400
6411
6420
6430
6440
6450
6460
6470
6480
6490
6500
6510
6520
6530
6540
6550
6560
6570
6580
6590
6600
6611596
66219196
66384
6640
6650
6660
6670
66884
6690
6701208
671324
6728
6738
6740
6750
6764520
6771480
67874
67974
6800
6810
6822
6830
6842
6850
6862
6872
6882
6892
6900
6910
6920
6930
6940
6950
6960
6970
6980
6992
7000
7010
7020
7030
7040
7050
7060
7070
7080
7090
7100
7110
7124
7134
7141
7151
7160
7170
7184
7190
7200
7210
7220
7230
7240
7250
7260
7270
7280
7290
7300
7310
7320
7330
7340
7350
7360
7370
7380
7390
7400
7410
7420
7430
7440
7450
7460
7470
7480
7490
7500
7510
7520
7530
7540
7550
7560
7570
7580
7590
7600
7610
7620
7630
7640
7650
7660
7670
7680
7690
7700
7710
7720
/** Utility functions for array processing Copyright: © 2012 RejectedSoftware e.K. License: Subject to the terms of the MIT license, as written in the included LICENSE.txt file. Authors: Sönke Ludwig */ module vibe.utils.array; import vibe.internal.utilallocator; import std.algorithm; import std.range : isInputRange, isOutputRange; import std.traits; static import std.utf; void removeFromArray(T)(ref T[] array, T item) { foreach( i; 0 .. array.length ) if( array[i] is item ){ removeFromArrayIdx(array, i); return; } } void removeFromArrayIdx(T)(ref T[] array, size_t idx) { foreach( j; idx+1 .. array.length) array[j-1] = array[j]; array.length = array.length-1; } enum AppenderResetMode { keepData, freeData, reuseData } struct AllocAppender(ArrayType : E[], E) { alias ElemType = Unqual!E; static assert(!hasIndirections!E && !hasElaborateDestructor!E); private { ElemType[] m_data; ElemType[] m_remaining; IAllocator m_alloc; bool m_allocatedBuffer = false; } this(IAllocator alloc, ElemType[] initial_buffer = null) { m_alloc = alloc; m_data = initial_buffer; m_remaining = initial_buffer; } @disable this(this); @property ArrayType data() { return cast(ArrayType)m_data[0 .. m_data.length - m_remaining.length]; } void reset(AppenderResetMode reset_mode = AppenderResetMode.keepData) { if (reset_mode == AppenderResetMode.keepData) m_data = null; else if (reset_mode == AppenderResetMode.freeData) { if (m_allocatedBuffer) m_alloc.deallocate(m_data); m_data = null; } m_remaining = m_data; } /** Grows the capacity of the internal buffer so that it can hold a minumum amount of elements. Params: amount = The minimum amount of elements that shall be appendable without triggering a re-allocation. */ void reserve(size_t amount) @trusted { size_t nelems = m_data.length - m_remaining.length; if (!m_data.length) { m_data = cast(ElemType[])m_alloc.allocate(amount*E.sizeof); m_remaining = m_data; m_allocatedBuffer = true; } if (m_remaining.length < amount) { debug { import std.digest.crc; auto checksum = crc32Of(m_data[0 .. nelems]); } if (m_allocatedBuffer) { void[] vdata = m_data; m_alloc.reallocate(vdata, (nelems+amount)*E.sizeof); m_data = () @trusted { return cast(ElemType[])vdata; } (); } else { auto newdata = cast(ElemType[])m_alloc.allocate((nelems+amount)*E.sizeof); newdata[0 .. nelems] = m_data[0 .. nelems]; m_data = newdata; m_allocatedBuffer = true; } debug assert(crc32Of(m_data[0 .. nelems]) == checksum); } m_remaining = m_data[nelems .. m_data.length]; } void put(E el) @safe { if( m_remaining.length == 0 ) grow(1); m_remaining[0] = el; m_remaining = m_remaining[1 .. $]; } void put(ArrayType arr) @safe { if (m_remaining.length < arr.length) grow(arr.length); m_remaining[0 .. arr.length] = arr[]; m_remaining = m_remaining[arr.length .. $]; } static if( !hasAliasing!E ){ void put(in ElemType[] arr) @trusted { put(cast(ArrayType)arr); } } static if( is(ElemType == char) ){ void put(dchar el) @safe { if( el < 128 ) put(cast(char)el); else { char[4] buf; auto len = std.utf.encode(buf, el); put(() @trusted { return cast(ArrayType)buf[0 .. len]; }()); } } } static if( is(ElemType == wchar) ){ void put(dchar el) @safe { if( el < 128 ) put(cast(wchar)el); else { wchar[3] buf; auto len = std.utf.encode(buf, el); put(() @trusted { return cast(ArrayType)buf[0 .. len]; } ()); } } } static if (!is(E == immutable) || !hasAliasing!E) { /** Appends a number of bytes in-place. The delegate will get the memory slice of the memory that follows the already written data. Use `reserve` to ensure that this slice has enough room. The delegate should overwrite as much of the slice as desired and then has to return the number of elements that should be appended (counting from the start of the slice). */ void append(scope size_t delegate(scope ElemType[] dst) @safe del) { auto n = del(m_remaining); assert(n <= m_remaining.length); m_remaining = m_remaining[n .. $]; } } void grow(size_t min_free) { if( !m_data.length && min_free < 16 ) min_free = 16; auto min_size = m_data.length + min_free - m_remaining.length; auto new_size = max(m_data.length, 16); while( new_size < min_size ) new_size = (new_size * 3) / 2; reserve(new_size - m_data.length + m_remaining.length); } } unittest { auto a = AllocAppender!string(theAllocator()); a.put("Hello"); a.put(' '); a.put("World"); assert(a.data == "Hello World"); a.reset(); assert(a.data == ""); } unittest { char[4] buf; auto a = AllocAppender!string(theAllocator(), buf); a.put("He"); assert(a.data == "He"); assert(a.data.ptr == buf.ptr); a.put("ll"); assert(a.data == "Hell"); assert(a.data.ptr == buf.ptr); a.put('o'); assert(a.data == "Hello"); assert(a.data.ptr != buf.ptr); } unittest { char[4] buf; auto a = AllocAppender!string(theAllocator(), buf); a.put("Hello"); assert(a.data == "Hello"); assert(a.data.ptr != buf.ptr); } unittest { auto app = AllocAppender!(int[])(theAllocator); app.reserve(2); app.append((scope mem) { assert(mem.length >= 2); mem[0] = 1; mem[1] = 2; return size_t(2); }); assert(app.data == [1, 2]); } unittest { auto app = AllocAppender!string(theAllocator); app.reserve(3); app.append((scope mem) { assert(mem.length >= 3); mem[0] = 'f'; mem[1] = 'o'; mem[2] = 'o'; return size_t(3); }); assert(app.data == "foo"); } struct FixedAppender(ArrayType : E[], size_t NELEM, E) { alias ElemType = Unqual!E; private { ElemType[NELEM] m_data; size_t m_fill; } void clear() { m_fill = 0; } void put(E el) { m_data[m_fill++] = el; } static if( is(ElemType == char) ){ void put(dchar el) { if( el < 128 ) put(cast(char)el); else { char[4] buf; auto len = std.utf.encode(buf, el); put(cast(ArrayType)buf[0 .. len]); } } } static if( is(ElemType == wchar) ){ void put(dchar el) { if( el < 128 ) put(cast(wchar)el); else { wchar[3] buf; auto len = std.utf.encode(buf, el); put(cast(ArrayType)buf[0 .. len]); } } } void put(ArrayType arr) { m_data[m_fill .. m_fill+arr.length] = (cast(ElemType[])arr)[]; m_fill += arr.length; } @property ArrayType data() { return cast(ArrayType)m_data[0 .. m_fill]; } static if (!is(E == immutable)) { void reset() { m_fill = 0; } } } /** TODO: clear ring buffer fields upon removal (to run struct destructors, if T is a struct) */ struct FixedRingBuffer(T, size_t N = 0, bool INITIALIZE = true) { private { static if( N > 0 ) { static if (INITIALIZE) T[N] m_buffer; else T[N] m_buffer = void; } else T[] m_buffer; size_t m_start = 0; size_t m_fill = 0; } static if( N == 0 ){ this(size_t capacity) { m_buffer = new T[capacity]; } } @property bool empty() const { return m_fill == 0; } @property bool full() const { return m_fill == m_buffer.length; } @property size_t length() const { return m_fill; } @property size_t freeSpace() const { return m_buffer.length - m_fill; } @property size_t capacity() const { return m_buffer.length; } static if( N == 0 ){ /// Resets the capacity to zero and explicitly frees the memory for the buffer. void dispose() { delete m_buffer; m_buffer = null; m_start = m_fill = 0; } @property void capacity(size_t new_size) { if( m_buffer.length ){ auto newbuffer = new T[new_size]; auto dst = newbuffer; auto newfill = min(m_fill, new_size); read(dst[0 .. newfill]); m_buffer = newbuffer; m_start = 0; m_fill = newfill; } else { m_buffer = new T[new_size]; } } } @property ref inout(T) front() inout { assert(!empty); return m_buffer[m_start]; } @property ref inout(T) back() inout { assert(!empty); return m_buffer[mod(m_start+m_fill-1)]; } void clear() { popFrontN(length); assert(m_fill == 0); m_start = 0; } void put()(T itm) { assert(m_fill < m_buffer.length); m_buffer[mod(m_start + m_fill++)] = itm; } void put(TC : T)(TC[] itms) { if( !itms.length ) return; assert(m_fill+itms.length <= m_buffer.length); if( mod(m_start+m_fill) >= mod(m_start+m_fill+itms.length) ){ size_t chunk1 = m_buffer.length - (m_start+m_fill); size_t chunk2 = itms.length - chunk1; m_buffer[m_start+m_fill .. m_buffer.length] = itms[0 .. chunk1]; m_buffer[0 .. chunk2] = itms[chunk1 .. $]; } else { m_buffer[mod(m_start+m_fill) .. mod(m_start+m_fill)+itms.length] = itms[]; } m_fill += itms.length; } void putN(size_t n) { assert(m_fill+n <= m_buffer.length); m_fill += n; } void popFront() { assert(!empty); m_start = mod(m_start+1); m_fill--; } void popFrontN(size_t n) { assert(length >= n); m_start = mod(m_start + n); m_fill -= n; } void popBack() { assert(!empty); m_fill--; } void popBackN(size_t n) { assert(length >= n); m_fill -= n; } void removeAt(Range r) { assert(r.m_buffer is m_buffer); if (r.m_start == m_start) { popFront(); return; } if( m_start + m_fill > m_buffer.length ){ assert(r.m_start > m_start && r.m_start < m_buffer.length || r.m_start < mod(m_start+m_fill)); if( r.m_start > m_start ){ foreach(i; r.m_start .. m_buffer.length-1) m_buffer[i] = m_buffer[i+1]; m_buffer[$-1] = m_buffer[0]; foreach(i; 0 .. mod(m_start + m_fill - 1)) m_buffer[i] = m_buffer[i+1]; } else { foreach(i; r.m_start .. mod(m_start + m_fill - 1)) m_buffer[i] = m_buffer[i+1]; } } else { assert(r.m_start >= m_start && r.m_start < m_start+m_fill); foreach(i; r.m_start .. m_start+m_fill-1) m_buffer[i] = m_buffer[i+1]; } m_fill--; destroy(m_buffer[mod(m_start+m_fill)]); // TODO: only call destroy for non-POD T } inout(T)[] peek() inout { return m_buffer[m_start .. min(m_start+m_fill, m_buffer.length)]; } T[] peekDst() { if( m_start + m_fill < m_buffer.length ) return m_buffer[m_start+m_fill .. $]; else return m_buffer[mod(m_start+m_fill) .. m_start]; } void read(T[] dst) { assert(dst.length <= length); if( !dst.length ) return; if( mod(m_start) >= mod(m_start+dst.length) ){ size_t chunk1 = m_buffer.length - m_start; size_t chunk2 = dst.length - chunk1; dst[0 .. chunk1] = m_buffer[m_start .. $]; dst[chunk1 .. $] = m_buffer[0 .. chunk2]; } else { dst[] = m_buffer[m_start .. m_start+dst.length]; } popFrontN(dst.length); } int opApply(scope int delegate(ref T itm) @safe del) { if( m_start+m_fill > m_buffer.length ){ foreach(i; m_start .. m_buffer.length) if( auto ret = del(m_buffer[i]) ) return ret; foreach(i; 0 .. mod(m_start+m_fill)) if( auto ret = del(m_buffer[i]) ) return ret; } else { foreach(i; m_start .. m_start+m_fill) if( auto ret = del(m_buffer[i]) ) return ret; } return 0; } /// iterate through elements with index int opApply(scope int delegate(size_t i, ref T itm) @safe del) { if( m_start+m_fill > m_buffer.length ){ foreach(i; m_start .. m_buffer.length) if( auto ret = del(i - m_start, m_buffer[i]) ) return ret; foreach(i; 0 .. mod(m_start+m_fill)) if( auto ret = del(i + m_buffer.length - m_start, m_buffer[i]) ) return ret; } else { foreach(i; m_start .. m_start+m_fill) if( auto ret = del(i - m_start, m_buffer[i]) ) return ret; } return 0; } ref inout(T) opIndex(size_t idx) inout { assert(idx < length); return m_buffer[mod(m_start+idx)]; } Range opSlice() { return Range(m_buffer, m_start, m_fill); } Range opSlice(size_t from, size_t to) { assert(from <= to); assert(to <= m_fill); return Range(m_buffer, mod(m_start+from), to-from); } size_t opDollar(size_t dim)() const if(dim == 0) { return length; } private size_t mod(size_t n) const { static if( N == 0 ){ /*static if(PotOnly){ return x & (m_buffer.length-1); } else {*/ return n % m_buffer.length; //} } else static if( ((N - 1) & N) == 0 ){ return n & (N - 1); } else return n % N; } static struct Range { private { T[] m_buffer; size_t m_start; size_t m_length; } private this(T[] buffer, size_t start, size_t length) { m_buffer = buffer; m_start = start; m_length = length; } @property bool empty() const { return m_length == 0; } @property inout(T) front() inout { assert(!empty); return m_buffer[m_start]; } void popFront() { assert(!empty); m_start++; m_length--; if( m_start >= m_buffer.length ) m_start = 0; } } } unittest { static assert(isInputRange!(FixedRingBuffer!int) && isOutputRange!(FixedRingBuffer!int, int)); FixedRingBuffer!(int, 5) buf; assert(buf.length == 0 && buf.freeSpace == 5); buf.put(1); // |1 . . . . assert(buf.length == 1 && buf.freeSpace == 4); buf.put(2); // |1 2 . . . assert(buf.length == 2 && buf.freeSpace == 3); buf.put(3); // |1 2 3 . . assert(buf.length == 3 && buf.freeSpace == 2); buf.put(4); // |1 2 3 4 . assert(buf.length == 4 && buf.freeSpace == 1); buf.put(5); // |1 2 3 4 5 assert(buf.length == 5 && buf.freeSpace == 0); assert(buf.front == 1); buf.popFront(); // .|2 3 4 5 assert(buf.front == 2); buf.popFrontN(2); // . . .|4 5 assert(buf.front == 4); assert(buf.length == 2 && buf.freeSpace == 3); buf.put([6, 7, 8]); // 6 7 8|4 5 assert(buf.length == 5 && buf.freeSpace == 0); int[5] dst; buf.read(dst); // . . .|. . assert(dst == [4, 5, 6, 7, 8]); assert(buf.length == 0 && buf.freeSpace == 5); buf.put([1, 2]); // . . .|1 2 assert(buf.length == 2 && buf.freeSpace == 3); buf.read(dst[0 .. 2]); //|. . . . . assert(dst[0 .. 2] == [1, 2]); buf.put([0, 0, 0, 1, 2]); //|0 0 0 1 2 buf.popFrontN(2); //. .|0 1 2 buf.put([3, 4]); // 3 4|0 1 2 foreach(i, item; buf) { assert(i == item); } assert(buf.front == 0); assert(buf.full); buf.removeAt(buf[0..1]); //4 .|1 2 3 foreach(i, item; buf) { assert(i == item - 1); } buf.put(5); // 4 5|1 2 3 buf.removeAt(buf[3..4]); // 5 .|1 2 3 assert(buf.front == 1); buf.popFront(); assert(buf.front == 2); buf.popFront(); assert(buf.front == 3); buf.popFront(); assert(buf.front == 5); buf.popFront(); assert(buf.empty); } struct ArraySet(Key) { import std.experimental.allocator : makeArray, expandArray, dispose; import std.experimental.allocator.building_blocks.affix_allocator : AffixAllocator; private { static if (__VERSION__ < 2074) { struct AW { // work around AffixAllocator limitations IAllocator alloc; alias alloc this; enum alignment = max(Key.alignof, int.alignof); void[] resolveInternalPointer(void* p) { void[] ret; alloc.resolveInternalPointer(p, ret); return ret; } } alias AllocatorType = AffixAllocator!(AW, int); } else { IAllocator AW(IAllocator a) { return a; } alias AllocatorType = AffixAllocator!(IAllocator, int); } Key[4] m_staticEntries; Key[] m_entries; AllocatorType m_allocator; } ~this() @trusted { static if (__VERSION__ <= 2071) scope (failure) assert(false); if (m_entries.ptr) { if (--allocator.prefix(m_entries) <= 0) { try allocator.dispose(m_entries); catch (Exception e) assert(false, e.msg); // should never happen } } } this(this) @trusted { static if (__VERSION__ <= 2071) scope (failure) assert(false); if (m_entries.ptr) { allocator.prefix(m_entries)++; } } @property ArraySet dup() { static if (__VERSION__ <= 2071) scope (failure) assert(false); ArraySet ret; ret.m_staticEntries = m_staticEntries; ret.m_allocator = m_allocator; if (m_entries.length) { Key[] duped; () @trusted { try duped = allocator.makeArray!(Key)(m_entries.length); catch (Exception e) assert(false, e.msg); if (!duped.length) assert(false, "Failed to allocate memory for duplicated "~ArraySet.stringof); allocator.prefix(duped) = 1; } (); duped[] = m_entries[]; ret.m_entries = duped; } return ret; } void setAllocator(IAllocator allocator) in { assert(m_entries.ptr is null, "Cannot set allocator after elements have been inserted."); } body { m_allocator = AllocatorType(AW(allocator)); } bool opBinaryRight(string op)(Key key) if (op == "in") { return contains(key); } int opApply(int delegate(ref Key) @safe del) { foreach (ref k; m_staticEntries) if (k != Key.init) if (auto ret = del(k)) return ret; foreach (ref k; m_entries) if (k != Key.init) if (auto ret = del(k)) return ret; return 0; } bool contains(Key key) const { foreach (ref k; m_staticEntries) if (k == key) return true; foreach (ref k; m_entries) if (k == key) return true; return false; } void insert(Key key) { if (contains(key)) return; foreach (ref k; m_staticEntries) if (k == Key.init) { k = key; return; } foreach (ref k; m_entries) if (k == Key.init) { k = key; return; } size_t oldlen = m_entries.length; () @trusted { try { if (!oldlen) { m_entries = allocator.makeArray!Key(64); assert(m_entries.length, "Failed to allocate memory for "~ArraySet.stringof); allocator.prefix(m_entries) = 1; } else { int oldrc = allocator.prefix(m_entries); if (!allocator.expandArray(m_entries, max(64, oldlen * 3 / 4))) assert(false, "Failed to allocate memory for "~ArraySet.stringof); allocator.prefix(m_entries) = oldrc; } } catch (Exception e) assert(false, e.msg); } (); m_entries[oldlen] = key; } void remove(Key key) { foreach (ref k; m_staticEntries) if (k == key) { k = Key.init; return; } foreach (ref k; m_entries) if (k == key) { k = Key.init; return; } } ref allocator() nothrow @trusted { try { static if (__VERSION__ < 2074) auto palloc = m_allocator.parent; else auto palloc = m_allocator._parent; if (!palloc) { assert(vibeThreadAllocator !is null, "No theAllocator set!?"); m_allocator = AllocatorType(AW(vibeThreadAllocator)); } } catch (Exception e) assert(false, e.msg); // should never throw return m_allocator; } } @safe nothrow unittest { import std.experimental.allocator : allocatorObject; import std.experimental.allocator.mallocator : Mallocator; ArraySet!int s; s.setAllocator(() @trusted { return Mallocator.instance.allocatorObject; } ()); ArraySet!int t; t = s; s.insert(1); s.insert(2); s.insert(3); s.insert(4); assert(s.contains(1)); assert(s.contains(2)); assert(s.contains(3)); assert(s.contains(4)); assert(!t.contains(1)); s.insert(5); assert(s.contains(5)); t = s; assert(t.contains(5)); assert(t.contains(1)); s.insert(6); assert(s.contains(6)); assert(t.contains(6)); s = ArraySet!int.init; assert(!s.contains(1)); assert(t.contains(1)); assert(t.contains(6)); s = t.dup; assert(s.contains(1)); assert(s.contains(6)); t.remove(1); assert(!t.contains(1)); assert(s.contains(1)); assert(t.contains(2)); assert(t.contains(6)); t.remove(6); assert(!t.contains(6)); assert(s.contains(6)); assert(t.contains(5)); }