#arena #zone #area #memory-context

arenas

Simple Arena data structure for efficiently adding & removing items with stable IDs

3 unstable releases

0.2.0 Dec 21, 2022
0.1.1 Dec 19, 2022
0.1.0 Dec 19, 2022

#1617 in Data structures

28 downloads per month

MIT/Apache

14KB
273 lines

Provides a super-simple Arena collection that maps EntryIds to values of some type.

When you insert an item, you get the corresponding ID, and that ID won't change for as long as the item stays in the Arena. You can then retrieve or remove an item by its ID. This is useful for building graph-like data structures (trees, linked lists, or more flexible graphs) – for example, you can describe the relationships between nodes by using their IDs.

Insertion and access by index is efficient, as it's backed by a simple Vec

Alternatives

There are plenty of crates implementing Arenas. The focus of this crate is simplicity – no bells or whistles.

If you want your IDs to stick around even after you remove their corresponding item without causing confusion, consider using generational-arena instead. With that crate, IDs also keep track of the slot's "generation". Removing an item, then adding a new item will produce an ID with a different generation, even though the slot might be the same. (Unlike this crate, where IDs will be reused).

Dependencies

~185KB