11 releases (7 breaking)

Uses old Rust 2015

0.8.0 Jul 16, 2024
0.6.0 Jun 29, 2024
0.5.3 Jul 23, 2022
0.5.2 May 6, 2020
0.2.0 Jun 4, 2015

#12 in Data structures

Download history 2181173/week @ 2025-03-12 3395362/week @ 2025-03-19 2099486/week @ 2025-03-26 2036099/week @ 2025-04-02 2015511/week @ 2025-04-09 1591656/week @ 2025-04-16 1598882/week @ 2025-04-23 1566308/week @ 2025-04-30 1688674/week @ 2025-05-07 1821237/week @ 2025-05-14 1632525/week @ 2025-05-21 1643234/week @ 2025-05-28 1643815/week @ 2025-06-04 1854426/week @ 2025-06-11 1822677/week @ 2025-06-18 1799326/week @ 2025-06-25

7,443,761 downloads per month
Used in 7,197 crates (118 directly)

Apache-2.0 OR MIT

53KB
937 lines

bit-set

A compact set of bits.

crates.io Documentation Rust CI rustc 1.0+

Dependency Status Download Status

Usage

Add this to your Cargo.toml:

[dependencies]
bit-set = "0.8"

Since Rust 2018, extern crate is no longer mandatory. If your edition is old (Rust 2015), add this to your crate root:

extern crate bit_set;

If you want to use serde, enable it with the serde feature:

[dependencies]
bit-set = { version = "0.8", features = ["serde"] }

If you want to use bit-set in a program that has #![no_std], just drop default features:

[dependencies]
bit-set = { version = "0.8", default-features = false }

Description

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]);

License

Dual-licensed for compatibility with the Rust project.

Licensed under the Apache License Version 2.0: http://www.apache.org/licenses/LICENSE-2.0, or the MIT license: http://opensource.org/licenses/MIT, at your option.

Dependencies

~250KB

OSZAR »