#bitvec #vec #vector #bits #sequence #api #functions

vob

Vector of Bits with Vec-like API and usize backing storage

10 stable releases

✓ Uses Rust 2018 edition

2.0.3 Aug 21, 2019
2.0.2 Dec 18, 2018
2.0.0 Oct 10, 2018
1.3.2 Jul 15, 2018
0.1.0 Feb 1, 2018

#51 in Data structures

Download history 161/week @ 2019-07-08 49/week @ 2019-07-15 190/week @ 2019-07-22 105/week @ 2019-07-29 89/week @ 2019-08-05 51/week @ 2019-08-12 126/week @ 2019-08-19 129/week @ 2019-08-26 167/week @ 2019-09-02 77/week @ 2019-09-09 192/week @ 2019-09-16 136/week @ 2019-09-23 123/week @ 2019-09-30 42/week @ 2019-10-07 115/week @ 2019-10-14

424 downloads per month
Used in 7 crates (5 directly)

Apache-2.0 OR MIT

60KB
955 lines

Build Status Latest version Documentation

Vector of Bits (Vob)

A Vob is a "vector of bits": a sequence of bits which exposes a Vec-like interface. Whereas Vec<bool> requires 1 byte of storage per bit, Vob requires only 1 bit of storage per bit. Vob is broadly similar to BitVec, but has an API more closely aligned to Vec<bool> and allows non-32-bit backing storage. On 64-bit systems this can lead to a substantial performance increase, particularly when functions such as iter_set_bits are used.

Usage

#[macro_use] extern crate vob;

let mut v = vob![false, true, false];
assert_eq!(v[2], false);
v.set(2, true);
assert_eq!(v[2], true);
assert_eq!(v.iter_set_bits(..).collect::<Vec<_>>(), vec![1, 2]);

Migrating from Vec<bool>

As far as possible, Vob is intended to have a superset of Vec<bool>'s interface, which should make porting most code fairly simple. However, Vec<bool> contains several functions which are not yet implemented in Vob: these are missing simply due to a lack of a current use-case rather than because of any fundamental incompatibilities.

There is one missing feature which, currently, is impossible to implement: assignment to an index. In other words one cannot currently express v[0] = true for a Vob v. Until IndexGet / IndexMove and equivalents are implemented in rustc, this restriction appears to be inevitable. Note that referencing by index works (though via a hack identical to that used in BitVec): one can write println!("{}", v[0]) for a Vob v, for example.

Migrating from BitVec

Vob is directly inspired by the BitVec crate, but aims to provide an interface more closely aligned to Vec<bool> Several functions in BitVec have different names in Vob, but porting is in general fairly simple. The main semantic difference is that Vobs clear() function empties the Vob of contents (i.e. sets its length to 0), whereas BitVec's function of the same name unsets all bits (keeping the length unchanged). The same effect as BitVec's clear can be achieved by using Vob's set_all(false) function.

Dependencies

~150KB