fixedbitset_utils

Struct LexBitSet

Source
pub struct LexBitSet<'a>(pub &'a FixedBitSet);
Expand description

A totally ordered Bitset wrapper. Useful to implement tie break mechanisms. This wrapper orders the bitsets according to the lexical order of their underlying bits.

§Note:

This implementation uses the underlying words representation of the bitsets to perform several comparisons at once. Hence, using a LexBitSet should be more efficient than trying to establish the total ordering yourself with a loop on the 1-bits of the two sets.

§Example


let mut a = FixedBitSet::with_capacity(5);
let mut b = FixedBitSet::with_capacity(5);

a.set(2, true);  // bits 0..2 match for a and b
b.set(2, true);

a.set(3, false); // a and b diverge on bit 3
b.set(3, true);  // and a has a 0 bit in that pos

a.set(4, true);  // anything that remains after
b.set(4, false); // the firs lexicographical difference is ignored

assert!(LexBitSet(&a) < LexBitSet(&b));

Tuple Fields§

§0: &'a FixedBitSet

Trait Implementations§

Source§

impl<'a> Debug for LexBitSet<'a>

Source§

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

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

impl Ord for LexBitSet<'_>

The LexBitSet implements a total order on bitsets. As such, it must implement the standard trait Ord.

§Note:

This implementation uses the underlying words representation of the bitsets to perform several comparisons at once. Hence, using a LexBitSet should be more efficient than trying to establish the total ordering yourself with a loop on the 1-bits of the two sets.

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for LexBitSet<'_>

Having LexBitSet to implement PartialEq means that it at least defines a partial equivalence relation.

Source§

fn eq(&self, other: &Self) -> 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.
Source§

impl PartialOrd for LexBitSet<'_>

Because it is a total order, LexBitSet must also be a partial order. Hence, it must implement the standard trait PartialOrd.

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for LexBitSet<'_>

Because LexBitSet defines a total order, it makes sense to consider that it also defines an equivalence relation. As such, it implements the standard Eq and PartialEq traits.

Auto Trait Implementations§

§

impl<'a> Freeze for LexBitSet<'a>

§

impl<'a> RefUnwindSafe for LexBitSet<'a>

§

impl<'a> Send for LexBitSet<'a>

§

impl<'a> Sync for LexBitSet<'a>

§

impl<'a> Unpin for LexBitSet<'a>

§

impl<'a> UnwindSafe for LexBitSet<'a>

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> 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, 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.