authorgravatar for mail@linusgroh.deLinus Groh <mail@linusgroh.de> 2023-07-19 18:17:03+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-20 12:52:05-07:00
log3bada8e3ce9ba72f57c6fbed100c76fd40ba0d15
tree4c1ded13288e198e10c2f53389e1194661e352c7
parent772debb03a3f15cfba5d100925260d86c1fcc9dc

std.hash_map: Fix casing of keyPtr variables

The only case where those should be written in camelCase is if they were function pointers, which they aren't.

1 files changed, 15 insertions(+), 15 deletions(-)

lib/std/hash_map.zig+15-15
......@@ -639,11 +639,11 @@ pub fn HashMap(
639639 return self.unmanaged.removeAdapted(key, ctx);
640640 }
641641
642 /// Delete the entry with key pointed to by keyPtr from the hash map.
643 /// keyPtr is assumed to be a valid pointer to a key that is present
642 /// Delete the entry with key pointed to by key_ptr from the hash map.
643 /// key_ptr is assumed to be a valid pointer to a key that is present
644644 /// in the hash map.
645 pub fn removeByPtr(self: *Self, keyPtr: *K) void {
646 self.unmanaged.removeByPtr(keyPtr);
645 pub fn removeByPtr(self: *Self, key_ptr: *K) void {
646 self.unmanaged.removeByPtr(key_ptr);
647647 }
648648
649649 /// Creates a copy of this map, using the same allocator
......@@ -1433,16 +1433,16 @@ pub fn HashMapUnmanaged(
14331433 return false;
14341434 }
14351435
1436 /// Delete the entry with key pointed to by keyPtr from the hash map.
1437 /// keyPtr is assumed to be a valid pointer to a key that is present
1436 /// Delete the entry with key pointed to by key_ptr from the hash map.
1437 /// key_ptr is assumed to be a valid pointer to a key that is present
14381438 /// in the hash map.
1439 pub fn removeByPtr(self: *Self, keyPtr: *K) void {
1439 pub fn removeByPtr(self: *Self, key_ptr: *K) void {
14401440 // TODO: replace with pointer subtraction once supported by zig
14411441 // if @sizeOf(K) == 0 then there is at most one item in the hash
1442 // map, which is assumed to exist as keyPtr must be valid. This
1442 // map, which is assumed to exist as key_ptr must be valid. This
14431443 // item must be at index 0.
14441444 const idx = if (@sizeOf(K) > 0)
1445 (@intFromPtr(keyPtr) - @intFromPtr(self.keys())) / @sizeOf(K)
1445 (@intFromPtr(key_ptr) - @intFromPtr(self.keys())) / @sizeOf(K)
14461446 else
14471447 0;
14481448
......@@ -2166,10 +2166,10 @@ test "std.hash_map removeByPtr" {
21662166
21672167 i = 0;
21682168 while (i < 10) : (i += 1) {
2169 const keyPtr = map.getKeyPtr(i);
2170 try testing.expect(keyPtr != null);
2169 const key_ptr = map.getKeyPtr(i);
2170 try testing.expect(key_ptr != null);
21712171
2172 if (keyPtr) |ptr| {
2172 if (key_ptr) |ptr| {
21732173 map.removeByPtr(ptr);
21742174 }
21752175 }
......@@ -2185,10 +2185,10 @@ test "std.hash_map removeByPtr 0 sized key" {
21852185
21862186 try testing.expect(map.count() == 1);
21872187
2188 const keyPtr = map.getKeyPtr(0);
2189 try testing.expect(keyPtr != null);
2188 const key_ptr = map.getKeyPtr(0);
2189 try testing.expect(key_ptr != null);
21902190
2191 if (keyPtr) |ptr| {
2191 if (key_ptr) |ptr| {
21922192 map.removeByPtr(ptr);
21932193 }
21942194