diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-09-25 20:50:40 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-09-25 20:50:40 -0700 |
| commit | aded86e6909e01dfb45b35204e9dedf6aabb3d58 (patch) | |
| tree | 8b84db04a2537cd9005af7fbfab09a825633c0b5 /lib/std/array_hash_map.zig | |
| parent | 21b407b17f25001b70bbd847f9b2d2782866597c (diff) | |
| download | zig-aded86e6909e01dfb45b35204e9dedf6aabb3d58.tar.gz zig-aded86e6909e01dfb45b35204e9dedf6aabb3d58.zip | |
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.
Diffstat (limited to 'lib/std/array_hash_map.zig')
| -rw-r--r-- | lib/std/array_hash_map.zig | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/std/array_hash_map.zig b/lib/std/array_hash_map.zig index f8c3623ef2..649c1e1055 100644 --- a/lib/std/array_hash_map.zig +++ b/lib/std/array_hash_map.zig @@ -112,12 +112,10 @@ pub fn ArrayHashMap( return self.unmanaged.clearAndFree(self.allocator); } - /// Deprecated. Use `items().len`. 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 { return Iterator{ .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 there is an existing item with `key`, then the result /// `Entry` pointer points to it, and found_existing is true. |
