Struct 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: Tight<10> = 593.into();
let b = a * 96.into();
assert_eq!(b, 56928.into());

Implementations§

Source§

impl<const BASE: usize> Tight<BASE>

Source

pub unsafe fn from_raw_parts( data: VecDeque<Datum>, start_offset: usize, end_offset: usize, ) -> Self

Construct a Tight int directly from raw parts.

Ensure the following invariants hold true to maintain soundness:

  • start_offset <= end_offset
  • end_offset <= data.len() * big_int::tight::DATUM_SIZE
  • (end_offset - start_offset) % Tight::<BASE>::BITS_PER_DIGIT == 0
use big_int::prelude::*;

let a: Tight<10> = unsafe { Tight::from_raw_parts(
    vec![0b0001_1001, 0b0101_0000].into(),
    0, 16
) };

assert_eq!(a, 1950.into());
Source

pub fn aligned(self) -> Self

Return the int with the bits within aligned to the beginning of the data segment and unnecessary extra data truncated.

It’s likely unnecessary to invoke this directly unless using Tight::from_raw_parts.

use big_int::prelude::*;

let mut a: Tight<10> = unsafe { Tight::from_raw_parts(
    vec![0b0000_0000, 0b0000_1001, 0b0101_0000, 0b0000_0000].into(),
    12, 20
) };
assert_eq!(a.aligned(), unsafe { Tight::from_raw_parts(
    vec![0b1001_0101].into(),
    0, 8
) });

Trait Implementations§

Source§

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

Source§

type Output = Tight<BASE>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

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

Source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
Source§

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

Source§

fn normalized(self) -> Self

Return a normalized version of the int. Remove trailing zeros, disable the parity flag if the resulting number is zero, and align the internal bits to the beginning of the data array.

Source§

type Builder = TightBuilder<BASE>

Source§

type Denormal = Denormal<BASE, Tight<BASE>>

Source§

fn len(&self) -> usize

The length of the big int in digits. Read more
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. Read more
Source§

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

Set the digit of the big int to value at position digit. Read more
Source§

fn zero() -> Self

The value zero represented as a big int. Read more
Source§

fn sign(&self) -> Sign

The sign of the big int. Read more
Source§

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

The big int with the given sign. Read more
Source§

fn set_sign(&mut self, sign: Sign)

Set the sign of the big int to sign. Read more
Source§

fn push_back(&mut self, digit: Digit)

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

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

Append a digit to the left side of the int. Read more
Source§

unsafe fn shr_assign_inner(&mut self, amount: usize)

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

unsafe fn shl_assign_inner(&mut self, amount: usize)

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

unsafe fn pop_front(&mut self) -> Option<Digit>

Pop the leftmost digit from the end of the int, and return it. Read more
Source§

unsafe fn pop_back(&mut self) -> Option<Digit>

Pop the rightmost digit from the end of the int, and return it. Read more
Source§

const BITS_PER_DIGIT: usize = _

Source§

fn get_back_inner(&self, index: usize) -> Option<Digit>

Default implementation of big_int::GetBack. Read more
Source§

fn default_inner() -> Self

Default implementation of Default. Read more
Source§

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

Default implementation of Display. Read more
Source§

fn partial_cmp_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> Option<Ordering>

Default implementation of PartialOrd. Read more
Source§

fn cmp_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> Ordering

Default implementation of Ord. Read more
Source§

fn eq_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> bool

Default implementation of PartialEq. Read more
Source§

fn neg_inner(self) -> Self::Denormal

Default implementation of Neg. Read more
Source§

fn add_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal

Default implementation of Add. Read more
Source§

unsafe fn add_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)

Default implementation of AddAssign. Read more
Source§

fn sub_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal

Default implementation of Sub. Read more
Source§

unsafe fn sub_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)

Default implementation of SubAssign. Read more
Source§

fn mul_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal

Default implementation of Mul. Read more
Source§

unsafe fn mul_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)

Default implementation of MulAssign. Read more
Source§

fn div_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal

Default implementation of Div. Read more
Source§

unsafe fn div_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)

Default implementation of DivAssign. Read more
Source§

fn from_str_inner(s: &str) -> Result<Self::Denormal, BigIntError>

Default implementation of FromStr. Read more
Source§

fn from_iter_inner<T: IntoIterator<Item = Digit>>(iter: T) -> Self::Denormal

Default implementation of FromIterator. Read more
Source§

fn from_u128_inner(value: u128) -> Self::Denormal

Default implementation of From<_> for all unsigned primitive int types. Read more
Source§

fn from_i128_inner(value: i128) -> Self::Denormal

Default implementation of From<_> for all signed primitive int types. Read more
Source§

fn into_u128_inner(self) -> u128

Default implementation of Into<_> for all unsigned primitive int types. Read more
Source§

