pub struct DArray<const SELECT0_SUPPORT: bool = false> { /* private fields */ }
Expand description
Const generic SELECT0_SUPPORT may optionally add
extra data structures to support fast select0
queries,
which otherwise are not supported.
Implementations§
Source§impl<const SELECT0_SUPPORT: bool> DArray<SELECT0_SUPPORT>
Const genetic SELECT0_SUPPORT
impl<const SELECT0_SUPPORT: bool> DArray<SELECT0_SUPPORT>
Const genetic SELECT0_SUPPORT
Sourcepub fn ones(&self) -> BitVectorBitPositionsIter<'_, true> ⓘ
pub fn ones(&self) -> BitVectorBitPositionsIter<'_, true> ⓘ
Returns a non-consuming iterator over positions of bits set to 1 in the bit vector.
§Examples
use qwt::DArray;
let vv: Vec<usize> = vec![0, 63, 128, 129, 254, 1026];
let da: DArray = vv.iter().copied().collect();
let v: Vec<usize> = da.ones().collect();
assert_eq!(v, vv);
Sourcepub fn ones_with_pos(&self, pos: usize) -> BitVectorBitPositionsIter<'_, true> ⓘ
pub fn ones_with_pos(&self, pos: usize) -> BitVectorBitPositionsIter<'_, true> ⓘ
Returns a non-consuming iterator over positions of bits set to 1 in the bit vector, starting at a specified bit position.
§Examples
use qwt::DArray;
let vv: Vec<usize> = vec![0, 63, 128, 129, 254, 1026];
let da: DArray = vv.iter().copied().collect();
let v: Vec<usize> = da.ones_with_pos(2).collect();
assert_eq!(v, vec![63, 128, 129, 254, 1026]);
Sourcepub fn zeros(&self) -> BitVectorBitPositionsIter<'_, false> ⓘ
pub fn zeros(&self) -> BitVectorBitPositionsIter<'_, false> ⓘ
Returns a non-consuming iterator over positions of bits set to 0 in the bit vector.
§Examples
use qwt::DArray;
use qwt::perf_and_test_utils::negate_vector;
let vv: Vec<usize> = vec![0, 63, 128, 129, 254, 1026];
let da: DArray = vv.iter().copied().collect();
let v: Vec<usize> = da.zeros().collect();
assert_eq!(v, negate_vector(&vv));
Sourcepub fn zeros_with_pos(&self, pos: usize) -> BitVectorBitPositionsIter<'_, false> ⓘ
pub fn zeros_with_pos(&self, pos: usize) -> BitVectorBitPositionsIter<'_, false> ⓘ
Returns a non-consuming iterator over positions of bits set to 0 in the bit vector, starting at a specified bit position.
Sourcepub fn iter(&self) -> BitVectorIter<'_> ⓘ
pub fn iter(&self) -> BitVectorIter<'_> ⓘ
Returns a non-consuming iterator over bits of the bit vector.
§Examples
use qwt::DArray;
let v = vec![0,2,3,5];
let da: DArray = v.into_iter().collect();
let mut iter = da.iter();
assert_eq!(iter.next(), Some(true)); // First bit is true
assert_eq!(iter.next(), Some(false)); // Second bit is false
assert_eq!(iter.next(), Some(true)); // Third bit is true
assert_eq!(iter.next(), Some(true)); // Fourth bit is true
assert_eq!(iter.next(), Some(false)); // Fifth bit is false
assert_eq!(iter.next(), Some(true)); // Sixth bit is true
assert_eq!(iter.next(), None); // End of the iterator
Sourcepub fn count_ones(&self) -> usize
pub fn count_ones(&self) -> usize
Sourcepub fn count_zeros(&self) -> usize
pub fn count_zeros(&self) -> usize
Trait Implementations§
Source§impl<const SELECT0_SUPPORT: bool> AccessBin for DArray<SELECT0_SUPPORT>
impl<const SELECT0_SUPPORT: bool> AccessBin for DArray<SELECT0_SUPPORT>
Source§impl<'de, const SELECT0_SUPPORT: bool> Deserialize<'de> for DArray<SELECT0_SUPPORT>
impl<'de, const SELECT0_SUPPORT: bool> Deserialize<'de> for DArray<SELECT0_SUPPORT>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<V, const SELECT0_SUPPORT: bool> FromIterator<V> for DArray<SELECT0_SUPPORT>
Create a DArray
from an iterator over strictly increasing sequence of integer values.
impl<V, const SELECT0_SUPPORT: bool> FromIterator<V> for DArray<SELECT0_SUPPORT>
Create a DArray
from an iterator over strictly increasing sequence of integer values.
§Panics
Panics if the sequence is not stricly increasing or if any value of the sequence cannot be converted to usize.
§Examples
use qwt::{DArray, AccessBin};
// Create a [`DArray`] from an iterator over strictly increasing sequence of non-negative integer values.
let da: DArray = vec![0, 1, 3, 5].into_iter().collect();
assert_eq!(da.len(), 6);
assert_eq!(da.get(3), Some(true));
Source§impl<const SELECT0_SUPPORT: bool> FromIterator<bool> for DArray<SELECT0_SUPPORT>
Creates a DArray
from an iterator over bool
values.
impl<const SELECT0_SUPPORT: bool> FromIterator<bool> for DArray<SELECT0_SUPPORT>
Creates a DArray
from an iterator over bool
values.
§Examples
use qwt::{AccessBin, DArray};
// Create a bit vector from an iterator over bool values
let da: DArray = vec![true, false, true].into_iter().collect();
assert_eq!(da.len(), 3);
assert_eq!(da.get(1), Some(false));
Source§impl<const SELECT0_SUPPORT: bool> SelectBin for DArray<SELECT0_SUPPORT>
impl<const SELECT0_SUPPORT: bool> SelectBin for DArray<SELECT0_SUPPORT>
Source§fn select1(&self, i: usize) -> Option<usize>
fn select1(&self, i: usize) -> Option<usize>
Answers a select1
query.
The query select1(i)
returns the position of the (i+1)-th
occurrence of 1 in the binary vector.
§Examples
use qwt::{DArray, SelectBin};
let v: Vec<usize> = vec![0, 12, 33, 42, 55, 61, 1000];
let da: DArray = v.into_iter().collect();
assert_eq!(da.select1(1), Some(12));
§Panics
It panics if DArray
is built without support for select0
query.
Source§unsafe fn select1_unchecked(&self, i: usize) -> usize
unsafe fn select1_unchecked(&self, i: usize) -> usize
Answers a select1
query without checking for bounds.
The query select1(i)
returns the position of the (i+1)-th
occurrence of 1 in the binary vector.
§Examples
use qwt::{DArray, SelectBin};
let v: Vec<usize> = vec![0, 12, 33, 42, 55, 61, 1000];
let da: DArray = v.into_iter().collect();
assert_eq!(unsafe{da.select1_unchecked(1)}, 12);
Source§fn select0(&self, i: usize) -> Option<usize>
fn select0(&self, i: usize) -> Option<usize>
Answers a select0
query.
The query select0(i)
returns the position of the (i+1)-th
occurrence of 0 in the binary vector.
§Examples
use qwt::{DArray, SelectBin};
let v: Vec<usize> = vec![0, 12, 33, 42, 55, 61, 1000];
let da: DArray<true> = v.into_iter().collect();
assert_eq!(da.select0(1), Some(2));
assert_eq!(da.select0(11), Some(13));
§Panics
It panics if DArray
is built without support for select0
query.
Source§unsafe fn select0_unchecked(&self, i: usize) -> usize
unsafe fn select0_unchecked(&self, i: usize) -> usize
Answers a select0
query without checkin bounds.
The query select0(i)
returns the position of the (i+1)-th
occurrence of 0 in the binary vector.
§Examples
use qwt::{DArray, SelectBin};
let v: Vec<usize> = vec![0, 12, 33, 42, 55, 61, 1000];
let da: DArray<true> = v.into_iter().collect();
assert_eq!(unsafe{da.select0_unchecked(1)}, 2);
assert_eq!(unsafe{da.select0_unchecked(11)}, 13);
Source§impl<const SELECT0_SUPPORT: bool> SpaceUsage for DArray<SELECT0_SUPPORT>
impl<const SELECT0_SUPPORT: bool> SpaceUsage for DArray<SELECT0_SUPPORT>
Source§fn space_usage_byte(&self) -> usize
fn space_usage_byte(&self) -> usize
Returns the space usage of the data structure in bytes.