Skip to content

Commit 1b3885c

Browse files
authored
Merge pull request #104 from dlang-community/next
Next version of the containers library
2 parents 27bf9f0 + 6d5efa0 commit 1b3885c

File tree

16 files changed

+1000
-578
lines changed

16 files changed

+1000
-578
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ insert_final_newline = true
44
indent_size = 4
55
tab_width = 4
66
trim_trailing_whitespace = true
7+
8+
[*.d]
79
indent_style = tab
10+
11+
[*.json]
12+
indent_style = space

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ __test__*__
1919
.directory
2020
*.userprefs
2121
.vscode
22+
emsi_containers-test-unittest

dub.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,11 @@
99
],
1010
"dependencies": {
1111
"stdx-allocator": "~>2.77.0"
12-
}
12+
},
13+
"configurations": [
14+
{
15+
"name": "unittest",
16+
"versions": ["emsi_containers_unittest"]
17+
}
18+
]
1319
}

src/containers/cyclicbuffer.d

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ struct CyclicBuffer(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
184184
/// ditto
185185
alias insert = insertBack;
186186

187+
/// ditto
188+
alias insertAnywhere = insertBack;
189+
190+
/// ditto
191+
alias put = insertBack;
192+
187193
/**
188194
* Removes the item at the start of the buffer.
189195
*/
@@ -197,6 +203,9 @@ struct CyclicBuffer(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
197203
.destroy(storage[pos]);
198204
}
199205

206+
/// ditto
207+
alias popFront = removeFront;
208+
200209
/**
201210
* Removes the item at the end of the buffer.
202211
*/
@@ -210,6 +219,9 @@ struct CyclicBuffer(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
210219
.destroy(storage[pos]);
211220
}
212221

222+
/// ditto
223+
alias popBack = removeBack;
224+
213225
/// Accesses to the item at the start of the buffer.
214226
auto ref front(this This)() nothrow pure @property @safe
215227
{
@@ -434,7 +446,7 @@ private:
434446
size_t start, end, _length;
435447
}
436448

437-
version (unittest) private
449+
version(emsi_containers_unittest) private
438450
{
439451
import std.algorithm.comparison : equal;
440452
import stdx.allocator.gc_allocator : GCAllocator;
@@ -467,7 +479,7 @@ version (unittest) private
467479
}
468480
}
469481

