pub struct CharCollection { /* private fields */ }
Expand description
A collection of char
s (i.e. Unicode code points), used for storing large continuous ranges
efficiently.
Lookups and insertions are O(log R), where R is the number of disjoint ranges in the collection.
The easiest way to create instances is using the char_collect! macro.
use char_collection::CharCollection;
let mut collection: CharCollection = char_collect!('a'..='d', 'x'..='z');
char_collection += 'e';
char_collection += chars!('p'..='t');
assert_eq!(
collection.iter_ranges().collect(),
vec![chars!('a'..='e'), chars!('p'..='t'), chars!('x'..='z')]);
assert!(collection.contains(&'c'));
assert!(collection.contains_range(chars!('q'..='s')));
assert!(!collection.contains(&'9'));
collection -= chars!('t'..='y');
assert_eq!(
collection.iter_ranges().collect(),
vec![chars!('a'..='e', chars!('p'..'s'), chars!('z'..='z'))]);
TODO(kpozin): Implement IntoIter.
Implementations§
Source§impl CharCollection
impl CharCollection
Sourcepub fn new() -> CharCollection
pub fn new() -> CharCollection
Create a new, empty CharCollection
.
Sourcepub fn from_sorted_ranges<T>(ranges: T) -> Result<CharCollection, Error>where
T: IntoIterator<Item = CharRange>,
pub fn from_sorted_ranges<T>(ranges: T) -> Result<CharCollection, Error>where
T: IntoIterator<Item = CharRange>,
Create a new CharCollection
from a list of disjoint, non-adjacent CharRange
s, pre-sorted
in ascending code point order.
This factory method is primarily intended for use in deserializing valid representations of
CharCollections
. Will return an error if ranges are out of order, overlapping, or
adjacent.
Sourcepub fn from_sorted_chars<T>(chars: T) -> Result<CharCollection, Error>where
T: IntoIterator<Item = char>,
pub fn from_sorted_chars<T>(chars: T) -> Result<CharCollection, Error>where
T: IntoIterator<Item = char>,
Create a new CharCollection
from a list of char
s, pre-sorted in ascending code point
order.
This factory method is primarily intended for use in deserializing valid representations of
CharCollections
. Will return an error if chars are out of order or contain duplicates.
Sourcepub fn iter(&self) -> impl Iterator<Item = char> + '_
pub fn iter(&self) -> impl Iterator<Item = char> + '_
Iterate over all the char
s in the collection.
Sourcepub fn contains(&self, ch: &char) -> bool
pub fn contains(&self, ch: &char) -> bool
Test whether the collection contains a specific char
.
The time complexity is O(log R), where R is the number of ranges in the collection.
Sourcepub fn contains_range(&self, range: &CharRange) -> bool
pub fn contains_range(&self, range: &CharRange) -> bool
Test whether the collection contains an entire range of characters.
The time complexity is O(log R), where R is the number of ranges in the collection.
Sourcepub fn insert<V: MultiCharRange>(&mut self, to_add: &V) -> &mut Self
pub fn insert<V: MultiCharRange>(&mut self, to_add: &V) -> &mut Self
Insert a char
or other collection of chars into this collection.
Returns &mut self
for easy chaining.
The time complexity is O(T log(R + T)), where R
is the number of ranges in this collection and T is the number of ranges in
to_add
.
Sourcepub fn append(&mut self, ch: char) -> Result<&mut Self, Error>
pub fn append(&mut self, ch: char) -> Result<&mut Self, Error>
Appends a char
to the end of the existing collection. Panics if the given char
is not
higher than the highest code point in the existing collection.
Returns &mut self
for easy chaining.
The time complexity is O(1).
Sourcepub fn append_range(&mut self, range: CharRange) -> Result<&mut Self, Error>
pub fn append_range(&mut self, range: CharRange) -> Result<&mut Self, Error>
Appends a CharRange
to the end of the existing collection. Panics if the given range is
not higher than the highest code point in the existing collection. (The new range may be
adjacent to the previous highest range, but may not overlap.)
Returns &mut self
for easy chaining.
The time complexity is O(1).
Sourcepub fn remove<V: MultiCharRange>(&mut self, to_remove: &V) -> &mut Self
pub fn remove<V: MultiCharRange>(&mut self, to_remove: &V) -> &mut Self
Remove a char
or other collection of chars from this collection.
Returns &mut self
for easy chaining.
The time complexity is O(T log(R + T)), where R
is the number of ranges in this collection and T is the number of ranges in
to_remove
.
Sourcepub fn clear(&mut self) -> &mut Self
pub fn clear(&mut self) -> &mut Self
Remove all entries from this collection.
Returns &mut self
for easy chaining.
Sourcepub fn union<V: MultiCharRange>(&self, rhs: &V) -> CharCollection
pub fn union<V: MultiCharRange>(&self, rhs: &V) -> CharCollection
Return the set union of this collection and another one.
The time complexity is O(min(R, T) log(R + T)),
where R is the number of ranges in this collection and T is the number
of ranges in rhs
.
Sourcepub fn intersection<V: MultiCharRange>(&self, rhs: &V) -> CharCollection
pub fn intersection<V: MultiCharRange>(&self, rhs: &V) -> CharCollection
Return the set intersection of this collection and another one.
The time complexity is O(min(R, T) log(R + T)),
where R is the number of ranges in this collection and T is the number
of ranges in rhs
.
Sourcepub fn difference<V: MultiCharRange>(&self, rhs: &V) -> CharCollection
pub fn difference<V: MultiCharRange>(&self, rhs: &V) -> CharCollection
Return the (non-symmetric) set difference of this collection and another one.
The time complexity is O(T log(R + T)), where R
is the number of ranges in this collection and T is the number of ranges in
rhs
.
Sourcepub fn complement(&self) -> CharCollection
pub fn complement(&self) -> CharCollection
Return the set complement of this collection (over the universe of char
s).
The time complexity is O(R), where R is the number of ranges in this collection.
Trait Implementations§
Source§impl<V: MultiCharRange> Add<V> for CharCollection
impl<V: MultiCharRange> Add<V> for CharCollection
Source§impl<V: MultiCharRange> AddAssign<V> for CharCollection
impl<V: MultiCharRange> AddAssign<V> for CharCollection
Source§fn add_assign(&mut self, rhs: V)
fn add_assign(&mut self, rhs: V)
+=
operation. Read moreSource§impl<V: MultiCharRange> BitAnd<V> for CharCollection
impl<V: MultiCharRange> BitAnd<V> for CharCollection
Source§impl<V: MultiCharRange> BitAndAssign<V> for CharCollection
impl<V: MultiCharRange> BitAndAssign<V> for CharCollection
Source§fn bitand_assign(&mut self, rhs: V)
fn bitand_assign(&mut self, rhs: V)
&=
operation. Read moreSource§impl<V: MultiCharRange> BitOr<V> for CharCollection
impl<V: MultiCharRange> BitOr<V> for CharCollection
Source§impl<V: MultiCharRange> BitOrAssign<V> for CharCollection
impl<V: MultiCharRange> BitOrAssign<V> for CharCollection
Source§fn bitor_assign(&mut self, rhs: V)
fn bitor_assign(&mut self, rhs: V)
|=
operation. Read moreSource§impl Clone for CharCollection
impl Clone for CharCollection
Source§fn clone(&self) -> CharCollection
fn clone(&self) -> CharCollection
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for CharCollection
impl Debug for CharCollection
Source§impl Default for CharCollection
impl Default for CharCollection
Source§fn default() -> CharCollection
fn default() -> CharCollection
Source§impl<T: MultiCharRange> From<&T> for CharCollection
impl<T: MultiCharRange> From<&T> for CharCollection
Source§impl Hash for CharCollection
impl Hash for CharCollection
Source§impl MultiCharRange for CharCollection
impl MultiCharRange for CharCollection
Source§fn iter_ranges<'a>(&'a self) -> Box<dyn Iterator<Item = CharRange> + 'a>
fn iter_ranges<'a>(&'a self) -> Box<dyn Iterator<Item = CharRange> + 'a>
Source§fn range_count(&self) -> usize
fn range_count(&self) -> usize
Source§impl Not for CharCollection
impl Not for CharCollection
Source§impl PartialEq for CharCollection
impl PartialEq for CharCollection
Source§impl<V: MultiCharRange> Sub<V> for CharCollection
impl<V: MultiCharRange> Sub<V> for CharCollection
Source§impl<V: MultiCharRange> SubAssign<V> for CharCollection
impl<V: MultiCharRange> SubAssign<V> for CharCollection
Source§fn sub_assign(&mut self, rhs: V)
fn sub_assign(&mut self, rhs: V)
-=
operation. Read moreimpl Eq for CharCollection
impl StructuralPartialEq for CharCollection
Auto Trait Implementations§
impl Freeze for CharCollection
impl RefUnwindSafe for CharCollection
impl Send for CharCollection
impl Sync for CharCollection
impl Unpin for CharCollection
impl UnwindSafe for CharCollection
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)