Skip to content

Fix for case where calling shrink_to_fit could make the map larger

Alex Hornby requested to merge ahornby/chashmap:shrink_to_fit into master

Reproduced issue by adding new test shrink_to_fit_after_insert. Checked it was failing before doing any changes

With the test in place fixes were:

  1. Make CHashMap::reserve be the place the amortizing growth factor LENGTH_MULTIPLIER is applied, rather than Table::with_capacity ( non-CHashMap::reserve users of Table::with_capacity are requesting a specific capacity and just need load factor applied, not amortizing growth multiplier )

  2. Apply load factor consistently in Table::with_capacity() vs CHashMap::capacity()

  3. Apply MINIMUM_CAPACITY in CHashMap::capacity to stop reported capacity being below requested.

  4. Add test known_size_with_capacity_matches_shrink to test the initial capacity+shrink case

Tested via cargo test

Merge request reports