Added fix for multivalued map.
Build and Test Module / build-and-test (push) Successful in 6s Details

This commit is contained in:
Andrew Lalis 2025-08-02 23:37:52 -04:00
parent 8b198c58ee
commit 39bb474522
1 changed files with 10 additions and 5 deletions

View File

@ -183,17 +183,14 @@ struct MultiValueMap(
* k = The key to remove.
*/
void remove(KeyType k) {
import std.algorithm : remove;
long idx = indexOf(k);
if (idx == -1) return;
if (entries.length == 1) {
clear();
return;
}
if (idx + 1 < entries.length) {
const i = cast(size_t) idx;
entries[i .. $ - 1] = entries[i + 1 .. $];
}
entries.length = entries.length - 1;
entries = entries.remove(idx);
}
/**
@ -446,3 +443,11 @@ unittest {
builder.add("a", "456");
assert(builder.build()[] == [StringMultiValueMap.Entry("a", ["123", "456"])], builder.build().toString);
}
unittest {
MultiValueMap!(string, string) map;
map.add("a", "one");
map.add("b", "two");
map.add("c", "three");
map.remove("a");
}