mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
std.ArrayHashMap: add "AssertDiscard" function variants
* Add `swapRemoveAssertDiscard` * Add `orderedRemoveAssertDiscard` * Deprecate `removeAssertDiscard`
This commit is contained in:
parent
1f65828ec6
commit
8436134499
@ -239,12 +239,23 @@ pub fn ArrayHashMap(
|
||||
return self.unmanaged.orderedRemove(key);
|
||||
}
|
||||
|
||||
/// Asserts there is an `Entry` with matching key, deletes it from the hash map,
|
||||
/// and discards it.
|
||||
/// TODO: deprecated: call swapRemoveAssertDiscard instead.
|
||||
pub fn removeAssertDiscard(self: *Self, key: K) void {
|
||||
return self.unmanaged.removeAssertDiscard(key);
|
||||
}
|
||||
|
||||
/// Asserts there is an `Entry` with matching key, deletes it from the hash map
|
||||
/// by swapping it with the last element, and discards it.
|
||||
pub fn swapRemoveAssertDiscard(self: *Self, key: K) void {
|
||||
return self.unmanaged.swapRemoveAssertDiscard(key);
|
||||
}
|
||||
|
||||
/// Asserts there is an `Entry` with matching key, deletes it from the hash map
|
||||
/// by by shifting all elements forward thereby maintaining the current ordering.
|
||||
pub fn orderedRemoveAssertDiscard(self: *Self, key: K) void {
|
||||
return self.unmanaged.orderedRemoveAssertDiscard(key);
|
||||
}
|
||||
|
||||
pub fn items(self: Self) []Entry {
|
||||
return self.unmanaged.items();
|
||||
}
|
||||
@ -602,12 +613,23 @@ pub fn ArrayHashMapUnmanaged(
|
||||
return self.removeInternal(key, .ordered);
|
||||
}
|
||||
|
||||
/// Asserts there is an `Entry` with matching key, deletes it from the hash map,
|
||||
/// and discards it.
|
||||
/// TODO deprecated: call swapRemoveAssertDiscard instead.
|
||||
pub fn removeAssertDiscard(self: *Self, key: K) void {
|
||||
return self.swapRemoveAssertDiscard(key);
|
||||
}
|
||||
|
||||
/// Asserts there is an `Entry` with matching key, deletes it from the hash map
|
||||
/// by swapping it with the last element, and discards it.
|
||||
pub fn swapRemoveAssertDiscard(self: *Self, key: K) void {
|
||||
assert(self.swapRemove(key) != null);
|
||||
}
|
||||
|
||||
/// Asserts there is an `Entry` with matching key, deletes it from the hash map
|
||||
/// by by shifting all elements forward thereby maintaining the current ordering.
|
||||
pub fn orderedRemoveAssertDiscard(self: *Self, key: K) void {
|
||||
assert(self.orderedRemove(key) != null);
|
||||
}
|
||||
|
||||
pub fn items(self: Self) []Entry {
|
||||
return self.entries.items;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user