pub struct WaveletMatrix { /* private fields */ }Expand description
An immutable integer vector supporting rank/select-type queries.
Each item consists of the lowest 1 to 64 bits of a u64 value, as specified by the width of the vector.
The vector is represented using WMCore.
There is also an IntVector storing the starting position of each possible item value after the reordering done by the core.
Hence a WaveletMatrix should only be used when most values in 0..(1 << width) are in use.
The maximum length of the vector is approximately usize::MAX items.
A WaveletMatrix can be built from a Vec of unsigned integers using the From trait.
The construction requires several passes over the input and uses the input vector as working space.
Using smaller integer types helps reducing the space overhead during construction.
WaveletMatrix implements the following simple_sds traits:
- Basic functionality:
Vector,Access - Queries and operations:
VectorIndex - Serialization:
Serialize
Overridden default implementations:
VectorIndex::containshas a simple constant-time implementation.VectorIndex::inverse_selectis effectively the same asAccess::get.
§Examples
use simple_sds_sbwt::ops::{Vector, Access, VectorIndex};
use simple_sds_sbwt::wavelet_matrix::WaveletMatrix;
// Construction
let source: Vec<u64> = vec![1, 0, 3, 1, 1, 2, 4, 5, 1, 2, 1, 7, 0, 1];
let wm = WaveletMatrix::from(source.clone());
// Access
assert_eq!(wm.len(), source.len());
assert_eq!(wm.width(), 3);
for i in 0..wm.len() {
assert_eq!(wm.get(i), source[i]);
}
assert!(wm.iter().eq(source.iter().cloned()));
// Rank
assert_eq!(wm.rank(5, 3), 1);
assert_eq!(wm.rank(10, 2), 2);
// Select
assert_eq!(wm.select(2, 1), Some(4));
assert!(wm.select(1, 7).is_none());
assert_eq!(wm.select_iter(1, 2).next(), Some((1, 9)));
// Inverse select
let index = 7;
let inverse = wm.inverse_select(index).unwrap();
assert_eq!(inverse, (0, 5));
assert_eq!(wm.select(inverse.0, inverse.1), Some(index));
// Predecessor / successor
assert!(wm.predecessor(1, 3).next().is_none());
assert_eq!(wm.predecessor(2, 3).next(), Some((0, 2)));
assert_eq!(wm.successor(12, 0).next(), Some((1, 12)));
assert!(wm.successor(13, 0).next().is_none());§Notes
WaveletMatrixnever panics from I/O errors.
Trait Implementations§
Source§impl<'a> Access<'a> for WaveletMatrix
impl<'a> Access<'a> for WaveletMatrix
Source§type Iter = AccessIter<'a, WaveletMatrix>
type Iter = AccessIter<'a, WaveletMatrix>
Source§fn get(&self, index: usize) -> <Self as Vector>::Item
fn get(&self, index: usize) -> <Self as Vector>::Item
Source§fn get_or(
&self,
index: usize,
value: <Self as Vector>::Item,
) -> <Self as Vector>::Item
fn get_or( &self, index: usize, value: <Self as Vector>::Item, ) -> <Self as Vector>::Item
index is invalid. Read moreSource§fn is_mutable(&self) -> bool
fn is_mutable(&self) -> bool
true if the underlying data is mutable. Read moreSource§impl Clone for WaveletMatrix
impl Clone for WaveletMatrix
Source§fn clone(&self) -> WaveletMatrix
fn clone(&self) -> WaveletMatrix
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WaveletMatrix
impl Debug for WaveletMatrix
Source§impl IntoIterator for WaveletMatrix
impl IntoIterator for WaveletMatrix
Source§impl PartialEq for WaveletMatrix
impl PartialEq for WaveletMatrix
Source§impl Serialize for WaveletMatrix
impl Serialize for WaveletMatrix
Source§fn serialize_header<T: Write>(&self, writer: &mut T) -> Result<()>
fn serialize_header<T: Write>(&self, writer: &mut T) -> Result<()>
Source§fn serialize_body<T: Write>(&self, writer: &mut T) -> Result<()>
fn serialize_body<T: Write>(&self, writer: &mut T) -> Result<()>
Source§fn size_in_elements(&self) -> usize
fn size_in_elements(&self) -> usize
Source§fn serialize<T: Write>(&self, writer: &mut T) -> Result<()>
fn serialize<T: Write>(&self, writer: &mut T) -> Result<()>
Source§fn size_in_bytes(&self) -> usize
fn size_in_bytes(&self) -> usize
Source§impl Vector for WaveletMatrix
impl Vector for WaveletMatrix
Source§impl<'a> VectorIndex<'a> for WaveletMatrix
impl<'a> VectorIndex<'a> for WaveletMatrix
Source§type ValueIter = ValueIter<'a>
type ValueIter = ValueIter<'a>
Source§fn contains(&self, value: <Self as Vector>::Item) -> bool
fn contains(&self, value: <Self as Vector>::Item) -> bool
true if the vector contains an item with the given value. Read moreSource§fn value_iter(&'a self, value: <Self as Vector>::Item) -> Self::ValueIter
fn value_iter(&'a self, value: <Self as Vector>::Item) -> Self::ValueIter
value. Read more