#set #fixed-size #map #elements #numbers #ordered #iteration

no-std petitset

An ordered set data structure, optimized for stack-allocated storage of a tiny number of elements with a fixed cap

5 releases

0.2.1 Feb 8, 2022
0.2.0 Feb 1, 2022
0.1.2 Jan 26, 2022
0.1.1 Jan 21, 2022
0.1.0 Jan 21, 2022

#2112 in Data structures

Download history 455/week @ 2024-05-17 382/week @ 2024-05-24 444/week @ 2024-05-31 272/week @ 2024-06-07 376/week @ 2024-06-14 390/week @ 2024-06-21 273/week @ 2024-06-28 244/week @ 2024-07-05 452/week @ 2024-07-12 438/week @ 2024-07-19 438/week @ 2024-07-26 779/week @ 2024-08-02 915/week @ 2024-08-09 659/week @ 2024-08-16 981/week @ 2024-08-23 900/week @ 2024-08-30

3,663 downloads per month

MIT/Apache

54KB
792 lines

About

Array-backed ordered set and map data structures in Rust, optimized for stack-allocated storage of a tiny number of elements with a fixed cap. All you need is Eq!

This crate is:

  • entirely safe
  • fully documented
  • no_std compatible
  • zero dependencies (unless you want thiserror or serde integration)

This crate is designed to be used in performance-sensitive contexts with a small number of elements, where iteration is more common than look-ups and you don't mind a fixed size. One particularly useful quirk is that elements are not recompacted upon removal: this can be very useful when replacing elements in a set or using the indexes that the elements are stored at in a semantic fashion. Iteration order is guaranteed to be stable, on a first-in-first-out basis.

If this isn't what you're after, check out one of these alternatives!

  • smolset: automatically converts to a HashSet when the number of elements is too large. Unordered.
  • array_map: Blazing fast, fixed size. All possible keys must be known statically.
  • sparseset: Heap-allocated, great for sparse data and frequent iteration. Stable order!
  • HashSet: Heap-allocated, unordered, requires Hash, unbounded size.
  • BTreeSet: Heap-allocated, ordered, requires Ord, unbounded size.
  • IndexMap: Heap-allocated, requires Hash, unbounded size.

This crate has a reasonable collection of convenience methods for working with both sets and maps, aiming for rough equivalence with HashMap and HashSet. If you'd like more, please submit an issue or PR!

Dependencies

~170KB