pub struct Lc<X, R>{ /* private fields */ }Expand description
A linear combination Σ rᵢ · xᵢ with keys X: LcKey and coefficients in a
ring R. Stored via a private LcData, which specializes the empty and
single-term cases to avoid hashmap allocation.
Implementations§
Source§impl<X, R> Lc<X, R>
impl<X, R> Lc<X, R>
pub fn new() -> Self
pub fn nterms(&self) -> usize
pub fn any_term(&self) -> Option<(&X, &R)>
pub fn keys(&self) -> impl Iterator<Item = &X>
pub fn is_singleton(&self) -> bool
pub fn as_singleton(&self) -> Option<X>
pub fn coeff(&self, x: &X) -> &R
pub fn iter(&self) -> LcDataIter<'_, X, R> ⓘ
pub fn map<Y, S, F>(self, f: F) -> Lc<Y, S>
pub fn map_coeffs<S, F>(self, f: F) -> Lc<X, S>
pub fn map_keys<Y, F>(self, f: F) -> Lc<Y, R>
pub fn map_ref<Y, S, F>(&self, f: F) -> Lc<Y, S>
pub fn filter<F>(self, f: F) -> Self
pub fn filtered<F>(&self, f: F) -> Self
Sourcepub fn add_pairs<I>(&mut self, pairs: I)where
I: IntoIterator<Item = (X, R)>,
pub fn add_pairs<I>(&mut self, pairs: I)where
I: IntoIterator<Item = (X, R)>,
Add all pairs at once. Terms may cancel along the way, so the reduced form is
restored once at the end — prefer this over repeated add_pair in a hot loop.
Sourcepub fn add_pairs_ref<'a, I>(&mut self, pairs: I)where
I: IntoIterator<Item = (&'a X, R)>,
X: 'a,
pub fn add_pairs_ref<'a, I>(&mut self, pairs: I)where
I: IntoIterator<Item = (&'a X, R)>,
X: 'a,
Same, taking each key by reference — the coefficient is generally the cheaper
of the two to clone (compare a Cob key in yui-kh), so it is passed by value.
pub fn add_pair(&mut self, rhs: (X, R))
pub fn add_pair_ref(&mut self, rhs: (&X, R))
pub fn apply<F, Y: LcKey>(&self, f: F) -> Lc<Y, R>
pub fn apply_bilin<Y, Z, F>(&self, other: &Lc<Y, R>, x_map: F) -> Lc<Z, R>
pub fn sort_terms_by<F>(&self, cmp: F) -> impl Iterator<Item = (&X, &R)>
pub fn to_string_by<F>(&self, cmp: F, descending: bool) -> String
pub fn is_homogeneous<T, F>(&self, f: F) -> bool
pub fn homogeneous_value<T, F>(&self, f: F) -> Option<T>
Trait Implementations§
Source§impl<X, R> AddAssign for Lc<X, R>
impl<X, R> AddAssign for Lc<X, R>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+= operation. Read moreSource§impl<X, R> AddAssign<&Lc<X, R>> for Lc<X, R>
impl<X, R> AddAssign<&Lc<X, R>> for Lc<X, R>
Source§fn add_assign(&mut self, rhs: &Self)
fn add_assign(&mut self, rhs: &Self)
Performs the
+= operation. Read moreimpl<X, R> AddGrp for Lc<X, R>
impl<X, R> AddGrpOps for Lc<X, R>
impl<X, R> AddGrpOps<Lc<X, R>> for &Lc<X, R>
impl<X, R> AddMonOps for Lc<X, R>
impl<X, R> AddMonOps<Lc<X, R>> for &Lc<X, R>
impl<X, R> Eq for Lc<X, R>
Source§impl<X, R> FromIterator<(X, R)> for Lc<X, R>
impl<X, R> FromIterator<(X, R)> for Lc<X, R>
Source§impl<X, R> IntoIterator for Lc<X, R>
impl<X, R> IntoIterator for Lc<X, R>
Source§impl<X, R> MulAssign for Lc<X, R>
impl<X, R> MulAssign for Lc<X, R>
Source§fn mul_assign(&mut self, rhs: Lc<X, R>)
fn mul_assign(&mut self, rhs: Lc<X, R>)
Performs the
*= operation. Read moreSource§impl<X, R> MulAssign<&Lc<X, R>> for Lc<X, R>
impl<X, R> MulAssign<&Lc<X, R>> for Lc<X, R>
Source§fn mul_assign(&mut self, rhs: &Lc<X, R>)
fn mul_assign(&mut self, rhs: &Lc<X, R>)
Performs the
*= operation. Read moreSource§impl<X, R> MulAssign<&R> for Lc<X, R>
impl<X, R> MulAssign<&R> for Lc<X, R>
Source§fn mul_assign(&mut self, rhs: &R)
fn mul_assign(&mut self, rhs: &R)
Performs the
*= operation. Read moreSource§impl<X, R> MulAssign<R> for Lc<X, R>
impl<X, R> MulAssign<R> for Lc<X, R>
Source§fn mul_assign(&mut self, rhs: R)
fn mul_assign(&mut self, rhs: R)
Performs the
*= operation. Read moreimpl<X, R> RModOps<R, Lc<X, R>> for Lc<X, R>
impl<X, R> RModOps<R, Lc<X, R>> for &Lc<X, R>
impl<X, R> StructuralPartialEq for Lc<X, R>
Source§impl<X, R> SubAssign for Lc<X, R>
impl<X, R> SubAssign for Lc<X, R>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-= operation. Read moreSource§impl<X, R> SubAssign<&Lc<X, R>> for Lc<X, R>
impl<X, R> SubAssign<&Lc<X, R>> for Lc<X, R>
Source§fn sub_assign(&mut self, rhs: &Self)
fn sub_assign(&mut self, rhs: &Self)
Performs the
-= operation. Read moreAuto Trait Implementations§
impl<X, R> Freeze for Lc<X, R>
impl<X, R> RefUnwindSafe for Lc<X, R>
impl<X, R> Send for Lc<X, R>
impl<X, R> Sync for Lc<X, R>
impl<X, R> Unpin for Lc<X, R>
impl<X, R> UnsafeUnpin for Lc<X, R>
impl<X, R> UnwindSafe for Lc<X, R>
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
Mutably borrows from an owned value. Read more
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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> ⓘ
Converts
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> ⓘ
Converts
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