alot

alot forbids unsafe code alot is considered alpha crate version Live Build Status HTML Coverage Report for <code>main</code> Documentation for <code>main</code>

A set of collections for storing values in a map-like structure using generated unique keys. The base collection type, Lots<T>, returns a LotId for each stored value. The stored values can be retrieved or removed using their LotId.

This collection provides insert and read performance comparable to Vec<T>, but does not guarantee anything about the order of the contained values.

If ordering is needed, OrderedLots<T> is provided which tracks the order of elements while still allowing lookups by LotId. Removing a value by its LotId becomes an O(n) operation with this collection.

Lots<T>: Unordered collection of T

```rust use alot::Lots;

let mut map = Lots::new(); // Similar to a Vec, push adds a new value to the collection. let greeting = map.push("hello, world"); // Prints: Greeting: LotId { generation: 1, index: 0 } println!("Greeting: {greeting:?}"); // Values can be retrieved by their LotId. assert_eq!(map[greeting], "hello, world"); ```

OrderedLots<T>: Ordered collection of T

```rust use alot::OrderedLots;

let mut map = OrderedLots::new(); // Values stored in OrderedLots can be accessed by index or by their LotId. let c = map.push("c"); let a = map.push("a");

assert_eq!(map[c], map[0]);

// With OrderedLots, values can be inserted as well as pushed. let b = map.insert(1, "b"); assert_eq!(map, &["c", "b", "a"]);

// OrderedLots also provides sorting functions. map.sort(); assert_eq!(map, &["a", "b", "c"]); ```

What separates this crate from others?

There are several approaches to "slot maps" or "generational arenas" or other similarly named structures. This crate takes two approaches that make it unique:

These design choices cause these limitations on this implementation: