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
impl MatchSet
Sourcepub fn try_with_capacity(cap: usize) -> Result<Self>
pub fn try_with_capacity(cap: usize) -> Result<Self>
Create a match set with pre-allocated capacity.
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Create a match set with pre-allocated capacity (legacy interface, may panic on OOM).
Sourcepub fn try_insert(&mut self, m: Match) -> Result<()>
pub fn try_insert(&mut self, m: Match) -> Result<()>
Insert a match, maintaining sorted order. O(log n) search + O(n) shift.
Sourcepub fn insert(&mut self, m: Match)
pub fn insert(&mut self, m: Match)
Insert a match, maintaining sorted order (legacy interface, may panic on OOM).
Sourcepub fn try_extend(
&mut self,
iter: impl IntoIterator<Item = Match>,
) -> Result<()>
pub fn try_extend( &mut self, iter: impl IntoIterator<Item = Match>, ) -> Result<()>
Extend with multiple matches, then sort and dedup.
Sourcepub fn extend(&mut self, iter: impl IntoIterator<Item = Match>)
pub fn extend(&mut self, iter: impl IntoIterator<Item = Match>)
Extend with multiple matches, then sort and dedup (legacy interface, may panic on OOM).
Sourcepub fn try_merge_overlapping(&mut self) -> Result<()>
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.
Sourcepub fn merge_overlapping(&mut self)
pub fn merge_overlapping(&mut self)
Merge overlapping matches into a minimal covering set (legacy interface, may panic on OOM).
Sourcepub fn filter_by_pattern(&self, pattern_id: u32) -> Self
pub fn filter_by_pattern(&self, pattern_id: u32) -> Self
Filter matches to only those with the given pattern ID.
Sourcepub fn try_filter_by_pattern(&self, pattern_id: u32) -> Result<Self>
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.
Sourcepub fn pattern_counts(&self) -> HashMap<u32, usize>
pub fn pattern_counts(&self) -> HashMap<u32, usize>
Count matches for each pattern ID.
Sourcepub fn try_pattern_counts(&self) -> Result<HashMap<u32, usize>>
pub fn try_pattern_counts(&self) -> Result<HashMap<u32, usize>>
Count matches for each pattern ID, returning an error on OOM.
Sourcepub fn pattern_ids(&self) -> Vec<u32>
pub fn pattern_ids(&self) -> Vec<u32>
Distinct pattern IDs in the set.
Sourcepub fn try_pattern_ids(&self) -> Result<Vec<u32>>
pub fn try_pattern_ids(&self) -> Result<Vec<u32>>
Distinct pattern IDs in the set, returning an error on OOM.