pub struct IntVecSlice<'a, T: Storable, E: Endianness, B: AsRef<[u64]>> { /* private fields */ }
Expand description
An immutable, zero-copy slice of an IntVec
.
This struct provides a view into a contiguous portion of an IntVec
without copying the underlying compressed data. It is created by the
slice
or split_at
methods on an IntVec
.
All operations on an IntVecSlice
are relative to the start of the slice,
not the parent vector.
§Examples
use compressed_intvec::variable::{IntVec, UIntVec};
let data: Vec<u32> = (0..100).collect();
let vec: UIntVec<u32> = IntVec::from_slice(&data).unwrap();
// Create a slice of the elements from index 20 to 49
let slice = vec.slice(20, 30).unwrap();
assert_eq!(slice.len(), 30);
// Accessing an element of the slice
// Index 5 of the slice corresponds to index 25 of the original vector
assert_eq!(slice.get(5), Some(25));
// Iterating over the slice
let mut slice_sum = 0;
for value in slice.iter() {
slice_sum += value;
}
assert_eq!(slice_sum, (20..50).sum());
Implementations§
Source§impl<'a, T: Storable, E: Endianness, B: AsRef<[u64]>> IntVecSlice<'a, T, E, B>
impl<'a, T: Storable, E: Endianness, B: AsRef<[u64]>> IntVecSlice<'a, T, E, B>
Sourcepub fn get(&self, index: usize) -> Option<T>where
for<'b> BufBitReader<E, MemWordReader<u64, &'b [u64]>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,
pub fn get(&self, index: usize) -> Option<T>where
for<'b> BufBitReader<E, MemWordReader<u64, &'b [u64]>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,
Returns the element at the specified index within the slice, or None
if
the index is out of bounds.
The index is relative to the start of the slice.
Sourcepub unsafe fn get_unchecked(&self, index: usize) -> Twhere
for<'b> BufBitReader<E, MemWordReader<u64, &'b [u64]>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,
pub unsafe fn get_unchecked(&self, index: usize) -> Twhere
for<'b> BufBitReader<E, MemWordReader<u64, &'b [u64]>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,
Returns the element at index
within the slice without bounds checking.
The index is relative to the start of the slice.
§Safety
Calling this method with an out-of-bounds index is undefined behavior.
The caller must ensure that index < self.len()
.
Sourcepub fn iter(&self) -> IntVecSliceIter<'_, T, E, B> ⓘwhere
for<'b> BufBitReader<E, MemWordReader<u64, &'b [u64]>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,
pub fn iter(&self) -> IntVecSliceIter<'_, T, E, B> ⓘwhere
for<'b> BufBitReader<E, MemWordReader<u64, &'b [u64]>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,
Returns an iterator over the values in the slice.
Source§impl<T, E, B> IntVecSlice<'_, T, E, B>where
T: Storable + Ord,
E: Endianness,
B: AsRef<[u64]>,
for<'b> BufBitReader<E, MemWordReader<u64, &'b [u64]>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,
impl<T, E, B> IntVecSlice<'_, T, E, B>where
T: Storable + Ord,
E: Endianness,
B: AsRef<[u64]>,
for<'b> BufBitReader<E, MemWordReader<u64, &'b [u64]>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,
Sourcepub fn binary_search(&self, value: &T) -> Result<usize, usize>
pub fn binary_search(&self, value: &T) -> Result<usize, usize>
Binary searches this slice for a given element.
If the value is found, returns Ok(usize)
with the index of the
matching element within the slice. If not found, returns Err(usize)
with the insertion point to maintain order.
Sourcepub fn binary_search_by<F>(&self, f: F) -> Result<usize, usize>
pub fn binary_search_by<F>(&self, f: F) -> Result<usize, usize>
Binary searches this slice with a custom comparison function.
Trait Implementations§
Source§impl<'a, T: Clone + Storable, E: Clone + Endianness, B: Clone + AsRef<[u64]>> Clone for IntVecSlice<'a, T, E, B>
impl<'a, T: Clone + Storable, E: Clone + Endianness, B: Clone + AsRef<[u64]>> Clone for IntVecSlice<'a, T, E, B>
Source§fn clone(&self) -> IntVecSlice<'a, T, E, B>
fn clone(&self) -> IntVecSlice<'a, T, E, B>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl<'a, T, E, B> Freeze for IntVecSlice<'a, T, E, B>
impl<'a, T, E, B> RefUnwindSafe for IntVecSlice<'a, T, E, B>
impl<'a, T, E, B> Send for IntVecSlice<'a, T, E, B>
impl<'a, T, E, B> Sync for IntVecSlice<'a, T, E, B>
impl<'a, T, E, B> Unpin for IntVecSlice<'a, T, E, B>
impl<'a, T, E, B> UnwindSafe for IntVecSlice<'a, T, E, B>
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
Source§impl<T, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
impl<T, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DowncastableFrom<T> for T
impl<T> DowncastableFrom<T> for T
Source§fn downcast_from(value: T) -> T
fn downcast_from(value: T) -> T
Source§impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more