| ... | @@ -204,6 +204,10 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3 | ... | @@ -204,6 +204,10 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3 |
| 204 | return hm.internalGet(key); | 204 | return hm.internalGet(key); |
| 205 | } | 205 | } |
| 206 | | 206 | |
| | 207 | pub fn getValue(hm: *const Self, key: K) ?V { |
| | 208 | return if (hm.get(key)) |kv| kv.value else null; |
| | 209 | } |
| | 210 | |
| 207 | pub fn contains(hm: *const Self, key: K) bool { | 211 | pub fn contains(hm: *const Self, key: K) bool { |
| 208 | return hm.get(key) != null; | 212 | return hm.get(key) != null; |
| 209 | } | 213 | } |
| ... | @@ -427,12 +431,14 @@ test "basic hash map usage" { | ... | @@ -427,12 +431,14 @@ test "basic hash map usage" { |
| 427 | | 431 | |
| 428 | testing.expect(map.contains(2)); | 432 | testing.expect(map.contains(2)); |
| 429 | testing.expect(map.get(2).?.value == 22); | 433 | testing.expect(map.get(2).?.value == 22); |
| | 434 | testing.expect(map.getValue(2).? == 22); |
| 430 | | 435 | |
| 431 | const rmv1 = map.remove(2); | 436 | const rmv1 = map.remove(2); |
| 432 | testing.expect(rmv1.?.key == 2); | 437 | testing.expect(rmv1.?.key == 2); |
| 433 | testing.expect(rmv1.?.value == 22); | 438 | testing.expect(rmv1.?.value == 22); |
| 434 | testing.expect(map.remove(2) == null); | 439 | testing.expect(map.remove(2) == null); |
| 435 | testing.expect(map.get(2) == null); | 440 | testing.expect(map.get(2) == null); |
| | 441 | testing.expect(map.getValue(2) == null); |
| 436 | | 442 | |
| 437 | map.removeAssertDiscard(3); | 443 | map.removeAssertDiscard(3); |
| 438 | } | 444 | } |