#key-value #id #integer #order-id #maps #automatic #vec

idmap

Efficient maps of integer id keys to values, backed by an underlying Vec

24 releases

0.2.21 Sep 6, 2021
0.2.19 Jun 7, 2020
0.2.16 Aug 24, 2018
0.2.14 May 22, 2018
0.2.3 Oct 29, 2017

#1543 in Data structures

Download history 3/week @ 2024-02-09 16/week @ 2024-02-16 73/week @ 2024-02-23 63/week @ 2024-03-01 41/week @ 2024-03-08 32/week @ 2024-03-15 21/week @ 2024-03-22 194/week @ 2024-03-29

296 downloads per month

MIT license

84KB
2K SLoC

rust-idmap Crates.io Documentation

Efficient maps of integer id keys to values, backed by an underlying Vec.

Features

  • Compiles on stable rust
    • I only officially support the latest stable ;)
  • Automatically derived IntegerId for enums and newtype structs
    • Implemented in the idmap-derive proc_macro crate
  • Maintains insertion order of the entries, as there's an indirection like OrderMap.
    • Therefore, entries which aren't present take little space, as only a u32 needs to be stored.
    • This indirection can be avoided with a DirectIdMap which doesn't preserve order, and saves space when the ids of the map's keys are densly packed and mostly present.

lib.rs:

Efficient maps of integer id keys to values, backed by an underlying Vec.

However, unless a CompactIdMap is used, space requirements are O(n) the largest key. Any type that implements IntegerId can be used for the key, but no storage is wasted if the key can be represented from the id.

Dependencies

~76–530KB
~11K SLoC