[][src]Struct ddo::core::utils::LexBitSet

pub struct LexBitSet<'a>(pub &'a BitSet);

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 = BitSet::new(5);
let mut b = BitSet::new(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));

Trait Implementations

impl<'a> Debug for LexBitSet<'a>[src]

impl<'_> Eq for LexBitSet<'_>[src]

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.

impl<'_> Ord for LexBitSet<'_>[src]

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.

impl<'_> PartialEq<LexBitSet<'_>> for LexBitSet<'_>[src]

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

impl<'_> PartialOrd<LexBitSet<'_>> for LexBitSet<'_>[src]

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

Auto Trait Implementations

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.