pub struct ShortlexUnsignedVector<T: PrimitiveUnsigned>(pub UnsignedVector<T>);Expand description
ShortlexUnsignedVector is a wrapper around an UnsignedVector, taking the
UnsignedVector by value.
UnsignedVector does not implement Ord, because no order on vectors is canonical: lex,
graded lex, and the others all have their uses, and the order most natural mathematically,
comparing vectors of the same dimension element by element, is only partial. Wrapping an
UnsignedVector in a ShortlexUnsignedVector provides one total order: vectors are compared
first by dimension and then, in case of a tie, lexicographically, by their elements from first
to last. Its equality agrees with UnsignedVector equality.
Unlike lexicographic order on Vecs, this order puts every vector of a smaller dimension
before every vector of a larger one, so that $(5) < (0, 0)$. It is a well-order: any nonempty
set of vectors has a least element, the lexicographically least of those of the smallest
dimension present.
ShortlexUnsignedVector owns its value. This is useful in many cases, for example if you want
to use UnsignedVectors as keys in a BTreeMap. In other
situations, it is better to use ShortlexUnsignedVectorRef, which only has a reference to its
value.
Tuple Fields§
§0: UnsignedVector<T>Implementations§
Source§impl<T: PrimitiveUnsigned> ShortlexUnsignedVector<T>
impl<T: PrimitiveUnsigned> ShortlexUnsignedVector<T>
Sourcepub const fn as_ref(&self) -> ShortlexUnsignedVectorRef<'_, T>
pub const fn as_ref(&self) -> ShortlexUnsignedVectorRef<'_, T>
Borrows a ShortlexUnsignedVector as a ShortlexUnsignedVectorRef.
§Worst-case complexity
Constant time and additional memory.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::{
ShortlexUnsignedVector, ShortlexUnsignedVectorRef, UnsignedVector,
};
let v = UnsignedVector::<u32>::from_str("(1, 2, 3)").unwrap();
let x = ShortlexUnsignedVector(v.clone());
assert_eq!(x.as_ref(), ShortlexUnsignedVectorRef(&v));Trait Implementations§
Source§impl<T: Clone + PrimitiveUnsigned> Clone for ShortlexUnsignedVector<T>
impl<T: Clone + PrimitiveUnsigned> Clone for ShortlexUnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> Debug for ShortlexUnsignedVector<T>
impl<T: PrimitiveUnsigned> Debug for ShortlexUnsignedVector<T>
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Writes a ShortlexUnsignedVector as ShortlexUnsignedVector( followed by the vector and
).
§Examples
use core::str::FromStr;
use malachite_base::strings::ToDebugString;
use malachite_base::unsigned_vector::{ShortlexUnsignedVector, UnsignedVector};
let v = UnsignedVector::<u32>::from_str("(1, 2)").unwrap();
assert_eq!(
ShortlexUnsignedVector(v).to_debug_string(),
"ShortlexUnsignedVector((1, 2))"
);Source§impl<T: PrimitiveUnsigned> Deref for ShortlexUnsignedVector<T>
impl<T: PrimitiveUnsigned> Deref for ShortlexUnsignedVector<T>
Source§fn deref(&self) -> &UnsignedVector<T>
fn deref(&self) -> &UnsignedVector<T>
Allows a ShortlexUnsignedVector to dereference to an UnsignedVector.
use core::str::FromStr;
use malachite_base::unsigned_vector::{ShortlexUnsignedVector, UnsignedVector};
let v = UnsignedVector::<u32>::from_str("(1, 2, 3)").unwrap();
let x = ShortlexUnsignedVector(v.clone());
assert_eq!(*x, v);Source§type Target = UnsignedVector<T>
type Target = UnsignedVector<T>
impl<T: Eq + PrimitiveUnsigned> Eq for ShortlexUnsignedVector<T>
Source§impl<T: Hash + PrimitiveUnsigned> Hash for ShortlexUnsignedVector<T>
impl<T: Hash + PrimitiveUnsigned> Hash for ShortlexUnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> Ord for ShortlexUnsignedVector<T>
impl<T: PrimitiveUnsigned> Ord for ShortlexUnsignedVector<T>
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
Compares two ShortlexUnsignedVectors.
The order is shortlex: the vectors are compared first by dimension, and then, in case of a
tie, lexicographically. See the Ord implementation for ShortlexUnsignedVectorRef for
details.
§Examples
use core::str::FromStr;
use malachite_base::unsigned_vector::{ShortlexUnsignedVector, UnsignedVector};
use std::collections::BTreeSet;
let five = UnsignedVector::<u32>::from_str("(5)").unwrap();
let zero_zero = UnsignedVector::<u32>::from_str("(0, 0)").unwrap();
// Dimension decides, whatever the elements.
assert!(ShortlexUnsignedVector(five.clone()) < ShortlexUnsignedVector(zero_zero.clone()));
// The wrapper makes vectors usable in ordered collections.
let set: BTreeSet<_> = [zero_zero, five]
.into_iter()
.map(ShortlexUnsignedVector)
.collect();
assert_eq!(
set.iter().map(|v| v.to_string()).collect::<Vec<_>>(),
["(5)", "(0, 0)"]
);1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialEq + PrimitiveUnsigned> PartialEq for ShortlexUnsignedVector<T>
impl<T: PartialEq + PrimitiveUnsigned> PartialEq for ShortlexUnsignedVector<T>
Source§impl<T: PrimitiveUnsigned> PartialOrd for ShortlexUnsignedVector<T>
impl<T: PrimitiveUnsigned> PartialOrd for ShortlexUnsignedVector<T>
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Compares two ShortlexUnsignedVectors.
See the documentation for the Ord implementation.
impl<T: PartialEq + PrimitiveUnsigned> StructuralPartialEq for ShortlexUnsignedVector<T>
Auto Trait Implementations§
impl<T> Freeze for ShortlexUnsignedVector<T>where
<T as BalancedModPowerOf2>::Output: Sized,
<T as BalancedMod>::Output: Sized,
UnsignedVector<T>: Freeze,
impl<T> RefUnwindSafe for ShortlexUnsignedVector<T>where
<T as BalancedModPowerOf2>::Output: Sized,
<T as BalancedMod>::Output: Sized,
UnsignedVector<T>: RefUnwindSafe,
impl<T> Send for ShortlexUnsignedVector<T>where
<T as BalancedModPowerOf2>::Output: Sized,
<T as BalancedMod>::Output: Sized,
UnsignedVector<T>: Send,
impl<T> Sync for ShortlexUnsignedVector<T>where
<T as BalancedModPowerOf2>::Output: Sized,
<T as BalancedMod>::Output: Sized,
UnsignedVector<T>: Sync,
impl<T> Unpin for ShortlexUnsignedVector<T>where
<T as BalancedModPowerOf2>::Output: Sized,
<T as BalancedMod>::Output: Sized,
UnsignedVector<T>: Unpin,
impl<T> UnsafeUnpin for ShortlexUnsignedVector<T>where
<T as BalancedModPowerOf2>::Output: Sized,
<T as BalancedMod>::Output: Sized,
UnsignedVector<T>: UnsafeUnpin,
impl<T> UnwindSafe for ShortlexUnsignedVector<T>where
<T as BalancedModPowerOf2>::Output: Sized,
<T as BalancedMod>::Output: Sized,
UnsignedVector<T>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
fn imaginary_into(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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