pub struct BigUint { /* private fields */ }
Expand description

Simple wrapper around an infinitely large integer, represented as limbs of Single.

Implementations§

source§

impl BigUint

source

pub fn with_capacity(size: usize) -> Self

Create a new instance with size limbs. This prevents any number with zero limbs to be created.

The behavior of the type is undefined with zero limbs.

source

pub fn from_limbs(limbs: &[Single]) -> Self

Raw constructor from custom limbs. If limbs is empty, Zero::zero() implementation is used.

source

pub fn len(&self) -> usize

Number of limbs.

source

pub fn get(&self, index: usize) -> Single

A naive getter for limb at index. Note that the order is lsb -> msb.

Panics

This panics if index is out of range.

source

pub fn checked_get(&self, index: usize) -> Option<Single>

A naive getter for limb at index. Note that the order is lsb -> msb.

source

pub fn set(&mut self, index: usize, value: Single)

A naive setter for limb at index. Note that the order is lsb -> msb.

Panics

This panics if index is out of range.

source

pub fn lsb(&self) -> Single

returns the least significant limb of the number.

Panics

While the constructor of the type prevents this, this can panic if self has no digits.

source

pub fn msb(&self) -> Single

returns the most significant limb of the number.

Panics

While the constructor of the type prevents this, this can panic if self has no digits.

source

pub fn lstrip(&mut self)

Strips zeros from the left side (the most significant limbs) of self, if any.

source

pub fn lpad(&mut self, size: usize)

Zero-pad self from left to reach size limbs. Will not make any difference if self is already bigger than size limbs.

source

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

Adds self with other. self and other do not have to have any particular size. Given that the n = max{size(self), size(other)}, it will produce a number with n + 1 limbs.

This function does not strip the output and returns the original allocated n + 1 limbs. The caller may strip the output if desired.

Taken from “The Art of Computer Programming” by D.E. Knuth, vol 2, chapter 4.

source

pub fn sub(self, other: &Self) -> Result<Self, Self>

Subtracts other from self. self and other do not have to have any particular size. Given that the n = max{size(self), size(other)}, it will produce a number of size n.

If other is bigger than self, Err(B - borrow) is returned.

Taken from “The Art of Computer Programming” by D.E. Knuth, vol 2, chapter 4.

source

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

Multiplies n-limb number self with m-limb number other.

The resulting number will always have n + m limbs.

This function does not strip the output and returns the original allocated n + m limbs. The caller may strip the output if desired.

Taken from “The Art of Computer Programming” by D.E. Knuth, vol 2, chapter 4.

source

pub fn div_unit(self, other: Single) -> Self

Divides self by a single limb other. This can be used in cases where the original division cannot work due to the divisor (other) being just one limb.

Invariant: other cannot be zero.

source

pub fn div(self, other: &Self, rem: bool) -> Option<(Self, Self)>

Divides an n + m limb self by a n limb other. The result is a m + 1 limb quotient and a n limb remainder, if enabled by passing true in rem argument, both in the form of an option’s Ok.

  • requires other to be stripped and have no leading zeros.
  • requires self to be stripped and have no leading zeros.
  • requires other to have at least two limbs.
  • requires self to have a greater length compared to other.

