Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force insert at a given key #117

Open
james7132 opened this issue Jun 19, 2022 · 2 comments
Open

Force insert at a given key #117

james7132 opened this issue Jun 19, 2022 · 2 comments

Comments

@james7132
Copy link

james7132 commented Jun 19, 2022

Is it possible to forcibly insert a value at a given key? Either by allocating up to a given key, inserting into a vacant entry, or evicting a already occupied one. I'm in a situation where I need to keep multiple slabs and keep the same key between all of them. Would the bookkeeping make this prohibitively expensive?

@Darksonn
Copy link
Contributor

The cost of that would be linear time. The slab stores the list of unused indexes by threading a linked list through the slab. Removing something from that linked list requires traversing the entire linked list to find the position that comes before it.

@Ralith
Copy link

Ralith commented Jun 19, 2022

An alternative solution to this pattern is to have one slab, used to determine the index and maintain a freelist, and maintain Vec<Option<T>>s on the side that share the same indexes.

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

No branches or pull requests

3 participants