authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-25 20:50:40-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-25 20:50:40-07:00
logaded86e6909e01dfb45b35204e9dedf6aabb3d58
tree8b84db04a2537cd9005af7fbfab09a825633c0b5
parent21b407b17f25001b70bbd847f9b2d2782866597c

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.

1 files changed, 5 insertions(+), 3 deletions(-)

lib/std/array_hash_map.zig+5-3
......@@ -112,12 +112,10 @@ pub fn ArrayHashMap(
112112 return self.unmanaged.clearAndFree(self.allocator);
113113 }
114114
115 /// Deprecated. Use `items().len`.
116115 pub fn count(self: Self) usize {
117 return self.items().len;
116 return self.unmanaged.count();
118117 }
119118
120 /// Deprecated. Iterate using `items`.
121119 pub fn iterator(self: *const Self) Iterator {
122120 return Iterator{
123121 .hm = self,
......@@ -332,6 +330,10 @@ pub fn ArrayHashMapUnmanaged(
332330 }
333331 }
334332
333 pub fn count(self: Self) usize {
334 return self.entries.items.len;
335 }
336
335337 /// If key exists this function cannot fail.
336338 /// If there is an existing item with `key`, then the result
337339 /// `Entry` pointer points to it, and found_existing is true.