pub struct SampleIndex { /* private fields */ }Expand description
An index for narrowing down a range before binary search.
SampleIndex takes a strictly increasing sequence of n values in 0..universe.
The first value must be 0.
The index chooses a divisor that partitions the universe into approximately n / 8 ranges.
Each range i contains the values in range (i * divisor)..((i + 1) * divisor).
Given a value x, we can restrict the binary search to the range self.range(x) of values.
§Examples
use simple_sds_sbwt::int_vector::IntVector;
use simple_sds_sbwt::ops::{Vector, Access};
use simple_sds_sbwt::rl_vector::index::SampleIndex;
let values: Vec<usize> = vec![0, 33, 124, 131, 224, 291, 322, 341, 394, 466, 501];
let index = SampleIndex::new(values.iter().copied(), 540);
let range = index.range(300);
assert!(values[range.start] <= 300);
let upper_bound = *values.get(range.end).unwrap_or(&540);
assert!(upper_bound > 300);§Notes
- This is a simple support structure not intended to be serialized.
Implementations§
Source§impl SampleIndex
impl SampleIndex
Sourcepub fn new<T: Iterator<Item = usize> + ExactSizeIterator>(
iter: T,
universe: usize,
) -> Self
pub fn new<T: Iterator<Item = usize> + ExactSizeIterator>( iter: T, universe: usize, ) -> Self
Returns a SampleIndex for the given values.
§Arguments
values: A strictly increasing sequence of values starting from0.universe: Universe size. The values must be in range0..universe.
§Panics
Panics if the first value is not 0, the sequence of values is not strictly increasing, or if universe size is too small for the values.
Trait Implementations§
Source§impl Clone for SampleIndex
impl Clone for SampleIndex
Source§fn clone(&self) -> SampleIndex
fn clone(&self) -> SampleIndex
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SampleIndex
impl Debug for SampleIndex
Source§impl PartialEq for SampleIndex
impl PartialEq for SampleIndex
impl Eq for SampleIndex
impl StructuralPartialEq for SampleIndex
Auto Trait Implementations§
impl Freeze for SampleIndex
impl RefUnwindSafe for SampleIndex
impl Send for SampleIndex
impl Sync for SampleIndex
impl Unpin for SampleIndex
impl UnwindSafe for SampleIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more