Skip to main content

bit_set/
lib.rs

1// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
11//! # Description
12//!
13//! An implementation of a set using a bit vector as an underlying
14//! representation for holding unsigned numerical elements.
15//!
16//! It should also be noted that the amount of storage necessary for holding a
17//! set of objects is proportional to the maximum of the objects when viewed
18//! as a `usize`.
19//!
20//! # Examples
21//!
22//! ```
23//! use bit_set::BitSet;
24//!
25//! // It's a regular set
26//! let mut s = BitSet::new();
27//! s.insert(0);
28//! s.insert(3);
29//! s.insert(7);
30//!
31//! s.remove(7);
32//!
33//! if !s.contains(7) {
34//!     println!("There is no 7");
35//! }
36//!
37//! // Can initialize from a `BitVec`
38//! let other = BitSet::from_bytes(&[0b11010000]);
39//!
40//! s.union_with(&other);
41//!
42//! // Print 0, 1, 3 in some order
43//! for x in s.iter() {
44//!     println!("{}", x);
45//! }
46//!
47//! // Can convert back to a `BitVec`
48//! let bv = s.into_bit_vec();
49//! assert!(bv[3]);
50//! ```
51#![doc(html_root_url = "https://docs.rs/bit-set/0.11.0")]
52#![no_std]
53#![deny(clippy::shadow_reuse)]
54#![deny(clippy::shadow_same)]
55#![deny(clippy::shadow_unrelated)]
56#![warn(clippy::multiple_inherent_impl)]
57#![warn(clippy::multiple_crate_versions)]
58#![warn(clippy::single_match)]
59#![warn(clippy::missing_safety_doc)]
60
61#[cfg(any(test, feature = "std"))]
62extern crate std;
63
64mod iter;
65mod set;
66mod util;
67
68pub(crate) mod local_prelude {
69    pub use bit_vec::{BitBlock, BitVec, Blocks};
70    pub use core::cmp::Ordering;
71    pub use core::iter::{self, Chain, Enumerate, FromIterator, Repeat, Skip, Take};
72    pub use core::{cmp, fmt, hash};
73}
74
75pub use bit_vec::BitBlock;
76pub use set::BitSet;
77
78pub use iter::{Difference, Intersection, Iter, SymmetricDifference, Union};