Skip to main content

BigInt

Struct BigInt 

Source
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§

Source§

impl BigInt

Source

pub fn is_negative(&self) -> bool

true if the value is below zero.

Source

pub fn magnitude(&self) -> &BigUint

The absolute value.

Trait Implementations§

Source§

impl Add for BigInt

Source§

type Output = BigInt

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
Source§

impl Add for &BigInt

Source§

type Output = BigInt

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> BigInt

Performs the + operation. Read more
Source§

impl Add<&BigInt> for BigInt

Source§

type Output = BigInt

The resulting type after applying the + operator.
Source§

fn add(self, other: &BigInt) -> Self

Performs the + operation. Read more
Source§

impl AddAssign for BigInt

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl AddAssign<&BigInt> for BigInt

Source§

fn add_assign(&mut self, other: &BigInt)

Adds in place, reusing this value’s limbs.

Source§

impl Clone for BigInt

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BigInt

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BigInt

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for BigInt

Source§

impl ExactNumber for BigInt

Source§

fn zero() -> Self

Zero.
Source§

fn one() -> Self

One.
Source§

fn abs_diff(&self, other: &Self) -> Self

|self - other|.
Source§

impl From<BigUint> for BigInt

Source§

fn from(magnitude: BigUint) -> Self

Converts to this type from the input type.
Source§

impl From<i128> for BigInt

Source§

fn from(value: i128) -> Self

Converts to this type from the input type.
Source§

impl From<u128> for BigInt

Source§

fn from(value: u128) -> Self

Converts to this type from the input type.
Source§

impl Hash for BigInt

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Mul for &BigInt

Source§

type Output = BigInt

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> BigInt

Performs the * operation. Read more
Source§

impl Mul for BigInt

Source§

type Output = BigInt

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> Self

Performs the * operation. Read more
Source§

impl Mul<&BigInt> for BigInt

Source§

type Output = BigInt

The resulting type after applying the * operator.
Source§

fn mul(self, other: &BigInt) -> Self

Performs the * operation. Read more
Source§

impl MulAssign for BigInt

Source§

fn mul_assign(&mut self, other: Self)

Performs the *= operation. Read more
Source§

impl MulAssign<&BigInt> for BigInt

Source§

fn mul_assign(&mut self, other: &BigInt)

Performs the *= operation. Read more
Source§

impl Neg for BigInt

Source§

type Output = BigInt

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl Neg for &BigInt

Source§

type Output = BigInt

The resulting type after applying the - operator.
Source§

fn neg(self) -> BigInt

Performs the unary - operation. Read more
Source§

impl Ord for BigInt

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for BigInt

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for BigInt

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for BigInt

Source§

impl Sub for BigInt

Source§

type Output = BigInt

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
Source§

impl Sub for &BigInt

Source§

type Output = BigInt

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> BigInt

Performs the - operation. Read more
Source§

impl Sub<&BigInt> for BigInt

Source§

type Output = BigInt

The resulting type after applying the - operator.
Source§

fn sub(self, other: &BigInt) -> Self

Performs the - operation. Read more
Source§

impl SubAssign for BigInt

Source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
Source§

impl SubAssign<&BigInt> for BigInt

Source§

fn sub_assign(&mut self, other: &BigInt)

Subtracts in place, reusing this value’s limbs.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.