authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-16 22:49:20-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-01-16 22:49:20-07:00
log8436134499c623485aeb20374a9928685db4211e
tree648042f284a82ecdad0499a1de8243285d9b2dfc
parent1f65828ec6caa7697b26d9e919112aa1715b57bc

std.ArrayHashMap: add "AssertDiscard" function variants

* Add `swapRemoveAssertDiscard` * Add `orderedRemoveAssertDiscard` * Deprecate `removeAssertDiscard`

1 files changed, 26 insertions(+), 4 deletions(-)

lib/std/array_hash_map.zig+26-4
......@@ -239,12 +239,23 @@ pub fn ArrayHashMap(
239239 return self.unmanaged.orderedRemove(key);
240240 }
241241
242 /// Asserts there is an `Entry` with matching key, deletes it from the hash map,
243 /// and discards it.
242 /// TODO: deprecated: call swapRemoveAssertDiscard instead.
244243 pub fn removeAssertDiscard(self: *Self, key: K) void {
245244 return self.unmanaged.removeAssertDiscard(key);
246245 }
247246
247 /// Asserts there is an `Entry` with matching key, deletes it from the hash map
248 /// by swapping it with the last element, and discards it.
249 pub fn swapRemoveAssertDiscard(self: *Self, key: K) void {
250 return self.unmanaged.swapRemoveAssertDiscard(key);
251 }
252
253 /// Asserts there is an `Entry` with matching key, deletes it from the hash map
254 /// by by shifting all elements forward thereby maintaining the current ordering.
255 pub fn orderedRemoveAssertDiscard(self: *Self, key: K) void {
256 return self.unmanaged.orderedRemoveAssertDiscard(key);
257 }
258
248259 pub fn items(self: Self) []Entry {
249260 return self.unmanaged.items();
250261 }
......@@ -602,12 +613,23 @@ pub fn ArrayHashMapUnmanaged(
602613 return self.removeInternal(key, .ordered);
603614 }
604615
605 /// Asserts there is an `Entry` with matching key, deletes it from the hash map,
606 /// and discards it.
616 /// TODO deprecated: call swapRemoveAssertDiscard instead.
607617 pub fn removeAssertDiscard(self: *Self, key: K) void {
618 return self.swapRemoveAssertDiscard(key);
619 }
620
621 /// Asserts there is an `Entry` with matching key, deletes it from the hash map
622 /// by swapping it with the last element, and discards it.
623 pub fn swapRemoveAssertDiscard(self: *Self, key: K) void {
608624 assert(self.swapRemove(key) != null);
609625 }
610626
627 /// Asserts there is an `Entry` with matching key, deletes it from the hash map
628 /// by by shifting all elements forward thereby maintaining the current ordering.
629 pub fn orderedRemoveAssertDiscard(self: *Self, key: K) void {
630 assert(self.orderedRemove(key) != null);
631 }
632
611633 pub fn items(self: Self) []Entry {
612634 return self.entries.items;
613635 }