fn into_i128_inner(self) -> i128

Default implementation of Into<_> for all signed primitive int types. Read more
Source§

fn is_zero(&self) -> bool

Check if the big int is zero. Read more
Source§

fn shr_inner(self, amount: usize) -> Self::Denormal

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

fn shl_inner(self, amount: usize) -> Self::Denormal

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

fn div_rem_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<(OUT::Denormal, OUT::Denormal), BigIntError>

Divide one int by another, returning the quotient & remainder as a pair. Returns the result as a denormalized pair. Read more
Source§

fn div_rem<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<(OUT, OUT), BigIntError>

Divide one int by another, returning the quotient & remainder as a pair. Read more
Source§

fn exp_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT::Denormal, BigIntError>

Exponentiate the big int by rhs. Returns the result as a denormalized number. Read more
Source§

fn exp<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT, BigIntError>

Exponentiate the big int by rhs. Read more
Source§

fn log_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT::Denormal, BigIntError>

Compute the logarithm of the big int with the base rhs. Returns the result as a denormalized number. Read more
Source§

fn log<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT, BigIntError>

Compute the logarithm of the big int with the base rhs. Read more
Source§

fn root_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT::Denormal, BigIntError>

Compute the nth root of the big int, with root rhs. Returns the result as a denormalized number. Read more
Source§

fn root<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT, BigIntError>

Compute the nth root of the big int, with root rhs. Read more
Source§

fn is_even(&self) -> bool

Check if the number is even. Read more
Source§

fn iter<'a>(&'a self) -> BigIntIter<'a, BASE, Self>

Iterate over the digits of the int. Read more
Source§

fn normalize(&mut self)

Normalize a big int in place. A normalized int: 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::Denormal, ParseError>

Parse a 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§

fn convert_inner<const TO: usize, OUT: BigInt<TO>>(self) -> OUT::Denormal

Convert an int from its own base to another target base, to another BigInt type, or both at once. Returns the result as a denormalized number. Read more
Source§

fn convert<const TO: usize, OUT: BigInt<TO>>(self) -> OUT

Convert an int from its own base to another target base, to another BigInt type, or both at once. Read more
Source§

fn cmp_magnitude<RHS: BigInt<BASE>>(&self, rhs: &RHS) -> Ordering

Compare the absolute magnitude of two big ints, ignoring their sign. Read more
Source§

fn abs(self) -> Self

Return the absolute value of the int. Read more
Source§

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

Source§

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

Returns a duplicate 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> Default for Tight<BASE>

Source§

fn default() -> Self

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

impl<const BASE: usize> Display 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> Div for Tight<BASE>

Source§

type Output = Tight<BASE>

The resulting type after applying the / operator.
Source§

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

Performs the / operation. Read more
Source§

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

Source§

fn div_assign(&mut self, rhs: Self)

Performs the /= operation. Read more
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

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

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(value: TightBuilder<BASE>) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> From<Vec<u64>> for Tight<BASE>

Source§

fn from(value: Vec<Digit>) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: i128) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: i16) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: i8) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: isize) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: u128) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: u16) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: u64) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: u8) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(value: usize) -> Self

Converts to this type from the input type.
Source§

impl<const BASE: usize> FromIterator<u64> for Tight<BASE>

Source§

fn from_iter<T: IntoIterator<Item = Digit>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

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

Source§

type Err = BigIntError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

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

Source§

type Item = u64

Source§

fn get_back(&self, index: usize) -> Option<Digit>

Safely retrieve items from a collection with negative indexing. Returns None if the index is larger than the length of the collection.
Source§

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

Source§

type Item = u64

The type of the elements being iterated over.
Source§

type IntoIter = BigIntIntoIter<BASE, Tight<BASE>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

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

Source§

type Output = Tight<BASE>

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

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

Source§

fn mul_assign(&mut self, rhs: Self)

Performs the *= operation. Read more
Source§

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

Source§

type Output = Tight<BASE>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

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

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) -> Self
where Self: Sized,

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

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

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

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

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

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

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

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

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

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

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

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

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

Source§

type Output = Tight<BASE>

The resulting type after applying the << operator.
Source§

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

Performs the << operation. Read more
Source§

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

Source§

fn shl_assign(&mut self, rhs: Self)

Performs the <<= operation. Read more
Source§

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

Source§

type Output = Tight<BASE>

The resulting type after applying the >> operator.
Source§

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

Performs the >> operation. Read more
Source§

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

Source§

fn shr_assign(&mut self, rhs: Self)

Performs the >>= operation. Read more
Source§

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

Source§

type Output = Tight<BASE>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

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

Source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
Source§

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

Auto Trait Implementations§

§

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

§

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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

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

impl<T> UnsafeInto<T> for T

Source§

unsafe fn unsafe_into(self) -> T