Skip to main content

MatchSet

Struct MatchSet 

Source
pub struct MatchSet { /* private fields */ }
Expand description

Re-export of the sorted, deduplicated match collection. Sorted, deduplicated collection of matches with efficient insertion.

Ensures elements are consistently ordered and handles operations like duplicate removal and overlapping match merges.

§Example

use matchkit::{Match, MatchSet};

let mut set = MatchSet::new();
set.insert(Match::from_parts(1, 0, 10));
set.insert(Match::from_parts(1, 5, 15));
set.merge_overlapping();

assert_eq!(set.len(), 1);
assert_eq!(set.as_slice()[0].end, 15);

Implementations§

Source§

impl MatchSet

Source

pub fn new() -> Self

Create an empty match set.

Source

pub fn try_with_capacity(cap: usize) -> Result<Self>

Create a match set with pre-allocated capacity.

Source

pub fn with_capacity(cap: usize) -> Self

Create a match set with pre-allocated capacity (legacy interface, may panic on OOM).

Source

pub fn try_insert(&mut self, m: Match) -> Result<()>

Insert a match, maintaining sorted order. O(log n) search + O(n) shift.

Source

pub fn insert(&mut self, m: Match)

Insert a match, maintaining sorted order (legacy interface, may panic on OOM).

Source

pub fn try_extend( &mut self, iter: impl IntoIterator<Item = Match>, ) -> Result<()>

Extend with multiple matches, then sort and dedup.

Source

pub fn extend(&mut self, iter: impl IntoIterator<Item = Match>)

Extend with multiple matches, then sort and dedup (legacy interface, may panic on OOM).

Source

pub fn try_merge_overlapping(&mut self) -> Result<()>

Merge overlapping matches into a minimal covering set.

After merging, no two matches in the set overlap. Pattern ID is taken from the first match in each merged group.

Source

pub fn merge_overlapping(&mut self)

Merge overlapping matches into a minimal covering set (legacy interface, may panic on OOM).

Source

pub fn len(&self) -> usize

Number of matches in the set.

Source

pub fn is_empty(&self) -> bool

Whether the set is empty.

Source

pub fn as_slice(&self) -> &[Match]

Get matches as a slice.

Source

pub fn iter(&self) -> Iter<'_, Match>

Returns an iterator over the matches.

Source

pub fn into_vec(self) -> Vec<Match>

Consume the set into a Vec.

Source

pub fn filter_by_pattern(&self, pattern_id: u32) -> Self

Filter matches to only those with the given pattern ID.

Source

pub fn try_filter_by_pattern(&self, pattern_id: u32) -> Result<Self>

Filter matches to only those with the given pattern ID, returning an error on OOM.

Source

pub fn pattern_counts(&self) -> HashMap<u32, usize>

Count matches for each pattern ID.

Source

pub fn try_pattern_counts(&self) -> Result<HashMap<u32, usize>>

Count matches for each pattern ID, returning an error on OOM.

Source

pub fn pattern_ids(&self) -> Vec<u32>

Distinct pattern IDs in the set.

Source

pub fn try_pattern_ids(&self) -> Result<Vec<u32>>

Distinct pattern IDs in the set, returning an error on OOM.

Trait Implementations§

Source§

impl Clone for MatchSet

Source§

fn clone(&self) -> MatchSet

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MatchSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MatchSet

Source§

fn default() -> MatchSet

Returns the “default value” for a type. Read more
Source§

impl<'a> IntoIterator for &'a MatchSet

Source§

type Item = &'a Match

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, Match>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl IntoIterator for MatchSet

Source§

type Item = Match

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<Match>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.