pub struct DenseBitSetExtended { /* private fields */ }
Expand description
Provides a dense BitSet
implementation (only limited by available memory)
Internally, a Vec<u64>
data structure is used to store information.
This structure implements BitSet, Clone, Default, Debug, Hash, PartialEq, Eq
and bit operations.
Implementations§
Source§impl DenseBitSetExtended
impl DenseBitSetExtended
Sourcepub fn with_capacity(size: usize) -> Self
pub fn with_capacity(size: usize) -> Self
Returns an empty DenseBitsetExtended
with pre-allocated memory of size
bits.
This is useful to avoid additional allocations is situations where the bitset’s space requirements are known in advance.
§Example
let mut bs = DenseBitSetExtended::with_capacity(128);
bs.set_bit(127, true); // No additional allocation performed
Sourcepub fn from_dense_bitset(dbs: DenseBitSet) -> Self
pub fn from_dense_bitset(dbs: DenseBitSet) -> Self
Returns a DenseBitSetExtended
extending a given DenseBitSet
.
§Example
let dbs = DenseBitSet::from_integer(0b111000111);
let dbse = DenseBitSetExtended::from_dense_bitset(dbs);
println!("{}", dbse.to_string())
Sourcepub fn extract_u64(&self, position: usize, length: usize) -> u64
pub fn extract_u64(&self, position: usize, length: usize) -> u64
Returns an integer representation of the bitsting starting at the given position
with given length
(little endian convention).
Note: this method can extract up to 64 bits into an u64
. For larger extractions, use subset
instead.
§Example
let dbs = DenseBitSet::from_integer(0b111000111);
let dbse = DenseBitSetExtended::from_dense_bitset(dbs);
println!("{}", dbse.extract_u64(2, 4)); // Extracts "0001" (displayed with leading zeros)
§Panics
The function panics if length
is zero
let panic_me = dbse.extract_u64(3, 0);
Sourcepub fn subset(&self, position: usize, length: usize) -> Self
pub fn subset(&self, position: usize, length: usize) -> Self
Returns a DenseBitSetExtended
of given length
whose bits are extracted from the given position
.
§Example
let dbs = DenseBitSet::from_integer(0b111000111);
let dbse = DenseBitSetExtended::from_dense_bitset(dbs);
println!("{}", dbse.subset(2, 4).to_string());
Sourcepub fn insert(&mut self, other: &Self, position: usize, length: usize)
pub fn insert(&mut self, other: &Self, position: usize, length: usize)
Inserts the first length
bits of other
at the given position
in the current structure.
§Example
let mut bs = DenseBitSetExtended::new();
let bs2 =
DenseBitSetExtended::from_dense_bitset(DenseBitSet::from_integer(0b1011011101111));
bs.insert(&bs2, 60, 13);
Sourcepub fn insert_u64(&mut self, value: u64, position: usize, length: usize)
pub fn insert_u64(&mut self, value: u64, position: usize, length: usize)
Inserts a length
-bit integer as a bitset at the given position
.
§Example
let mut bs = DenseBitSetExtended::new();
bs.insert_u64(0b1011011101111, 50, 64);
Sourcepub fn reverse(&self) -> Self
pub fn reverse(&self) -> Self
Returns a bit-reversed bitset.
§Example
let val = 66612301234;
let dbs = DenseBitSet::from_integer(val);
let ext_dbs = DenseBitSetExtended::from_dense_bitset(dbs);
println!("{}", dbs.to_string());
println!("{}", ext_dbs.reverse().to_string());
Sourcepub fn rotl(self, shift: usize) -> Self
pub fn rotl(self, shift: usize) -> Self
Returns a left rotation of the bitset by shift
bits.
Note: The bitset is extended by shift
bits by this operation.
Sourcepub fn from_string(s: String, radix: u32) -> Self
pub fn from_string(s: String, radix: u32) -> Self
Constructs a DenseBitSetExtended
from a provided String
.
§Example
let bs2 = DenseBitSetExtended::from_string(String::from("f8d5215a52b57ea0aeb294af576a0aeb"), 16);
§Panics
This function expects a radix between 2 and 32 included, and will otherwise panic. This function will also panic if incorrect characters are provided.
Trait Implementations§
Source§impl BitAnd for DenseBitSetExtended
impl BitAnd for DenseBitSetExtended
Source§impl BitAndAssign for DenseBitSetExtended
impl BitAndAssign for DenseBitSetExtended
Source§fn bitand_assign(&mut self, rhs: Self)
fn bitand_assign(&mut self, rhs: Self)
&=
operation. Read moreSource§impl BitOr for DenseBitSetExtended
impl BitOr for DenseBitSetExtended
Source§impl BitOrAssign for DenseBitSetExtended
impl BitOrAssign for DenseBitSetExtended
Source§fn bitor_assign(&mut self, rhs: Self)
fn bitor_assign(&mut self, rhs: Self)
|=
operation. Read moreSource§impl BitSet for DenseBitSetExtended
This is an extended implementation of the BitSet
trait. It dynamically resizes the bitset as necessary
to accomodate growing or shrinking operations (e.g. left shifts) and is only limited by available memory.
In practice however, we (arbitrarily) limited allocation to 64000 bits.
impl BitSet for DenseBitSetExtended
This is an extended implementation of the BitSet
trait. It dynamically resizes the bitset as necessary
to accomodate growing or shrinking operations (e.g. left shifts) and is only limited by available memory.
In practice however, we (arbitrarily) limited allocation to 64000 bits.
Note: The BitSet
trait must be in scope in order to use methods from this trait.
Note: The Copy
trait cannot be implemented for DenseBitSetExtended
(for the same reasons avec Vec
).
Source§fn get_weight(&self) -> u32
fn get_weight(&self) -> u32
Returns the bitset’s Hamming weight (in other words, the number of bits set to true).
Source§impl BitXor for DenseBitSetExtended
impl BitXor for DenseBitSetExtended
Source§impl BitXorAssign for DenseBitSetExtended
impl BitXorAssign for DenseBitSetExtended
Source§fn bitxor_assign(&mut self, rhs: Self)
fn bitxor_assign(&mut self, rhs: Self)
^=
operation. Read moreSource§impl Clone for DenseBitSetExtended
impl Clone for DenseBitSetExtended
Source§fn clone(&self) -> DenseBitSetExtended
fn clone(&self) -> DenseBitSetExtended
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for DenseBitSetExtended
impl Debug for DenseBitSetExtended
Source§impl Default for DenseBitSetExtended
impl Default for DenseBitSetExtended
Source§fn default() -> DenseBitSetExtended
fn default() -> DenseBitSetExtended
Source§impl Hash for DenseBitSetExtended
impl Hash for DenseBitSetExtended
Source§impl Not for DenseBitSetExtended
impl Not for DenseBitSetExtended
Source§impl PartialEq for DenseBitSetExtended
impl PartialEq for DenseBitSetExtended
Source§impl Shl<usize> for DenseBitSetExtended
impl Shl<usize> for DenseBitSetExtended
Source§impl ShlAssign<usize> for DenseBitSetExtended
impl ShlAssign<usize> for DenseBitSetExtended
Source§fn shl_assign(&mut self, rhs: usize)
fn shl_assign(&mut self, rhs: usize)
<<=
operation. Read moreSource§impl Shr<usize> for DenseBitSetExtended
impl Shr<usize> for DenseBitSetExtended
Source§impl ShrAssign<usize> for DenseBitSetExtended
impl ShrAssign<usize> for DenseBitSetExtended
Source§fn shr_assign(&mut self, rhs: usize)
fn shr_assign(&mut self, rhs: usize)
>>=
operation. Read more