Expand description
Fixed-size sets of bits (igraph_bitset.h, igraph_bitset_list.h).
Bitset is igraph’s igraph_bitset_t made Rusty: a compact, owned
sequence of bits (one machine word stores 64 of them) that frees its
storage on Drop, can be cloned, compared, iterated and combined with
the usual bit operators &, |, ^ and !. igraph uses bitsets e.g. to
mark visited vertices; BitsetList is the owned list of bitsets
(igraph_bitset_list_t) returned by some algorithms, such as
igraph_reachability (wrapped by
Graph::reachability, which unpacks the
bitsets into booleans).
Bits are indexed from 0 (the least significant bit); Display
prints them like igraph does, most significant first, as a binary number.
use igraph::bitset::Bitset;
let mut visited = Bitset::new(10);
visited.set(2, true);
visited.set(7, true);
assert_eq!(visited.count_ones(), 2);
assert_eq!(visited.iter_ones().collect::<Vec<_>>(), vec![2, 7]);
assert_eq!(visited.to_string(), "0010000100");
let evens: Bitset = (0..10).map(|i| i % 2 == 0).collect();
assert_eq!((&visited & &evens).iter_ones().collect::<Vec<_>>(), vec![2]);
assert_eq!((!&evens).count_ones(), 5);| Rust | C |
|---|---|
Bitset::new, Bitset::clone | igraph_bitset_init, igraph_bitset_init_copy |
len, capacity | igraph_bitset_size, igraph_bitset_capacity |
resize, reserve | igraph_bitset_resize, igraph_bitset_reserve |
get, set, toggle | IGRAPH_BIT_TEST, IGRAPH_BIT_SET, IGRAPH_BIT_CLEAR |
count_ones | igraph_bitset_popcount |
leading_zeros, leading_ones | igraph_bitset_countl_zero, igraph_bitset_countl_one |
trailing_zeros, trailing_ones | igraph_bitset_countr_zero, igraph_bitset_countr_one |
all, any, none, not_all | igraph_bitset_is_all_one, igraph_bitset_is_any_one, igraph_bitset_is_all_zero, igraph_bitset_is_any_zero |
&, |, ^, ! (and &=, …) | igraph_bitset_and, igraph_bitset_or, igraph_bitset_xor, igraph_bitset_not |
fill, clear | igraph_bitset_fill, igraph_bitset_null |
Display | igraph_bitset_print |
Re-exports§
pub use crate::list::BitsetList;
Type Aliases§
- Bitset
- An owned, fixed-size set of bits (
igraph_bitset_t), see the module docs.