8 releases (4 breaking)

Uses old Rust 2015

0.5.3 Jul 23, 2022
0.5.2 May 6, 2020
0.5.1 Mar 21, 2019
0.5.0 Apr 23, 2018
0.1.0 Jun 3, 2015

#17 in Data structures

Download history 502968/week @ 2023-11-21 655269/week @ 2023-11-28 597982/week @ 2023-12-05 592339/week @ 2023-12-12 394850/week @ 2023-12-19 264913/week @ 2023-12-26 514043/week @ 2024-01-02 514562/week @ 2024-01-09 579532/week @ 2024-01-16 540135/week @ 2024-01-23 571368/week @ 2024-01-30 555889/week @ 2024-02-06 527257/week @ 2024-02-13 604593/week @ 2024-02-20 605914/week @ 2024-02-27 501743/week @ 2024-03-05

2,334,603 downloads per month
Used in 4,355 crates (94 directly)

MIT/Apache

48KB
920 lines

WARNING: THIS PROJECT IS IN MAINTENANCE MODE, DUE TO INSUFFICIENT MAINTAINER RESOURCES

It works fine, but will generally no longer be improved.

We are currently only accepting changes which:

  • keep this compiling with the latest versions of Rust or its dependencies.
  • have minimal review requirements, such as documentation changes (so not totally new APIs).

A Set of bits.

Documentation is available at https://contain-rs.github.io/bit-set/bit_set.

Build Status


lib.rs:

An implementation of a set using a bit vector as an underlying representation for holding unsigned numerical elements.

It should also be noted that the amount of storage necessary for holding a set of objects is proportional to the maximum of the objects when viewed as a usize.

Examples

use bit_set::BitSet;

// It's a regular set
let mut s = BitSet::new();
s.insert(0);
s.insert(3);
s.insert(7);

s.remove(7);

if !s.contains(7) {
    println!("There is no 7");
}

// Can initialize from a `BitVec`
let other = BitSet::from_bytes(&[0b11010000]);

s.union_with(&other);

// Print 0, 1, 3 in some order
for x in s.iter() {
    println!("{}", x);
}

// Can convert back to a `BitVec`
let bv = s.into_bit_vec();
assert!(bv[3]);

Dependencies

~79KB