pub struct Segmentation { /* private fields */ }Expand description
CSR-style segmentation: groups elements into segments via offset array.
offsets.len() == n_segments + 1; segment i spans
offsets[i]..offsets[i+1].
Implementations§
Source§impl Segmentation
impl Segmentation
Sourcepub fn from_offsets(offsets: Vec<u32>) -> Self
pub fn from_offsets(offsets: Vec<u32>) -> Self
Build from pre-computed offsets (e.g., [0, 5, 12, 20] for 3 segments).
§Panics
Panics if offsets is empty (needs at least the sentinel [0]).
Sourcepub fn from_change_points<K: PartialEq>(keys: impl Iterator<Item = K>) -> Self
pub fn from_change_points<K: PartialEq>(keys: impl Iterator<Item = K>) -> Self
Build by detecting change-points in a key sequence.
Each run of equal consecutive keys becomes one segment.
§Example
let seg = Segmentation::from_change_points(["A","A","A","B","B","C"].iter().copied());
assert_eq!(seg.count(), 3);Sourcepub fn segment_of(&self, elem: usize) -> usize
pub fn segment_of(&self, elem: usize) -> usize
O(log n) binary-search lookup: which segment contains element elem?
Returns the segment index such that segment(idx) contains elem.
§Panics
Panics if elem is out of range (>= total element count).
Trait Implementations§
Source§impl Clone for Segmentation
impl Clone for Segmentation
Source§fn clone(&self) -> Segmentation
fn clone(&self) -> Segmentation
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 Segmentation
impl Debug for Segmentation
Source§impl PartialEq for Segmentation
impl PartialEq for Segmentation
impl StructuralPartialEq for Segmentation
Auto Trait Implementations§
impl Freeze for Segmentation
impl RefUnwindSafe for Segmentation
impl Send for Segmentation
impl Sync for Segmentation
impl Unpin for Segmentation
impl UnsafeUnpin for Segmentation
impl UnwindSafe for Segmentation
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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