slab icon indicating copy to clipboard operation
slab copied to clipboard

Force insert at a given key

Open james7132 opened this issue 3 years ago • 2 comments
trafficstars

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?

james7132 avatar Jun 19 '22 04:06 james7132

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.

Darksonn avatar Jun 19 '22 14:06 Darksonn

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.

Ralith avatar Jun 19 '22 14:06 Ralith