Skip to main content

PositionSet

Struct PositionSet 

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

A set of usize positions stored as a BitSet. Provides O(1) membership testing and efficient set operations. Caches bounds for cheap overlap pre-checks.

Implementations§

Source§

impl PositionSet

Source

pub fn from_usize_iter<I: IntoIterator<Item = usize>>(iter: I) -> Self

Create a PositionSet from an iterator of usize positions.

Source

pub fn new() -> Self

Create an empty PositionSet.

Source

pub fn len(&self) -> usize

Number of positions in the set.

Source

pub fn is_empty(&self) -> bool

Is the set empty?

Source

pub fn min_pos(&self) -> usize

Returns the minimum position in the set.

Returns usize::MAX for an empty set.

Source

pub fn max_pos(&self) -> usize

Returns the maximum position in the set.

Returns 0 for an empty set.

Source

pub fn insert(&mut self, pos: usize) -> bool

Insert a position.

Source

pub fn extend_from_span(&mut self, span: &PositionSpan)

Extend this set from a PositionSpan without allocating an intermediate set.

Source

pub fn contains(&self, pos: usize) -> bool

Check if position is in the set.

Source

pub fn remove(&mut self, pos: usize) -> bool

Remove a position from the set.

Source

pub fn remove_span(&mut self, span: &PositionSpan)

Remove all positions in a span from the set.

Source

pub fn may_overlap_range(&self, range_start: usize, range_end: usize) -> bool

Quick check if a range [range_start, range_end) might overlap with this set. Returns true if the bounding boxes overlap, false if they definitely don’t. This is O(1) and used as a pre-filter before the expensive BitSet check.

Source

pub fn restricted_to_range(&self, start: usize, end: usize) -> PositionSet

Build the subset of positions that fall within the half-open range [start, end).

The naive form is self.iter().filter(|p| start <= p < end), which always walks the entire set. When this set is a whole-query matchables set (hundreds of thousands of positions for a multi-MB file) but the range is a single small query run (tens of tokens), that full scan is repeated once per run and the per-file cost degrades to O(num_runs * total_positions) — quadratic in file size. Translation catalogs (.po) are the pathological case: thousands of small runs over a single huge token stream.

Instead, iterate whichever side is smaller. The clamped range can never be longer than the set’s own span, and for a small run it is far shorter, so we probe range.contains against this set’s O(1) membership test. For a range that spans the whole set (the whole-query run) we fall back to walking the set directly, which is the same work as before.

Source

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

Compute the union of this set with another PositionSet.

Returns a new PositionSet containing all positions from both sets.

Source

pub fn difference(&self, other: &PositionSet) -> PositionSet

Return the difference (elements in self but not in other).

Source

pub fn intersection_len(&self, other: &PositionSet) -> usize

Count elements in the intersection of self and other.

Source

pub fn overlaps_span(&self, span: &PositionSpan) -> bool

Check if this set overlaps with a PositionSpan. Uses O(1) bounds check before the O(n) element-wise check.

Source

pub fn contains_range(&self, range: Range<usize>) -> bool

Check if this set contains all positions in a range. Returns true for empty ranges.

Source

pub fn iter(&self) -> impl Iterator<Item = usize> + '_

Iterate over positions.

Source

pub fn to_position_span(&self) -> PositionSpan

Convert this PositionSet to a PositionSpan.

If positions are contiguous, returns a Range; otherwise returns Discrete.

Trait Implementations§

Source§

impl Clone for PositionSet

Source§

fn clone(&self) -> PositionSet

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for PositionSet

Source§

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

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

impl Default for PositionSet

Source§

fn default() -> Self

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

impl Eq for PositionSet

Source§

impl FromIterator<usize> for PositionSet

Source§

fn from_iter<T: IntoIterator<Item = usize>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for PositionSet

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PositionSet

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> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

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

Source§

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

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

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

Source§

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

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToAst for T

Source§

fn ast(self, begin: usize, end: usize) -> Spanned<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<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

Source§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
Source§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

Source§

fn to_owned_table(&self) -> U

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

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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