pub struct BigInt { /* private fields */ }Expand description
An arbitrary-precision signed integer: a sign and a BigUint magnitude.
Costs are never negative, but expressions over them can be: a parametric weight
den · c₁ - num · c₂ (Dinkelbach’s method for ratio objectives), a reduced cost, or the
difference of two path sums. BigInt holds such values exactly; +, - and * never
overflow or round.
Zero has a single representation, so it is never negative and -0 == 0.
Every operator also takes references (&a + &b), and +=, -= and *= take
&BigInt. In a hot loop, sum += &weight reuses sum’s limbs instead of cloning
both operands.
§Examples
use search_core::{BigInt, ExactArith};
// den · c₁ - num · c₂ for one edge, with 128-bit ratio terms and 64-bit costs.
let weight = |den: u128, c1: u64, num: u128, c2: u64| {
BigInt::from(den.exact() * c1.exact()) - BigInt::from(num.exact() * c2.exact())
};
let w = weight(u128::MAX, 2, u128::MAX, 3);
assert!(w.is_negative());
assert_eq!(w + weight(u128::MAX, 1, 0, 0), BigInt::from(0_u128));
assert!(BigInt::from(-5_i128) < BigInt::from(3_i128));Implementations§
Trait Implementations§
Source§impl AddAssign for BigInt
impl AddAssign for BigInt
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
Performs the
+= operation. Read moreSource§impl AddAssign<&BigInt> for BigInt
impl AddAssign<&BigInt> for BigInt
Source§fn add_assign(&mut self, other: &BigInt)
fn add_assign(&mut self, other: &BigInt)
Adds in place, reusing this value’s limbs.
impl Eq for BigInt
Source§impl ExactNumber for BigInt
impl ExactNumber for BigInt
Source§impl MulAssign for BigInt
impl MulAssign for BigInt
Source§fn mul_assign(&mut self, other: Self)
fn mul_assign(&mut self, other: Self)
Performs the
*= operation. Read moreSource§impl MulAssign<&BigInt> for BigInt
impl MulAssign<&BigInt> for BigInt
Source§fn mul_assign(&mut self, other: &BigInt)
fn mul_assign(&mut self, other: &BigInt)
Performs the
*= operation. Read moreSource§impl Ord for BigInt
impl Ord for BigInt
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for BigInt
impl PartialOrd for BigInt
impl StructuralPartialEq for BigInt
Auto Trait Implementations§
impl Forget for BigInt
impl Freeze for BigInt
impl Move for BigInt
impl RefUnwindSafe for BigInt
impl Send for BigInt
impl Sync for BigInt
impl Unpin for BigInt
impl UnsafeUnpin for BigInt
impl UnwindSafe for BigInt
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