Returns the capacity in bits for this bit vector. Inserting any
element less than this amount will not trigger a resizing.
use bit_set::BitSet;
let mut s = BitSet::with_capacity(100);
assert!(s.capacity() >= 100);
Reserves capacity for the given BitSet
to contain len
distinct elements. In the case
of BitSet
this means reallocations will not occur as long as all inserted elements
are less than len
.
The collection may reserve more space to avoid frequent reallocations.
use bit_set::BitSet;
let mut s = BitSet::new();
s.reserve_len(10);
assert!(s.capacity() >= 10);
Reserves the minimum capacity for the given BitSet
to contain len
distinct elements.
In the case of BitSet
this means reallocations will not occur as long as all inserted
elements are less than len
.
Note that the allocator may give the collection more space than it requests. Therefore
capacity can not be relied upon to be precisely minimal. Prefer reserve_len
if future
insertions are expected.
use bit_set::BitSet;
let mut s = BitSet::new();
s.reserve_len_exact(10);
assert!(s.capacity() >= 10);
Returns a reference to the underlying bit vector.
use bit_set::BitSet;
let mut s = BitSet::new();
s.insert(0);
let bv = s.get_ref();
assert_eq!(bv[0], true);
Truncates the underlying vector to the least length required.
use bit_set::BitSet;
let mut s = BitSet::new();
s.insert(32183231);
s.remove(&32183231);
println!("old capacity: {}", s.capacity());
s.shrink_to_fit();
println!("new capacity: {}", s.capacity());
Iterator over each usize stored in the BitSet
.
use bit_set::BitSet;
let s = BitSet::from_bytes(&[0b01001010]);
for x in s.iter() {
println!("{}", x);
}
Iterator over each usize stored in self
union other
.
See union_with for an efficient in-place version.
use bit_set::BitSet;
let a = BitSet::from_bytes(&[0b01101000]);
let b = BitSet::from_bytes(&[0b10100000]);
for x in a.union(&b) {
println!("{}", x);
}
Iterator over each usize stored in self
intersect other
.
See intersect_with for an efficient in-place version.
use bit_set::BitSet;
let a = BitSet::from_bytes(&[0b01101000]);
let b = BitSet::from_bytes(&[0b10100000]);
for x in a.intersection(&b) {
println!("{}", x);
}
Iterator over each usize stored in the self
setminus other
.
See difference_with for an efficient in-place version.
use bit_set::BitSet;
let a = BitSet::from_bytes(&[0b01101000]);
let b = BitSet::from_bytes(&[0b10100000]);
for x in a.difference(&b) {
println!("{}", x);
}
for x in b.difference(&a) {
println!("{}", x);
}
Iterator over each usize stored in the symmetric difference of self
and other
.
See symmetric_difference_with for
an efficient in-place version.
use bit_set::BitSet;
let a = BitSet::from_bytes(&[0b01101000]);
let b = BitSet::from_bytes(&[0b10100000]);
for x in a.symmetric_difference(&b) {
println!("{}", x);
}
Unions in-place with the specified other bit vector.
use bit_set::BitSet;
let a = 0b01101000;
let b = 0b10100000;
let res = 0b11101000;
let mut a = BitSet::from_bytes(&[a]);
let b = BitSet::from_bytes(&[b]);
let res = BitSet::from_bytes(&[res]);
a.union_with(&b);
assert_eq!(a, res);
Intersects in-place with the specified other bit vector.
use bit_set::BitSet;
let a = 0b01101000;
let b = 0b10100000;
let res = 0b00100000;
let mut a = BitSet::from_bytes(&[a]);
let b = BitSet::from_bytes(&[b]);
let res = BitSet::from_bytes(&[res]);
a.intersect_with(&b);
assert_eq!(a, res);
Makes this bit vector the difference with the specified other bit vector
in-place.
use bit_set::BitSet;
let a = 0b01101000;
let b = 0b10100000;
let a_b = 0b01001000;
let b_a = 0b10000000;
let mut bva = BitSet::from_bytes(&[a]);
let bvb = BitSet::from_bytes(&[b]);
let bva_b = BitSet::from_bytes(&[a_b]);
let bvb_a = BitSet::from_bytes(&[b_a]);
bva.difference_with(&bvb);
assert_eq!(bva, bva_b);
let bva = BitSet::from_bytes(&[a]);
let mut bvb = BitSet::from_bytes(&[b]);
bvb.difference_with(&bva);
assert_eq!(bvb, bvb_a);
Makes this bit vector the symmetric difference with the specified other
bit vector in-place.
use bit_set::BitSet;
let a = 0b01101000;
let b = 0b10100000;
let res = 0b11001000;
let mut a = BitSet::from_bytes(&[a]);
let b = BitSet::from_bytes(&[b]);
let res = BitSet::from_bytes(&[res]);
a.symmetric_difference_with(&b);
assert_eq!(a, res);
Returns the number of set bits in this set.
Returns whether there are no bits set in this set
Clears all bits in this set
Returns true
if this set contains the specified integer.
Returns true
if the set has no elements in common with other
.
This is equivalent to checking for an empty intersection.
Returns true
if the set is a subset of another.
Returns true
if the set is a superset of another.
Adds a value to the set. Returns true
if the value was not already
present in the set.
Removes a value from the set. Returns true
if the value was
present in the set.