# std: count hash_map tombstones as available · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/ef0566df7858df3a770a2b3112ca991358974be3)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: ef0566df7858df3a770a2b3112ca991358974be3

Requested commit: ef0566df7858df3a770a2b3112ca991358974be3

Commit: ef0566df7858df3a770a2b3112ca991358974be3

Tree: bf4966f7cd3a7e6a988db12664f07756060053bb

Author: sentientwaffle

Committer: Andrew Kelley

## Message

```
std: count hash_map tombstones as available

When entries are inserted and removed into a hash map at an equivalent rate (maintaining a mostly-consistent total count of entries), it should never need to be resized. But `HashMapUnmanaged.available` does not presently count tombstoned slots as "available", so this put/remove pattern eventually panics (assertion failure) when `available` reaches `0`.

The solution implemented here is to count tombstoned slots as "available". Another approach (which hashbrown (https://github.com/rust-lang/hashbrown/blob/b3eaf32e608d1ec4c10963a4f495503d7f8a7ef5/src/raw/mod.rs#L1455-L1542) takes) would be to rehash all entries in place when there are too many tombstones. This is more complex but avoids an `O(n)` bad case when the hash map is full of many tombstones.

```

## Parents

- [d54ba76e40232f9e8e3f784e927f3138bdd97520](https://git.cafe/gitcafe/zig/commit/d54ba76e40232f9e8e3f784e927f3138bdd97520?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/ef0566df7858df3a770a2b3112ca991358974be3?format=markdown)