All arguments are examined without being stripped for the above conditions. If any of the above fails, None is returned.`

Taken from “The Art of Computer Programming” by D.E. Knuth, vol 2, chapter 4.

Trait Implementations§

source§

impl Add<BigUint> for BigUint

§

type Output = BigUint

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl Clone for BigUint

source§

fn clone(&self) -> BigUint

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for BigUint

source§

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

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

impl Decode for BigUint

source§

fn decode<__CodecInputEdqy: Input>( __codec_input_edqy: &mut __CodecInputEdqy ) -> Result<Self, Error>

Attempt to deserialise the value from input.
§

fn decode_into<I>( input: &mut I, dst: &mut MaybeUninit<Self> ) -> Result<DecodeFinished, Error>where I: Input,

Attempt to deserialize the value from input into a pre-allocated piece of memory. Read more
§

fn skip<I>(input: &mut I) -> Result<(), Error>where I: Input,

Attempt to skip the encoded value from input. Read more
§

fn encoded_fixed_size() -> Option<usize>

Returns the fixed encoded size of the type. Read more
source§

impl Default for BigUint

source§

fn default() -> BigUint

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

impl Encode for BigUint

source§

fn encode_to<__CodecOutputEdqy: Output + ?Sized>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )

Convert self to a slice and append it to the destination.
source§

fn encode(&self) -> Vec<u8>

Convert self to an owned vector.
source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

Convert self to a slice and then invoke the given closure with it.
§

fn size_hint(&self) -> usize

If possible give a hint of expected size of the encoding. Read more
§

fn encoded_size(&self) -> usize

Calculates the encoded size. Read more
source§

impl From<u128> for BigUint

source§

fn from(a: u128) -> Self

Converts to this type from the input type.
source§

impl From<u16> for BigUint

source§

fn from(a: u16) -> Self

Converts to this type from the input type.
source§

impl From<u32> for BigUint

source§

fn from(a: u32) -> Self

Converts to this type from the input type.
source§

impl From<u64> for BigUint

source§

fn from(a: Double) -> Self

Converts to this type from the input type.
source§

impl From<u8> for BigUint

source§

fn from(a: u8) -> Self

Converts to this type from the input type.
source§

impl Mul<BigUint> for BigUint

§

type Output = BigUint

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
source§

impl One for BigUint

source§

fn one() -> Self

Returns the multiplicative identity element of Self, 1. Read more
source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
source§

fn is_one(&self) -> boolwhere Self: PartialEq<Self>,

Returns true if self is equal to the multiplicative identity. Read more
source§

impl Ord for BigUint

source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

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

impl PartialEq<BigUint> for BigUint

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<BigUint> for BigUint

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 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Sub<BigUint> for BigUint

§

type Output = BigUint

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
source§

impl TryFrom<BigUint> for u128

§

type Error = &'static str

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

fn try_from(value: BigUint) -> Result<u128, Self::Error>

Performs the conversion.
source§

impl TryFrom<BigUint> for u64

§

type Error = &'static str

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

fn try_from(value: BigUint) -> Result<u64, Self::Error>

Performs the conversion.
source§

impl Zero for BigUint

source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
source§

impl EncodeLike<BigUint> for BigUint

source§

impl Eq for BigUint

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
§

impl<T> DecodeAll for Twhere T: Decode,

§

fn decode_all(input: &mut &[u8]) -> Result<T, Error>

Decode Self and consume all of the given input data. Read more
§

impl<T> DecodeLimit for Twhere T: Decode,

§

fn decode_all_with_depth_limit( limit: u32, input: &mut &[u8] ) -> Result<T, Error>

Decode Self and consume all of the given input data. Read more
§

fn decode_with_depth_limit<I>(limit: u32, input: &mut I) -> Result<T, Error>where I: Input,

Decode Self with the given maximum recursion depth and advance input by the number of bytes consumed. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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.

§

impl<T> KeyedVec for Twhere T: Codec,

§

fn to_keyed_vec(&self, prepend_key: &[u8]) -> Vec<u8, Global>

Return an encoding of Self prepended by given slice.
source§

impl<T> SaturatedConversion for T

source§

fn saturated_from<T>(t: T) -> Selfwhere Self: UniqueSaturatedFrom<T>,

Convert from a value of T into an equivalent instance of Self. Read more
source§

fn saturated_into<T>(self) -> Twhere Self: UniqueSaturatedInto<T>,

Consume self to return an equivalent value of T. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T, S> UniqueSaturatedInto<T> for Swhere T: Bounded, S: TryInto<T>,

source§

fn unique_saturated_into(self) -> T

Consume self to return an equivalent value of T.
§

impl<S> Codec for Swhere S: Decode + Encode,

§

impl<T> EncodeLike<&&T> for Twhere T: Encode,

§

impl<T> EncodeLike<&T> for Twhere T: Encode,

§

impl<T> EncodeLike<&mut T> for Twhere T: Encode,

§

impl<T> EncodeLike<Arc<T>> for Twhere T: Encode,

§

impl<T> EncodeLike<Box<T, Global>> for Twhere T: Encode,

§

impl<'a, T> EncodeLike<Cow<'a, T>> for Twhere T: ToOwned + Encode,

§

impl<T> EncodeLike<Rc<T>> for Twhere T: Encode,

§

impl<S> FullCodec for Swhere S: Decode + FullEncode,

§

impl<S> FullEncode for Swhere S: Encode + EncodeLike<S>,

§

impl<T> JsonSchemaMaybe for T