| Crates.io | maplike |
| lib.rs | maplike |
| version | 0.7.2 |
| created_at | 2025-12-19 18:13:32.542366+00 |
| updated_at | 2026-01-20 23:42:20.273865+00 |
| description | Traits for common operations over maps, sets, (stable) vectors. Has built-ins for std, stable-vec, thunderdome, rstar, rstared. |
| homepage | |
| repository | https://codeberg.org/topola/maplike |
| max_upload_size | |
| id | 1995235 |
| size | 36,713 |
This crate provides traits for common operations over map-like data structures: get, insert, remove, stable remove, push.
Rust's standard library collections are supported via built-in convenience implementations:
HashMap, gated by the std feature (enabled by default);HashSet, gated by the std feature (enabled by default);BTreeMap, not feature-gated;BTreeSet, not feature-gated;Vec, not feature-gated, but does not support stable removal.In addition to the standard library, maplike has built-in feature-gated
convenience implementations for data structures from certain external crates:
stable_vec::StableVec,
gated by the stable-vec feature; (example usage:
examples/stable_vec.rs),thunderdome::Arena,
gated by the thunderdome feature; (example usage:
examples/thunderdome.rs),rstar::RTree, gated by the
rstar feature. (example usage: examples/rstar.rs).rstared::RTreed, gated by the
rstared feature.Standard library's VecDeque is unsupported.
Among stable vector data structures,
Slab,
SlotMap,
generational-arena
cannot be supported because they lack interfaces for insertion at an arbitrary
key.
Unlike maps and sets, not all stable vector data
structures allow insertion and removal at arbitrary indexes regardless of
whether they are vacant, occupied or out of bounds. For StableVec, we managed
to implement inserting at out-of-bound indexes by changing the length before
insertion using the
.reserve_for()
method. For thunderdome::Arena, we insert at arbitrary key directly via the
.insert_at()
method. Collections for which we could not achieve this are documented in the
section below.
For Slab, an interface to insert at an arbitrary key is missing apparently
because
the freelist Slab uses to keep
track of its vacant indexes is only singly-linked, not doubly-linked. Inserting
an element at an arbitrary vacant index would require removing that index from
the freelist. But since there is no backwards link available at a given key,
doing so would require traversing the freelist from the beginning to find the
position of the previous node, which would incur an overly slow O(n) time
cost.