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(...@@ -112,12 +112,10 @@ pub fn ArrayHashMap(
112 return self.unmanaged.clearAndFree(self.allocator);112 return self.unmanaged.clearAndFree(self.allocator);
113 }113 }
114114
115 /// Deprecated. Use `items().len`.
116 pub fn count(self: Self) usize {115 pub fn count(self: Self) usize {
117 return self.items().len;116 return self.unmanaged.count();
118 }117 }
119118
120 /// Deprecated. Iterate using `items`.
121 pub fn iterator(self: *const Self) Iterator {119 pub fn iterator(self: *const Self) Iterator {
122 return Iterator{120 return Iterator{
123 .hm = self,121 .hm = self,
...@@ -332,6 +330,10 @@ pub fn ArrayHashMapUnmanaged(...@@ -332,6 +330,10 @@ pub fn ArrayHashMapUnmanaged(
332 }330 }
333 }331 }
334332
333 pub fn count(self: Self) usize {
334 return self.entries.items.len;
335 }
336
335 /// If key exists this function cannot fail.337 /// If key exists this function cannot fail.
336 /// If there is an existing item with `key`, then the result338 /// If there is an existing item with `key`, then the result
337 /// `Entry` pointer points to it, and found_existing is true.339 /// `Entry` pointer points to it, and found_existing is true.