Skip to main content

BitVector

Struct BitVector 

Source
pub struct BitVector {
    data: Vec<(usize, usize)>,
    sum: usize,
    len: usize,
}

Fields§

§data: Vec<(usize, usize)>

[(bit, sum)]

§sum: usize§len: usize

Implementations§

Source§

impl BitVector

Source

const WORD_SIZE: usize

Source

pub fn with_capacity(bits: usize) -> Self

Examples found in repository?
crates/competitive/src/data_structure/bit_vector.rs (line 168)
164    fn from_iter<T: IntoIterator<Item = bool>>(iter: T) -> Self {
165        let iter = iter.into_iter();
166        let (lower, upper) = iter.size_hint();
167        let mut bit_vector = match upper {
168            Some(upper) => Self::with_capacity(upper),
169            None => Self::with_capacity(lower),
170        };
171        for b in iter {
172            bit_vector.push(b);
173        }
174        bit_vector
175    }
More examples
Hide additional examples
crates/competitive/src/data_structure/wavelet_matrix.rs (line 29)
21    pub fn new(v: Vec<T>) -> Self {
22        let len = v.len();
23        let compress: VecCompress<T> = v.iter().cloned().collect();
24        let bit_length = usize::BITS as usize - compress.size().leading_zeros() as usize;
25        let mut indices: Vec<usize> = v
26            .iter()
27            .map(|value| compress.index_exact(value).unwrap())
28            .collect();
29        let mut bit_vector = BitVector::with_capacity(len * bit_length);
30        let mut zeros = Vec::with_capacity(bit_length);
31        for d in (0..bit_length).rev() {
32            let mut zero_count = 0;
33            for &idx in &indices {
34                let bit = ((idx >> d) & 1) != 0;
35                bit_vector.push(bit);
36                if !bit {
37                    zero_count += 1;
38                }
39            }
40            zeros.push(zero_count);
41            let mut next = Vec::with_capacity(len);
42            next.extend(
43                indices
44                    .iter()
45                    .filter(|&&idx| ((idx >> d) & 1) == 0)
46                    .copied(),
47            );
48            next.extend(
49                indices
50                    .iter()
51                    .filter(|&&idx| ((idx >> d) & 1) == 1)
52                    .copied(),
53            );
54            indices = next;
55        }
56        let mut ones_prefix = Vec::with_capacity(bit_length);
57        let mut prefix = 0;
58        for &zero in &zeros {
59            ones_prefix.push(prefix);
60            prefix += len - zero;
61        }
62        Self {
63            len,
64            bit_length,
65            zeros,
66            ones_prefix,
67            bit_vector,
68            compress,
69        }
70    }
Source

pub fn push(&mut self, bit: bool)

Examples found in repository?
crates/competitive/src/data_structure/bit_vector.rs (line 172)
164    fn from_iter<T: IntoIterator<Item = bool>>(iter: T) -> Self {
165        let iter = iter.into_iter();
166        let (lower, upper) = iter.size_hint();
167        let mut bit_vector = match upper {
168            Some(upper) => Self::with_capacity(upper),
169            None => Self::with_capacity(lower),
170        };
171        for b in iter {
172            bit_vector.push(b);
173        }
174        bit_vector
175    }
More examples
Hide additional examples
crates/competitive/src/data_structure/wavelet_matrix.rs (line 35)
21    pub fn new(v: Vec<T>) -> Self {
22        let len = v.len();
23        let compress: VecCompress<T> = v.iter().cloned().collect();
24        let bit_length = usize::BITS as usize - compress.size().leading_zeros() as usize;
25        let mut indices: Vec<usize> = v
26            .iter()
27            .map(|value| compress.index_exact(value).unwrap())
28            .collect();
29        let mut bit_vector = BitVector::with_capacity(len * bit_length);
30        let mut zeros = Vec::with_capacity(bit_length);
31        for d in (0..bit_length).rev() {
32            let mut zero_count = 0;
33            for &idx in &indices {
34                let bit = ((idx >> d) & 1) != 0;
35                bit_vector.push(bit);
36                if !bit {
37                    zero_count += 1;
38                }
39            }
40            zeros.push(zero_count);
41            let mut next = Vec::with_capacity(len);
42            next.extend(
43                indices
44                    .iter()
45                    .filter(|&&idx| ((idx >> d) & 1) == 0)
46                    .copied(),
47            );
48            next.extend(
49                indices
50                    .iter()
51                    .filter(|&&idx| ((idx >> d) & 1) == 1)
52                    .copied(),
53            );
54            indices = next;
55        }
56        let mut ones_prefix = Vec::with_capacity(bit_length);
57        let mut prefix = 0;
58        for &zero in &zeros {
59            ones_prefix.push(prefix);
60            prefix += len - zero;
61        }
62        Self {
63            len,
64            bit_length,
65            zeros,
66            ones_prefix,
67            bit_vector,
68            compress,
69        }
70    }

Trait Implementations§

Source§

impl Clone for BitVector

Source§

fn clone(&self) -> BitVector

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BitVector

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromIterator<bool> for BitVector

Source§

fn from_iter<T: IntoIterator<Item = bool>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl RankSelectDictionaries for BitVector

Source§

fn bit_length(&self) -> usize

Source§

fn access(&self, k: usize) -> bool

get k-th bit
Source§

fn rank1(&self, k: usize) -> usize

the number of 1 in [0, k)
Source§

fn select1(&self, k: usize) -> Option<usize>

index of k-th 1
Source§

fn select0(&self, k: usize) -> Option<usize>

index of k-th 0
Source§

fn rank0(&self, k: usize) -> usize

the number of 0 in [0, k)

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToArrayVecScalar for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.