Skip to content

Commit 6d5efa0

Browse files
committed
Defined the behavior of the remove methods when duplicates are possible
1 parent d9c3f39 commit 6d5efa0

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/containers/ttree.d

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ struct TTree(T, Allocator = Mallocator, bool allowDuplicates = false,
160160
alias put = insert;
161161

162162
/**
163-
* Removes a value from the tree.
163+
* Removes a single value from the tree, or does nothing.
164+
*
165+
* If `allowDuplicates` is true only a single element that is equivalent to
166+
* the given `value` will be removed. Which of these elements is removed is
167+
* not defined.
164168
*
165169
* Params:
166170
* value = a value equal to the one to be removed
@@ -1326,3 +1330,23 @@ version(emsi_containers_unittest) unittest
13261330
tt.insert(f);
13271331
auto r = tt[];
13281332
}
1333+
1334+
version(emsi_containers_unittest) unittest
1335+
{
1336+
import std.range : walkLength;
1337+
import std.stdio;
1338+
1339+
TTree!(int, Mallocator, true) tt;
1340+
tt.insert(10);
1341+
tt.insert(11);
1342+
tt.insert(12);
1343+
writeln(tt[]);
1344+
assert(tt.length == 3);
1345+
tt.insert(11);
1346+
writeln(tt[]);
1347+
assert(tt.length == 4);
1348+
tt.remove(11);
1349+
writeln(tt[]);
1350+
assert(tt.length == 3);
1351+
assert(tt[].walkLength == tt.length);
1352+
}

src/containers/unrolledlist.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ struct UnrolledList(T, Allocator = Mallocator,
194194
}
195195

196196
/**
197-
* Removes the given item from the list.
197+
* Removes the first instance of the given item from the list.
198+
*
198199
* Returns: true if something was removed.
199200
*/
200201
bool remove(T item)

0 commit comments

Comments
 (0)