#succinct #vector #array #smallvec

vec-collections

Rust collections that are newtype wrappers around smallvec

11 releases

0.2.8 Oct 17, 2020
0.2.7 Oct 17, 2020
0.2.4 Sep 9, 2020
0.2.1 Aug 7, 2020
0.1.1 Nov 6, 2019

#126 in Data structures

Download history 2/week @ 2020-07-04 4/week @ 2020-07-11 8/week @ 2020-08-01 24/week @ 2020-08-08 15/week @ 2020-08-15 1/week @ 2020-08-22 6/week @ 2020-08-29 131/week @ 2020-09-05 423/week @ 2020-09-12 777/week @ 2020-09-19 495/week @ 2020-09-26 105/week @ 2020-10-03 817/week @ 2020-10-10 412/week @ 2020-10-17

945 downloads per month

MIT/Apache

110KB
2.5K SLoC

Vec-collections   Build Status Latest Version Docs Badge

About

This crate provides collections (sets and maps) that wrap SmallVec.

Use cases

Small collections

It happens very frequently that you have collections that have on average just a very small number of elements. If you know the maximum size or even the maximum typical size in advance, you can use this crate to store such collections without allocations. For a larger number of elements, the underlying SmallVec will allocate the elements on the heap as a single allocation.

Read-heavy collections

Another very frequent pattern is that you have a possibly large collection that is being created once and then used readonly for a long time. E.g. lookup tables. In these cases, ease of adding individual new elements is less important than compact in-memory representation and lookup performance. This crate provides succinct collections that have only a very small constant overhead over the contents of the collections.

Performance

Performance for bulk creation as well as lookup is better than BTreeMap/BTreeSet and comparable with HashMap/HashSet for types with a cheap Ord instance, like primitive types, and small to medium sizes. Performance for insertion or removal of individual elements to/from large collections is bad, however. This is not the intended use case.

Collections overview

VecSet

Provides a set backed by a SmallVec of elements.

VecMap

Provides a map backed by a SmallVec of key value pairs.

TotalVecSet

A VecSet with an additional flag so it can support negation. This way it is possible to represent e.g. the set of all u64 except 1.

TotalVecMap

A VecMap with an additional default value, so lookup is a total function.

Unsafe

The in place operations use unsafe code. If that is a problem for you, let me know and I can hide them behind a feature.

Dependencies

~380–540KB
~11K SLoC