470-
unittest
482+
version(emsi_containers_unittest) unittest
471483
{
472484
static void test(int size)
473485
{
@@ -512,7 +524,7 @@ unittest
512524
test(size);
513525
}
514526

515-
unittest
527+
version(emsi_containers_unittest) unittest
516528
{
517529
static void test(int prefix, int suffix, int newSize)
518530
{
@@ -535,7 +547,7 @@ unittest
535547
test(a, b, c);
536548
}
537549

538-
unittest
550+
version(emsi_containers_unittest) unittest
539551
{
540552
int a = 0;
541553
{
@@ -560,7 +572,7 @@ unittest
560572
assert(a == 21);
561573
}
562574

563-
unittest
575+
version(emsi_containers_unittest) unittest
564576
{
565577
int* a = new int;
566578
CyclicBuffer!C b;
@@ -587,7 +599,7 @@ unittest
587599
assert(*a == 0 || *a == 1);
588600
}
589601

590-
unittest
602+
version(emsi_containers_unittest) unittest
591603
{
592604
CyclicBuffer!int b;
593605
b.insertFront(10);
@@ -608,7 +620,7 @@ unittest
608620
assert(b[3] == 7);
609621
}
610622

611-
unittest
623+
version(emsi_containers_unittest) unittest
612624
{
613625
import std.range : isInputRange, isForwardRange, isBidirectionalRange, isRandomAccessRange;
614626
CyclicBuffer!int b;
@@ -618,13 +630,13 @@ unittest
618630
static assert(isRandomAccessRange!(typeof(b[])));
619631
}
620632

621-
unittest
633+
version(emsi_containers_unittest) unittest
622634
{
623635
CyclicBuffer!int b;
624636
assert(b[].empty);
625637
}
626638

627-
unittest
639+
version(emsi_containers_unittest) unittest
628640
{
629641
FreeList!(Mallocator, 0, 64) alloc;
630642
FreeList!(GCAllocator, 0, 64) alloc2;
@@ -633,7 +645,7 @@ unittest
633645
auto b3 = CyclicBuffer!(int, GCAllocator)();
634646
}
635647

636-
unittest
648+
version(emsi_containers_unittest) unittest
637649
{
638650
static void testConst(const ref CyclicBuffer!int b, int x)
639651
{
@@ -664,7 +676,7 @@ unittest
664676
assert(b[][0] == 5);
665677
}
666678

667-
unittest
679+
version(emsi_containers_unittest) unittest
668680
{
669681
int a = 0;
670682
{
@@ -688,7 +700,7 @@ unittest
688700
assert(a == 10);
689701
}
690702

691-
unittest
703+
version(emsi_containers_unittest) unittest
692704
{
693705
CyclicBuffer!int b;
694706
foreach (i; 0 .. 4)
@@ -702,7 +714,7 @@ unittest
702714
assert(equal(b[], [2, 3, 4, 5]));
703715
}
704716

705-
unittest
717+
version(emsi_containers_unittest) unittest
706718
{
707719
CyclicBuffer!int b;
708720
foreach (i; 0 .. 4)
@@ -718,7 +730,7 @@ unittest
718730
assert(equal(b[], [3, 4, 5, 6]));
719731
}
720732

721-
unittest
733+
version(emsi_containers_unittest) unittest
722734
{
723735
static void test(ref CyclicBuffer!int b)
724736
{
@@ -772,7 +784,7 @@ unittest
772784
}
773785
}
774786

775-
unittest
787+
version(emsi_containers_unittest) unittest
776788
{
777789
CyclicBuffer!int b;
778790
foreach (i; 0 .. 10)
@@ -782,7 +794,7 @@ unittest
782794
assert(b.capacity >= 12);
783795
}
784796

785-
unittest
797+
version(emsi_containers_unittest) unittest
786798
{
787799
CyclicBuffer!int b;
788800
foreach (i; 0 .. 6)
@@ -794,7 +806,7 @@ unittest
794806
assert(equal(b[], [7, 6, 0, 1, 2, 3, 4, 5]));
795807
}
796808

797-
unittest
809+
version(emsi_containers_unittest) unittest
798810
{
799811
static class Foo
800812
{

src/containers/dynamicarray.d

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct DynamicArray(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
108108
/**
109109
* Inserts the given value into the end of the array.
110110
*/
111-
void insert(T value)
111+
void insertBack(T value)
112112
{
113113
import stdx.allocator.mallocator : Mallocator;
114114
import containers.internal.node : shouldAddGCRange;
@@ -152,7 +152,13 @@ struct DynamicArray(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
152152
}
153153

154154
/// ditto
155-
alias put = insert;
155+
alias insert = insertBack;
156+
157+
/// ditto
158+
alias insertAnywhere = insertBack;
159+
160+
/// ditto
161+
alias put = insertBack;
156162

157163
/**
158164
* ~= operator overload
@@ -311,7 +317,7 @@ struct DynamicArray(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange
311317
}
312318

313319
/**
314-
* Removes the last element from the array.
320+
* Removes the last element from the array.
315321
*/
316322
void removeBack()
317323
{
@@ -381,7 +387,7 @@ private:
381387
size_t l;
382388
}
383389

384-
unittest
390+
version(emsi_containers_unittest) unittest
385391
{
386392
import std.algorithm : equal;
387393
import std.range : iota;
@@ -411,7 +417,7 @@ unittest
411417
assert(ints[0] == 1337);
412418
}
413419

414-
version(unittest)
420+
version(emsi_containers_unittest)
415421
{
416422
class Cls
417423
{
@@ -429,7 +435,7 @@ version(unittest)
429435
}
430436
}
431437

432-
unittest
438+
version(emsi_containers_unittest) unittest
433439
{
434440
int a = 0;
435441
{
@@ -439,7 +445,7 @@ unittest
439445
assert(a == 0); // Destructor not called.
440446
}
441447

442-
unittest
448+
version(emsi_containers_unittest) unittest
443449
{
444450
import std.exception : assertThrown;
445451
import core.exception : RangeError;
@@ -481,7 +487,7 @@ unittest
481487
assert(two.length == 0);
482488
}
483489

484-
unittest
490+
version(emsi_containers_unittest) unittest
485491
{
486492
int a = 0;
487493
DynamicArray!(Cls, Mallocator, true) arr;
@@ -491,7 +497,7 @@ unittest
491497
assert(a == 0); // Destructor not called.
492498
}
493499

494-
unittest
500+
version(emsi_containers_unittest) unittest
495501
{
496502
DynamicArray!(int*, Mallocator, true) arr;
497503

@@ -506,7 +512,7 @@ unittest
506512
assert (*slice[1] == 2);
507513
}
508514

509-
unittest
515+
version(emsi_containers_unittest) unittest
510516
{
511517
import std.format : format;
512518

@@ -526,22 +532,22 @@ unittest
526532

527533
}
528534

529-
@system unittest
535+
version(emsi_containers_unittest) @system unittest
530536
{
531-
DynamicArray!int a;
532-
a.reserve(1000);
533-
assert(a.length == 0);
534-
assert(a.empty);
535-
assert(a.arr.length >= 1000);
536-
int* p = a[].ptr;
537-
foreach (i; 0 .. 1000)
538-
{
539-
a.insert(i);
540-
}
541-
assert(p is a[].ptr);
537+
DynamicArray!int a;
538+
a.reserve(1000);
539+
assert(a.length == 0);
540+
assert(a.empty);
541+
assert(a.arr.length >= 1000);
542+
int* p = a[].ptr;
543+
foreach (i; 0 .. 1000)
544+
{
545+
a.insert(i);
546+
}
547+
assert(p is a[].ptr);
542548
}
543549

544-
unittest
550+
version(emsi_containers_unittest) unittest
545551
{
546552
// Ensure that Array.insert doesn't call the destructor for
547553
// a struct whose state is uninitialized memory.
@@ -562,17 +568,17 @@ unittest
562568
assert(a == 1);
563569
}
564570

565-
@nogc unittest
571+
version(emsi_containers_unittest) @nogc unittest
566572
{
567-
struct HStorage
568-
{
569-
import containers.dynamicarray: DynamicArray;
570-
DynamicArray!int storage;
571-
}
573+
struct HStorage
574+
{
575+
import containers.dynamicarray: DynamicArray;
576+
DynamicArray!int storage;
577+
}
572578
auto hs = HStorage();
573579
}
574580

575-
@nogc unittest
581+
version(emsi_containers_unittest) @nogc unittest
576582
{
577583
DynamicArray!char a;
578584
const DynamicArray!char b = a ~ "def";

0 commit comments

Comments
 (0)