• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..30-Mar-2022-

src/H30-Mar-2022-3,0412,174

.cargo-checksum.jsonH A D03-May-202227 11

Cargo.tomlH A D30-Mar-2022602 2218

LICENSEH A D30-Mar-202212 KiB221182

README.mdH A D30-Mar-20222.2 KiB4134

README.md

1This crate contains array-based data structures used by the core Cranelift code
2generator which use densely numbered entity references as mapping keys.
3
4One major difference between this crate and crates like [slotmap], [slab],
5and [generational-arena] is that this crate currently provides no way to delete
6entities. This limits its use to situations where deleting isn't important,
7however this also makes it more efficient, because it doesn't need extra
8bookkeeping state to reuse the storage for deleted objects, or to ensure that
9new objects always have unique keys (eg. slotmap's and generational-arena's
10versioning).
11
12Another major difference is that this crate protects against using a key from
13one map to access an element in another. Where `SlotMap`, `Slab`, and `Arena`
14have a value type parameter, `PrimaryMap` has a key type parameter and a value
15type parameter. The crate also provides the `entity_impl` macro which makes it
16easy to declare new unique types for use as keys. Any attempt to use a key in
17a map it's not intended for is diagnosed with a type error.
18
19Another is that this crate has two core map types, `PrimaryMap` and
20`SecondaryMap`, which serve complementary purposes. A `PrimaryMap` creates its
21own keys when elements are inserted, while an `SecondaryMap` reuses the keys
22values of a `PrimaryMap`, conceptually storing additional data in the same
23index space. `SecondaryMap`'s values must implement `Default` and all elements
24in an `SecondaryMap` initially have the value of `default()`.
25
26A common way to implement `Default` is to wrap a type in `Option`, however
27this crate also provides the `PackedOption` utility which can use less memory
28in some cases.
29
30Additional utilities provided by this crate include:
31 - `EntityList`, for allocating many small arrays (such as instruction operand
32    lists in a compiler code generator).
33 - `SparseMap`: an alternative to `SecondaryMap` which can use less memory
34   in some situations.
35 - `EntitySet`: a specialized form of `SecondaryMap` using a bitvector to
36   record which entities are members of the set.
37
38[slotmap]: https://crates.io/crates/slotmap
39[slab]: https://crates.io/crates/slab
40[generational-arena]: https://crates.io/crates/generational-arena
41