std.ArrayHashMap: count and iterator are not deprecated
These APIs allow one to write code that is agnostic of whether it is using an ArrayHashMap or a HashMap, which can be valuable. Specify intent precisely: if you only need the count of the items, it makes sense to have a function for that.
This commit is contained in:
parent
21b407b17f
commit
aded86e690
@ -112,12 +112,10 @@ pub fn ArrayHashMap(
|
|||||||
return self.unmanaged.clearAndFree(self.allocator);
|
return self.unmanaged.clearAndFree(self.allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deprecated. Use `items().len`.
|
|
||||||
pub fn count(self: Self) usize {
|
pub fn count(self: Self) usize {
|
||||||
return self.items().len;
|
return self.unmanaged.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deprecated. Iterate using `items`.
|
|
||||||
pub fn iterator(self: *const Self) Iterator {
|
pub fn iterator(self: *const Self) Iterator {
|
||||||
return Iterator{
|
return Iterator{
|
||||||
.hm = self,
|
.hm = self,
|
||||||
@ -332,6 +330,10 @@ pub fn ArrayHashMapUnmanaged(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn count(self: Self) usize {
|
||||||
|
return self.entries.items.len;
|
||||||
|
}
|
||||||
|
|
||||||
/// If key exists this function cannot fail.
|
/// If key exists this function cannot fail.
|
||||||
/// If there is an existing item with `key`, then the result
|
/// If there is an existing item with `key`, then the result
|
||||||
/// `Entry` pointer points to it, and found_existing is true.
|
/// `Entry` pointer points to it, and found_existing is true.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user