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