arenas

Crates.ioarenas
lib.rsarenas
version0.2.0
sourcesrc
created_at2022-12-19 14:41:23.833263
updated_at2022-12-21 22:06:01.831791
descriptionSimple Arena data structure for efficiently adding & removing items with stable IDs
homepage
repository
max_upload_size
id741316
size13,921
Reinis Mazeiks (rMazeiks)

documentation

README

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).

Commit count: 0

cargo fmt