Struct big_int::tight::Tight

source ·
pub struct Tight<const BASE: usize> { /* private fields */ }
Expand description

A tightly-packed arbitrary base big int implementation. Supports any base from 2-u64::MAX.

In this implementation, bits are tightly packed against one another, requiring only ceil(log_2(BASE)) bits per digit. Signficiantly more space-efficient for smaller bases compared to the loose implementation. However, the extra indirection contributes to some added overhead.

use big_int::prelude::*;

let a: TightInt<10> = 593.into();
let b = a * 96.into();
assert_eq!(b, 56928.into());

Trait Implementations§

source§

impl<const BASE: usize> BigIntImplementation<BASE> for Tight<BASE>

§

type Builder = TightBuilder<BASE>

§

type DigitIterator<'a> = TightIter<'a, BASE>

source§

fn len(&self) -> usize

The length of the big int.
source§

fn get_digit(&self, digit: usize) -> Option<Digit>

Get the digit of the big int at position digit, or None if the number does not have that many digits / the digit is negative.
source§

fn set_digit(&mut self, digit: usize, value: Digit)

Set the digit of the big int to value at position digit. Return Some(Digit) of the digit’s existing value, or None if no digit was set.
source§

fn zero() -> Self

The constant zero represented as a big int.
source§

fn sign(&self) -> Sign

The sign of the big int.
source§

fn with_sign(self, sign: Sign) -> Self

The big int with the desired parity of sign.
source§

fn set_sign(&mut self, sign: Sign)

Set the sign of the big int to sign.
source§

fn push_back(&mut self, digit: Digit)

Append a digit to the right side of the int. Equivalent to (int << 1) + digit
source§

unsafe fn push_front(&mut self, digit: Digit)

Append a digit to the left side of the int. Will denormalize if the appended digit is a zero; make sure to call .normalize() afterwards to prevent undefined functionality.
source§

fn shr_assign(&mut self, amount: usize)

Divide the int by BASE^amount in place. Read more
source§

fn shl_assign(&mut self, amount: usize)

Multiply the int by BASE^amount in place. Read more
source§

fn iter<'a>(&'a self) -> Self::DigitIterator<'a>

source§

fn normalized(self) -> Self

Return a normalized version of the int. Remove trailing zeros, and disable the parity flag if the resulting number is zero. Read more
source§

fn shr(self, amount: usize) -> Self

Divide the int by BASE^amount. Read more
source§

fn shl(self, amount: usize) -> Self

Multiply the int by BASE^amount. Read more
source§

fn normalize(&mut self)

Normalize a Loose big int in place. Remove trailing zeros, and disable the parity flag if the resulting number is zero. Read more
source§

fn display(&self, alphabet: &str) -> Result<String, BigIntError>

Convert a big int to a printable string using the provided alphabet alphabet. Display uses this method with the default alphabet STANDARD_ALPHABET. Read more
source§

fn parse(value: &str, alphabet: &str) -> Result<Self, ParseError>

Parse a Loose big int from a value: &str, referencing the provided alphabet to determine what characters represent which digits. FromStr uses this method with the default alphabet STANDARD_ALPHABET. Read more
source§

impl<const BASE: usize> Build<Tight<BASE>> for TightBuilder<BASE>

source§

fn build(self) -> Tight<BASE>

source§

impl<const BASE: usize> Clone for Tight<BASE>

source§

fn clone(&self) -> Tight<BASE>

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<const BASE: usize> Debug for Tight<BASE>

source§

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

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

impl<const BASE: usize> From<Tight<BASE>> for TightBuilder<BASE>

source§

fn from(value: Tight<{ BASE }>) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize> From<TightBuilder<BASE>> for Tight<BASE>

source§

fn from(builder: TightBuilder<BASE>) -> Self

Converts to this type from the input type.
source§

impl<const BASE: usize> PartialEq for Tight<BASE>

source§

fn eq(&self, other: &Tight<BASE>) -> 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<const BASE: usize> Eq for Tight<BASE>

source§

impl<const BASE: usize> StructuralEq for Tight<BASE>

source§

impl<const BASE: usize> StructuralPartialEq for Tight<BASE>

Auto Trait Implementations§

§

impl<const BASE: usize> RefUnwindSafe for Tight<BASE>

§

impl<const BASE: usize> Send for Tight<BASE>

§

impl<const BASE: usize> Sync for Tight<BASE>

§

impl<const BASE: usize> Unpin for Tight<BASE>

§

impl<const BASE: usize> UnwindSafe for Tight<BASE>

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> 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,

§

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>,

§

type Error = Infallible

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

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

Performs the conversion.
source§

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

§

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.