pub struct ShortlexIntegerVector(pub IntegerVector);Expand description
ShortlexIntegerVector is a wrapper around an IntegerVector, taking the IntegerVector
by value.
IntegerVector 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 a
IntegerVector in an ShortlexIntegerVector 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 IntegerVector 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 not a well-order, since the
Integers are not: $(0) > (-1) > (-2) > \ldots$ descends forever.
ShortlexIntegerVector owns its value. This is useful in many cases, for example if you want to
use IntegerVectors as keys in a BTreeMap. In other
situations, it is better to use ShortlexIntegerVectorRef, which only has a reference to its
value.
Tuple Fields§
§0: IntegerVectorImplementations§
Source§impl ShortlexIntegerVector
impl ShortlexIntegerVector
Sourcepub const fn as_ref(&self) -> ShortlexIntegerVectorRef<'_>
pub const fn as_ref(&self) -> ShortlexIntegerVectorRef<'_>
Borrows an ShortlexIntegerVector as a ShortlexIntegerVectorRef.
§Worst-case complexity
Constant time and additional memory.
§Examples
use core::str::FromStr;
use malachite_nz::integer_vector::{
IntegerVector, ShortlexIntegerVector, ShortlexIntegerVectorRef,
};
let v = IntegerVector::from_str("(1, 2, 3)").unwrap();
let x = ShortlexIntegerVector(v.clone());
assert_eq!(x.as_ref(), ShortlexIntegerVectorRef(&v));Trait Implementations§
Source§impl Clone for ShortlexIntegerVector
impl Clone for ShortlexIntegerVector
Source§impl Debug for ShortlexIntegerVector
impl Debug for ShortlexIntegerVector
Source§impl Deref for ShortlexIntegerVector
impl Deref for ShortlexIntegerVector
Source§fn deref(&self) -> &IntegerVector
fn deref(&self) -> &IntegerVector
Allows an ShortlexIntegerVector to dereference to an IntegerVector.
use core::str::FromStr;
use malachite_nz::integer_vector::{IntegerVector, ShortlexIntegerVector};
let v = IntegerVector::from_str("(1, 2, 3)").unwrap();
let x = ShortlexIntegerVector(v.clone());
assert_eq!(*x, v);Source§type Target = IntegerVector
type Target = IntegerVector
impl Eq for ShortlexIntegerVector
Source§impl Hash for ShortlexIntegerVector
impl Hash for ShortlexIntegerVector
Source§impl Ord for ShortlexIntegerVector
impl Ord for ShortlexIntegerVector
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
Compares two ShortlexIntegerVectors.
The order is shortlex: the vectors are compared first by dimension, and then, in case of a
tie, lexicographically. See the Ord implementation for ShortlexIntegerVectorRef for
details.
§Worst-case complexity
$T(n) = O(n)$
$M(n) = O(1)$
where $T$ is time, $M$ is additional memory, and $n$ is the smaller of the two vectors’ total number of bits, summed over their elements. Vectors of different dimensions are compared in constant time.
§Examples
use core::str::FromStr;
use malachite_nz::integer_vector::{IntegerVector, ShortlexIntegerVector};
use std::collections::BTreeSet;
let five = IntegerVector::from_str("(5)").unwrap();
let zero_zero = IntegerVector::from_str("(0, 0)").unwrap();
// Dimension decides, whatever the elements.
assert!(ShortlexIntegerVector(five.clone()) < ShortlexIntegerVector(zero_zero.clone()));
// The wrapper makes vectors usable in ordered collections.
let set: BTreeSet<_> = [zero_zero, five]
.into_iter()
.map(ShortlexIntegerVector)
.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 PartialEq for ShortlexIntegerVector
impl PartialEq for ShortlexIntegerVector
Source§impl PartialOrd for ShortlexIntegerVector
impl PartialOrd for ShortlexIntegerVector
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
Compares two ShortlexIntegerVectors.
See the documentation for the Ord implementation.
impl StructuralPartialEq for ShortlexIntegerVector
Auto Trait Implementations§
impl Freeze for ShortlexIntegerVector
impl RefUnwindSafe for ShortlexIntegerVector
impl Send for ShortlexIntegerVector
impl Sync for ShortlexIntegerVector
impl Unpin for ShortlexIntegerVector
impl UnsafeUnpin for ShortlexIntegerVector
impl UnwindSafe for ShortlexIntegerVector
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