-
Notifications
You must be signed in to change notification settings - Fork 0
/
container.d
1954 lines (1649 loc) · 46.6 KB
/
container.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/++
Containers.
Example:
---
{
Buffer!string buffer;
buffer.put("abc");
buffer.put("def");
assert(!buffer.empty);
assert(buffer.front == "abc");
buffer.popFront();
assert(buffer.front == "def");
buffer.popFront();
assert(buffer.empty);
}
{
Buffer!(char, Yes.dynamic, 3) buffer;
assert(!buffer.buf.length);
buffer ~= 'a';
assert(buffer.buf.length == 3);
buffer ~= 'b';
buffer ~= 'c';
assert(buffer.length == 3);
buffer ~= 'd';
assert(buffer.buf.length > 3);
assert(buffer[0..5] == "abcd");
buffer.clear();
assert(buffer.empty);
}
{
RehashingAA!(int[string]) aa;
aa.minimumNeededForRehash = 2;
aa["abc"] = 123;
aa["def"] = 456;
assert((aa.newKeysSinceLastRehash == 2), aa.newKeysSinceLastRehash.to!string);
assert((aa.numRehashes == 0), aa.numRehashes.to!string);
aa["ghi"] = 789;
assert((aa.numRehashes == 1), aa.numRehashes.to!string);
assert((aa.newKeysSinceLastRehash == 0), aa.newKeysSinceLastRehash.to!string);
aa.rehash();
assert((aa.numRehashes == 2), aa.numRehashes.to!string);
auto realAA = cast(int[string])aa;
assert("abc" in realAA);
assert("def" in realAA);
auto alsoRealAA = aa.aaOf;
assert("ghi" in realAA);
assert("jkl" !in realAA);
auto aa2 = aa.dup;
aa2["jkl"] = 123;
assert("jkl" in aa2);
assert("jkl" !in aa);
}
{
MutexedAA!(string[int]) aa;
aa.setup(); // important!
aa[1] = "one";
aa[2] = "two";
aa[3] = "three";
auto hasOne = aa.has(1);
assert(hasOne);
assert(aa[1] == "one");
assert(aa[2] == "two");
auto three = aa.get(3);
assert(three == "three");
auto four = aa.get(4, "four");
assert(four == "four");
auto five = aa.require(5, "five");
assert(five == "five");
assert(aa[5] == "five");
auto keys = aa.keys;
assert(keys.canFind(1));
assert(keys.canFind(5));
assert(!keys.canFind(6));
auto values = aa.values;
assert(values.canFind("one"));
assert(values.canFind("four"));
assert(!values.canFind("six"));
aa.rehash();
}
---
Copyright: [JR](https://github.com/zorael)
License: [Boost Software License 1.0](https://www.boost.org/users/license.html)
Authors:
[JR](https://github.com/zorael)
+/
module lu.container;
private:
import std.typecons : Flag, No, Yes;
public:
// Buffer
/++
Simple buffer/queue for storing and fetching items of any type `T`.
Does not use manual memory allocation.
It can use a static array internally to store elements on the stack, which
imposes a hard limit on how many items can be added, or a dynamic heap one
with a resizable buffer.
Example:
---
Buffer!(string, No.dynamic, 16) buffer;
buffer.put("abc");
buffer ~= "def";
assert(!buffer.empty);
assert(buffer.front == "abc");
buffer.popFront();
assert(buffer.front == "def");
buffer.popFront();
assert(buffer.empty);
---
Params:
T = Buffer item type.
dynamic = Whether to use a dynamic array whose size can be grown at
runtime, or to use a static array with a fixed size. Trying to add
more elements than there is room for will cause an assert.
Defaults to `No.dynamic`; a static array.
originalSize = How many items to allocate space for. If `No.dynamic` was
passed it will assert if you attempt to store anything past this amount.
+/
struct Buffer(T, Flag!"dynamic" dynamic = No.dynamic, size_t originalSize = 128)
{
pure nothrow:
static if (dynamic)
{
/++
By how much to grow the buffer when we reach the end of it.
+/
private enum growthFactor = 1.5;
/++
Internal buffer dynamic array.
+/
T[] buf;
/++
Variable buffer size.
+/
size_t bufferSize;
}
else
{
/++
Internal buffer static array.
+/
T[bufferSize] buf;
/++
Static buffer size.
+/
alias bufferSize = originalSize;
}
/++
Current position in the array.
+/
ptrdiff_t pos;
/++
Position of last entry in the array.
+/
ptrdiff_t end;
static if (dynamic)
{
// put
/++
Append an item to the end of the buffer.
If it would be put beyond the end of the buffer, it will be resized to fit.
Params:
more = Item to add.
+/
void put(/*const*/ T more) pure @safe nothrow
{
if (end == bufferSize)
{
bufferSize = !bufferSize ? originalSize : cast(size_t)(bufferSize * growthFactor);
buf.length = bufferSize;
}
buf[end++] = more;
}
}
else
{
// put
/++
Append an item to the end of the buffer.
If it would be put beyond the end of the buffer, it will assert.
Params:
more = Item to add.
+/
void put(/*const*/ T more) pure @safe nothrow @nogc
in ((end < bufferSize), '`' ~ typeof(this).stringof ~ "` buffer overflow")
{
buf[end++] = more;
}
}
static if (dynamic)
{
// reserve
/++
Reserves enough room for the specified number of elements. If there
is already enough room, nothing is done. Otherwise the buffer is grown.
Params:
reserveSize = Number of elements to reserve size for.
+/
void reserve(const size_t reserveSize) pure @safe nothrow
{
if (bufferSize < reserveSize)
{
bufferSize = reserveSize;
buf.length = bufferSize;
}
}
}
// opOpAssign
/++
Implements `buf ~= someT` (appending) by wrapping `put`.
Params:
op = Operation type, here specialised to "`~`".
more = Item to add.
+/
void opOpAssign(string op : "~")(/*const*/ T more) pure @safe nothrow
{
return put(more);
}
// front
/++
Fetches the item at the current position of the buffer.
Returns:
An item T.
+/
ref auto front() inout pure @safe nothrow @nogc
in ((end > 0), '`' ~ typeof(this).stringof ~ "` buffer underrun")
{
return buf[pos];
}
// popFront
/++
Advances the current position to the next item in the buffer.
+/
void popFront() pure @safe nothrow @nogc
{
if (++pos == end) reset();
}
// length
/++
Returns what amounts to the current length of the buffer; the distance
between the current position `pos` and the last element `end`.
Returns:
The buffer's current length.
+/
auto length() inout
{
return (end - pos);
}
// empty
/++
Returns whether or not the container is considered empty.
Mind that the buffer may well still contain old contents. Use `clear`
to zero it out.
Returns:
`true` if there are items available to get via `front`,
`false` if not.
+/
auto empty() inout
{
return (end == 0);
}
// reset
/++
Resets the array positions, effectively soft-emptying the buffer.
The old elements' values are still there, they will just be overwritten
as the buffer is appended to.
+/
void reset() pure @safe nothrow @nogc
{
pos = 0;
end = 0;
}
// clear
/++
Zeroes out the buffer's elements, getting rid of old contents.
+/
void clear() pure @safe nothrow @nogc
{
reset();
buf[] = T.init;
}
}
///
unittest
{
{
Buffer!(bool, No.dynamic, 4) buffer;
assert(buffer.empty);
buffer.put(true);
buffer.put(false);
assert(buffer.length == 2);
buffer.put(true);
buffer.put(false);
assert(!buffer.empty);
assert(buffer.front == true);
buffer.popFront();
assert(buffer.front == false);
buffer.popFront();
assert(buffer.front == true);
buffer.popFront();
assert(buffer.front == false);
buffer.popFront();
assert(buffer.empty);
assert(buffer.buf == [ true, false, true, false ]);
buffer.put(false);
assert(buffer.buf == [ false, false, true, false ]);
buffer.reset();
assert(buffer.empty);
buffer.clear();
assert(buffer.buf == [ false, false, false, false ]);
}
{
Buffer!(string, No.dynamic, 4) buffer;
assert(buffer.empty);
buffer.put("abc");
buffer.put("def");
buffer.put("ghi");
assert(!buffer.empty);
assert(buffer.front == "abc");
buffer.popFront();
assert(buffer.front == "def");
buffer.popFront();
buffer.put("JKL");
assert(buffer.front == "ghi");
buffer.popFront();
assert(buffer.front == "JKL");
buffer.popFront();
assert(buffer.empty);
assert(buffer.buf == [ "abc", "def", "ghi", "JKL" ]);
buffer.put("MNO");
assert(buffer.buf == [ "MNO", "def", "ghi", "JKL" ]);
buffer.clear();
assert(buffer.buf == [ string.init, string.init, string.init, string.init ]);
}
{
Buffer!(char, No.dynamic, 64) buffer;
buffer ~= 'a';
buffer ~= 'b';
buffer ~= 'c';
assert(buffer.buf[0..3] == "abc");
foreach (char_; buffer)
{
assert((char_ == 'a') || (char_ == 'b') || (char_ == 'c'));
}
}
{
Buffer!(int, Yes.dynamic, 3) buffer;
assert(!buffer.buf.length);
buffer ~= 1;
assert(buffer.buf.length == 3);
buffer ~= 2;
buffer ~= 3;
assert(buffer.front == 1);
buffer.popFront();
assert(buffer.front == 2);
buffer.popFront();
assert(buffer.front == 3);
buffer.popFront();
assert(buffer.empty);
buffer.reserve(64);
assert(buffer.buf.length == 64);
buffer.reserve(63);
assert(buffer.buf.length == 64);
}
{
Buffer!(char, No.dynamic, 4) buffer;
buffer ~= 'a';
buffer ~= 'b';
buffer ~= 'c';
buffer ~= 'd';
assert(buffer.buf == "abcd");
assert(buffer.length == 4);
buffer.reset();
assert(buffer.buf == "abcd");
buffer.clear();
assert(buffer.buf == typeof(buffer.buf).init);
}
}
// CircularBuffer
/++
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.
It can use a static array internally to store elements on the stack, which
imposes a hard limit on how many items can be added, or a dynamic heap one
with a resizable buffer.
Example:
---
CircularBuffer!(int, Yes.dynamic) buf;
buf.resize(3);
buf.put(1);
buf.put(2);
buf.put(3);
but.put(4);
assert(buf.front == 4);
assert(buf.buf == [ 4, 2, 3 ]);
---
Params:
T = Buffer item type.
dynamic = Whether to use a dynamic array whose size can be grown at
runtime, or to use a static array with a fixed size. Trying to add
more elements than there is room for will wrap around and discard elements.
Defaults to `No.dynamic`; a static buffer.
originalSize = How many items to allocate space for in the case of a
static array.
+/
struct CircularBuffer(T, Flag!"dynamic" dynamic = No.dynamic, size_t originalSize = 16)
if (originalSize > 1)
{
private:
static if (dynamic)
{
// buf
/++
Internal buffer dynamic array.
+/
T[] buf;
}
else
{
// buf
/++
Internal buffer static array.
+/
T[originalSize] buf;
}
// head
/++
Head position in the internal buffer.
+/
size_t head;
// tail
/++
Tail position in the internal buffer.
+/
size_t tail;
// caughtUp
/++
Whether or not [head] and [tail] point to the same position in the
context of a circular array.
+/
bool caughtUp;
// initialised
/++
Whether or not at least one element has been added.
+/
bool initialised;
public:
// front
/++
Returns the front element.
Returns:
An item T.
+/
ref auto front() inout
in ((buf.length > 0), "Tried to get `front` from a zero-sized " ~ typeof(this).stringof)
{
return buf[head];
}
// put
/++
Append an item to the buffer.
If it would be put beyond the end of the buffer, it will wrap around and
truncate old values.
Params:
item = Item to add.
+/
void put(T item) pure @safe @nogc nothrow
in ((buf.length > 0), "Tried to `put` something into a zero-sized " ~ typeof(this).stringof)
{
if (initialised) ++head %= buf.length;
buf[head] = item;
tail = head;
caughtUp = true;
initialised = true;
}
// popFront
/++
Advances the current position to the next item in the buffer.
+/
void popFront() pure @safe @nogc nothrow
in ((buf.length > 0), "Tried to `popFront` a zero-sized " ~ typeof(this).stringof)
in (!empty, "Tried to `popFront` an empty " ~ typeof(this).stringof)
{
if (head == 0)
{
head = (buf.length + (-1));
caughtUp = false;
}
else
{
--head;
}
}
static if (dynamic)
{
// resize
/++
Resizes the internal buffer to a specified size.
Params:
size = New size.
+/
void resize(const size_t size) pure @safe nothrow
{
buf.length = size;
if (head >= buf.length) head = buf.length +(-1);
if (tail >= buf.length) tail = buf.length +(-1);
}
}
// opOpAssign
/++
Implements `buf ~= someT` (appending) by wrapping `put`.
Params:
op = Operation type, here specialised to "`~`".
more = Item to add.
+/
void opOpAssign(string op : "~")(const T more) pure @safe @nogc nothrow
{
return put(more);
}
// size
/++
Returns the size of the internal buffer.
Returns:
Internal buffer size.
+/
auto size() inout
{
return buf.length;
}
// empty
/++
Returns whether or not the container is considered empty.
Mind that the buffer may well still contain old contents. Use `clear`
to zero it out.
Returns:
`true` if there are items available to get via `front`,
`false` if not.
+/
auto empty() inout
{
return !caughtUp && (head == tail);
}
// save
/++
Implements Range `save`.
Returns:
A shallow copy of the container.
+/
auto save()
{
return this;
}
// dup
/++
Makes a deep(er) duplicate of the container.
Returns:
A copy of the current container with the internal buffer explicitly `.dup`ed.
+/
auto dup()
{
auto copy = this;
static if (dynamic)
{
copy.buf = this.buf.dup;
}
return copy;
}
// clear
/++
Resets the buffer pointers but doesn't clear the contents.
+/
void reset() pure @safe @nogc nothrow
{
head = 0;
tail = 0;
}
// clear
/++
Zeroes out the buffer's elements, getting rid of old contents.
+/
void clear() pure @safe @nogc nothrow
{
reset();
buf[] = T.init;
}
}
///
unittest
{
import std.conv : text;
{
CircularBuffer!(int, Yes.dynamic) buf;
buf.resize(3);
buf.put(1);
assert((buf.front == 1), buf.front.text);
buf.put(2);
assert((buf.front == 2), buf.front.text);
buf.put(3);
assert((buf.front == 3), buf.front.text);
buf ~= 4;
assert((buf.front == 4), buf.front.text);
assert((buf.buf[] == [ 4, 2, 3 ]), buf.buf.text);
buf ~= 5;
assert((buf.front == 5), buf.front.text);
buf ~= 6;
assert((buf.front == 6), buf.front.text);
assert((buf.buf[] == [ 4, 5, 6 ]), buf.buf.text);
buf.popFront();
buf.popFront();
buf.popFront();
assert(buf.empty);
}
{
CircularBuffer!(int, No.dynamic, 3) buf;
//buf.resize(3);
buf.put(1);
assert((buf.front == 1), buf.front.text);
buf.put(2);
assert((buf.front == 2), buf.front.text);
buf.put(3);
assert((buf.front == 3), buf.front.text);
buf ~= 4;
assert((buf.front == 4), buf.front.text);
assert((buf.buf[] == [ 4, 2, 3 ]), buf.buf.text);
buf.popFront();
buf.popFront();
buf.popFront();
assert(buf.empty);
}
{
CircularBuffer!(int, No.dynamic, 2) buf;
//buf.resize(2);
buf.put(1);
assert((buf.front == 1), buf.front.text);
buf.put(2);
assert((buf.front == 2), buf.front.text);
buf.put(3);
assert((buf.front == 3), buf.front.text);
buf ~= 4;
assert((buf.front == 4), buf.front.text);
assert((buf.buf[] == [ 3, 4 ]), buf.buf.text);
buf.popFront();
buf.popFront();
assert(buf.empty);
//buf.popFront(); // AssertError
}
{
CircularBuffer!(int, No.dynamic, 2) buf;
//buf.resize(2);
buf.put(1);
assert((buf.front == 1), buf.front.text);
buf.put(2);
assert((buf.front == 2), buf.front.text);
buf.put(3);
assert((buf.front == 3), buf.front.text);
buf ~= 4;
assert((buf.front == 4), buf.front.text);
assert((buf.buf[] == [ 3, 4 ]), buf.buf.text);
auto savedBuf = buf.save();
buf.popFront();
buf.popFront();
assert(buf.empty);
assert((savedBuf.front == 4), savedBuf.front.text);
savedBuf.popFront();
auto savedBuf2 = savedBuf.save();
savedBuf.popFront();
assert(savedBuf.empty);
assert((savedBuf2.front == 3), savedBuf2.front.text);
savedBuf2.popFront();
assert(savedBuf2.empty);
}
}
// RehashingAA
/++
A wrapper around a native associative array that you can controllably set to
automatically rehash as entries are added.
Params:
AA = Associative array type.
V = Value type.
K = Key type.
+/
struct RehashingAA(AA : V[K], V, K)
{
private:
/++
Internal associative array.
+/
AA aa;
/++
The number of times this instance has rehashed itself. Private value.
+/
uint _numRehashes;
/++
The number of new entries that has been added since the last rehash. Private value.
+/
uint _newKeysSinceLastRehash;
/++
The number of keys (and length of the array) when the last rehash took place.
Private value.
+/
size_t _lengthAtLastRehash;
public:
/++
The minimum number of additions needed before the first rehash takes place.
+/
uint minimumNeededForRehash = 64;
/++
The modifier by how much more entries must be added before another rehash
takes place, with regards to the current [RehashingAA.aa|aa] length.
A multiplier of `2.0` means the associative array will be rehashed as
soon as its length doubles in size. Must be more than 1.
+/
double rehashThresholdMultiplier = 1.5;
// opIndexAssign
/++
Assigns a value into the internal associative array. If it created a new
entry, then call [maybeRehash] to bump the internal counter and maybe rehash.
Params:
value = Value.
key = Key.
+/
void opIndexAssign(V value, K key)
{
if (auto existing = key in aa)
{
*existing = value;
}
else
{
aa[key] = value;
maybeRehash();
}
}
// opAssign
/++
Inherit a native associative array into [RehashingAA.aa|aa].
Params:
aa = Other associative array.
+/
void opAssign(V[K] aa)
{
this.aa = aa;
this.rehash();
_numRehashes = 0;
}
// opCast
/++
Allows for casting this into the base associative array type.
Params:
T = Type to cast to, here the same as the type of [RehashingAA.aa|aa].
Returns:
The internal associative array.
+/
auto opCast(T : AA)() inout
{
return aa;
}
// aaOf
/++
Returns the internal associative array, for when the wrapper is insufficient.
Returns:
The internal associative array.
+/
auto aaOf() inout
{
return aa;
}
// remove
/++
Removes a key from the [RehashingAA.aa|aa] associative array by merely
invoking `.remove`.
Params:
key = The key to remove.
Returns:
Whatever `aa.remove(key)` returns.
+/
auto remove(K key)
{
//scope(exit) maybeRehash();
return aa.remove(key);
}
// maybeRehash
/++
Bumps the internal counter of new keys since the last rehash, and depending
on the resulting value of it, maybe rehashes.
Returns:
`true` if the associative array was rehashed; `false` if not.
+/
auto maybeRehash()
{
if (++_newKeysSinceLastRehash > minimumNeededForRehash)
{
if (aa.length > (_lengthAtLastRehash * rehashThresholdMultiplier))
{
this.rehash();
return true;
}
}
return false;
}
// clear
/++
Clears the internal associative array and all counters.
+/
void clear()
{
aa.clear();
_newKeysSinceLastRehash = 0;
_lengthAtLastRehash = 0;
_numRehashes = 0;
}
// rehash
/++
Rehashes the internal associative array, bumping the rehash counter and
zeroing the keys-added counter. Additionally invokes the [onRehashDg] delegate.
Returns:
A reference to the rehashed internal array.
+/
ref auto rehash()
{
scope(exit) if (onRehashDg) onRehashDg();
_lengthAtLastRehash = aa.length;
_newKeysSinceLastRehash = 0;
++_numRehashes;
aa.rehash();
return this;
}
// numRehashes
/++
The number of times this instance has rehashed itself. Accessor.
Returns:
The number of times this instance has rehashed itself.
+/
auto numRehashes() inout
{
return _numRehashes;
}
// numKeysAddedSinceLastRehash
/++
The number of new entries that has been added since the last rehash. Accessor.
Returns:
The number of new entries that has been added since the last rehash.
+/
auto newKeysSinceLastRehash() inout
{
return _newKeysSinceLastRehash;
}
// opBinaryRight
/++
Wraps `key in aa` to the internal associative array.
Params:
op = Operation, here "in".
key = Key.
Returns:
A pointer to the value of the key passed, or `null` if it isn't in
the associative array
+/
auto opBinaryRight(string op : "in")(K key) inout
{
return key in aa;
}
// length
/++
Returns the length of the internal associative array.
Returns:
The length of the internal associative array.
+/
auto length() inout