Skip to content

Conversation

@cuviper
Copy link
Member

@cuviper cuviper commented Nov 20, 2025

This lets us simplify OccupiedEntry to just a reference and a bucket
index, rather than needing a separate reference to our Vec while the
inner entry holds a reference to the HashTable. This in turn lets us
get rid of the RefMut abstraction that was providing common methods
for that pair of references.

The OccupiedEntry currently holds the index for the vector as well,
but this is more of an optimization since most entry methods need it, so
we don't have to indirectly read it through the bucket each time. Thus
the overall size hasn't changed, but we could drop that if we decided
the size was more important.

The sizes of VacantEntry and IndexedEntry are reduced though,
because they're also now holding a single map reference rather than the
double RefMut, which was only needed before due the structure of the
OccupiedEntry. The overall Entry should also be smaller as a result.

This lets us simplify `OccupiedEntry` to just a reference and a bucket
index, rather than needing a separate reference to our `Vec` while the
inner entry holds a reference to the `HashTable`. This in turn lets us
get rid of the `RefMut` abstraction that was providing common methods
for that pair of references.

The `OccupiedEntry` currently holds the index for the vector as well,
but this is more of an optimization since most entry methods need it, so
we don't have to indirectly read it through the bucket each time. Thus
the overall size hasn't changed, but we could drop that if we decided
the size was more important.

The sizes of `VacantEntry` and `IndexedEntry` *are* reduced though,
because they're also now holding a single map reference rather than the
double `RefMut`, which was only needed before due the structure of the
`OccupiedEntry`. The overall `Entry` should also be smaller as a result.
@cuviper cuviper added this pull request to the merge queue Nov 20, 2025
Merged via the queue into indexmap-rs:main with commit cfad758 Nov 20, 2025
16 checks passed
cuviper added a commit to cuviper/ringmap that referenced this pull request Nov 20, 2025
This is similar to indexmap-rs/indexmap#424, simplify a lot of code by
using a bucket index in `OccupiedEntry` rather than having to split
references. The effects are a little more pronounced here because our
`RefMut` needed **3** references, due to the extra offset tracking, so
with that gone, now *every* `*Entry` type is reduced in size.
@cuviper cuviper deleted the buckets branch November 20, 2025 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant