Crates.io | arenas |
lib.rs | arenas |
version | 0.2.0 |
source | src |
created_at | 2022-12-19 14:41:23.833263 |
updated_at | 2022-12-21 22:06:01.831791 |
description | Simple Arena data structure for efficiently adding & removing items with stable IDs |
homepage | |
repository | |
max_upload_size | |
id | 741316 |
size | 13,921 |
Provides a super-simple Arena
collection that maps EntryId
s 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
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).