Skip to main content

Subset

Struct Subset 

pub struct Subset { /* private fields */ }
Expand description

Represents a multi-subset of a string, that is a subset where elements can be included multiple times. This is represented as each element of the string having a “count” which is the number of times that element is included in the set.

Internally, this is stored as a list of “segments” with a length and a count.

Implementations§

§

impl Subset

pub fn new(len: usize) -> Subset

Creates an empty Subset of a string of length len

pub fn delete_from_string(&self, s: &str) -> String

Mostly for testing.

pub fn delete_from<N>(&self, s: &Node<N>) -> Node<N>
where N: NodeInfo,

Builds a version of s with all the elements in this Subset deleted from it.

pub fn len_after_delete(&self) -> usize

The length of the resulting sequence after deleting this subset. A convenience alias for self.count(CountMatcher::Zero) to reduce thinking about what that means in the cases where the length after delete is what you want to know.

self.delete_from_string(s).len() = self.len(s.len())

pub fn count(&self, matcher: CountMatcher) -> usize

Count the total length of all the segments matching matcher.

pub fn len(&self) -> usize

Convenience alias for self.count(CountMatcher::All)

pub fn is_empty(&self) -> bool

Determine whether the subset is empty. In this case deleting it would do nothing.

pub fn union(&self, other: &Subset) -> Subset

Compute the union of two subsets. The count of an element in the result is the sum of the counts in the inputs.

pub fn subtract(&self, other: &Subset) -> Subset

Compute the difference of two subsets. The count of an element in the result is the subtraction of the counts of other from self.

pub fn bitxor(&self, other: &Subset) -> Subset

Compute the bitwise xor of two subsets, useful as a reversible difference. The count of an element in the result is the bitwise xor of the counts of the inputs. Unchanged segments will be 0.

This works like set symmetric difference when all counts are 0 or 1 but it extends nicely to the case of larger counts.

pub fn transform_expand(&self, other: &Subset) -> Subset

Transform through coordinate transform represented by other. The equation satisfied is as follows:

s1 = other.delete_from_string(s0)

s2 = self.delete_from_string(s1)

element in self.transform_expand(other).delete_from_string(s0) if (not in s1) or in s2

pub fn transform_union(&self, other: &Subset) -> Subset

The same as taking transform_expand and then unioning with other.

pub fn transform_shrink(&self, other: &Subset) -> Subset

Transform subset through other coordinate transform, shrinking. The following equation is satisfied:

C = A.transform_expand(B)

B.transform_shrink(C).delete_from_string(C.delete_from_string(s)) = A.delete_from_string(B.delete_from_string(s))

pub fn range_iter(&self, matcher: CountMatcher) -> RangeIter<'_>

Return an iterator over the ranges with a count matching the matcher. These will often be easier to work with than raw segments.

pub fn complement_iter(&self) -> RangeIter<'_>

Convenience alias for self.range_iter(CountMatcher::Zero). Semantically iterates the ranges of the complement of this Subset.

pub fn zip<'a>(&'a self, other: &'a Subset) -> ZipIter<'a>

Return an iterator over ZipSegments where each ZipSegment contains the count for both self and other in that range. The two Subsets must have the same total length.

Each returned ZipSegment will differ in at least one count.

pub fn complement(&self) -> Subset

Find the complement of this Subset. Every 0-count element will have a count of 1 and every non-zero element will have a count of 0.

pub fn mapper(&self, matcher: CountMatcher) -> Mapper<'_>

Return a Mapper that can be use to map coordinates in the document to coordinates in this Subset, but only in non-decreasing order for performance reasons.

Trait Implementations§

§

impl Clone for Subset

§

fn clone(&self) -> Subset

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
§

impl Debug for Subset

§

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

Use the alternate flag (#) to print a more compact representation where each character represents the count of one element: ‘-’ is 0, ‘#’ is 1, 2-9 are digits, + is >9

§

impl<'de> Deserialize<'de> for Subset

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Subset, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl PartialEq for Subset

§

fn eq(&self, other: &Subset) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Serialize for Subset

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl Eq for Subset

§

impl StructuralPartialEq for Subset

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
§

impl<T> AnyEq for T
where T: Any + PartialEq,

§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

§

fn as_any(&self) -> &(dyn Any + 'static)

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,

§

impl<T> WasmNotSync for T
where T: Sync,