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 Ord for LexBitSet<'_>
The LexBitSet
implements a total order on bitsets. As such, it must
implement the standard trait Ord
.
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§impl PartialEq for LexBitSet<'_>
Having LexBitSet
to implement PartialEq
means that it at least defines
a partial equivalence relation.
impl PartialEq for LexBitSet<'_>
Having LexBitSet
to implement PartialEq
means that it at least defines
a partial equivalence relation.
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
.
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
.
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.