7 stable releases

Uses old Rust 2015

1.2.4 Aug 4, 2021
1.2.3 Mar 15, 2021
1.2.2 Nov 21, 2019
1.2.1 Jul 31, 2019
1.1.0 Oct 17, 2018

#1950 in Data structures

Download history 3269/week @ 2024-07-29 3059/week @ 2024-08-05 2690/week @ 2024-08-12 3602/week @ 2024-08-19 3612/week @ 2024-08-26 3097/week @ 2024-09-02 2674/week @ 2024-09-09 3012/week @ 2024-09-16 2808/week @ 2024-09-23 3681/week @ 2024-09-30 3298/week @ 2024-10-07 4056/week @ 2024-10-14 3868/week @ 2024-10-21 3963/week @ 2024-10-28 3693/week @ 2024-11-04 3123/week @ 2024-11-11

14,857 downloads per month
Used in 14 crates (2 directly)

Apache-2.0/MIT

28KB
506 lines

Build Status Latest version Documentation

PackedVec

A PackedVec stores vectors of integers efficiently while providing an API similar to Vec. The basic idea is to store each element using the minimum number of bits needed to represent every element in the Vec. For example, if we have a Vec<u64> with elements [20, 30, 140], every element wastes most of its 64 bits: 7 bits is sufficient to represent the range of elements in the vector. Given this input vector, PackedVec stores each elements using exactly 7 bits, saving substantial memory. For vectors which often contain small ranges of numbers, and which are created rarely, but read from frequently, this can be a significant memory and performance win.

Examples

PackedVec has two main API differences from Vec: a PackedVec is created from a Vec; and a PackedVec returns values rather than references. Both points can be seen in this example:

use packedvec::PackedVec;
let v = vec![-1, 30, 120];
let pv = PackedVec::new(v.clone());
assert_eq!(pv.get(0), Some(-1));
assert_eq!(pv.get(2), Some(120));
assert_eq!(pv.get(3), None);
assert_eq!(v.iter().cloned().collect::<Vec<_>>(), pv.iter().collect::<Vec<_>>());

Dependencies

~94–310KB