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>
impl<const BASE: usize> Tight<BASE>
Sourcepub unsafe fn from_raw_parts(
data: VecDeque<Datum>,
start_offset: usize,
end_offset: usize,
) -> Self
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());
Sourcepub fn aligned(self) -> Self
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> AddAssign for Tight<BASE>
impl<const BASE: usize> AddAssign for Tight<BASE>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moreSource§impl<const BASE: usize> BigInt<BASE> for Tight<BASE>
impl<const BASE: usize> BigInt<BASE> for Tight<BASE>
Source§fn normalized(self) -> Self
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.
type Builder = TightBuilder<BASE>
type Denormal = Denormal<BASE, Tight<BASE>>
Source§fn get_digit(&self, digit: usize) -> Option<Digit>
fn get_digit(&self, digit: usize) -> Option<Digit>
digit
,
or None if the number does not have that many digits. Read moreSource§fn push_back(&mut self, digit: Digit)
fn push_back(&mut self, digit: Digit)
(int << 1) + digit
Read moreSource§unsafe fn push_front(&mut self, digit: Digit)
unsafe fn push_front(&mut self, digit: Digit)
Source§unsafe fn shr_assign_inner(&mut self, amount: usize)
unsafe fn shr_assign_inner(&mut self, amount: usize)
Source§unsafe fn shl_assign_inner(&mut self, amount: usize)
unsafe fn shl_assign_inner(&mut self, amount: usize)
Source§unsafe fn pop_front(&mut self) -> Option<Digit>
unsafe fn pop_front(&mut self) -> Option<Digit>
Source§unsafe fn pop_back(&mut self) -> Option<Digit>
unsafe fn pop_back(&mut self) -> Option<Digit>
const BITS_PER_DIGIT: usize = _
Source§fn get_back_inner(&self, index: usize) -> Option<Digit>
fn get_back_inner(&self, index: usize) -> Option<Digit>
big_int::GetBack
. Read moreSource§fn default_inner() -> Self
fn default_inner() -> Self
Default
. Read moreSource§fn fmt_inner(&self, f: &mut Formatter<'_>) -> Result
fn fmt_inner(&self, f: &mut Formatter<'_>) -> Result
Display
. Read moreSource§fn partial_cmp_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> Option<Ordering>
fn partial_cmp_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> Option<Ordering>
PartialOrd
. Read moreSource§fn cmp_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> Ordering
fn cmp_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> Ordering
Ord
. Read moreSource§fn eq_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> bool
fn eq_inner<RHS: BigInt<BASE>>(&self, other: &RHS) -> bool
PartialEq
. Read moreSource§fn add_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> OUT::Denormal
fn add_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal
Add
. Read moreSource§unsafe fn add_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)
unsafe fn add_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)
AddAssign
. Read moreSource§fn sub_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> OUT::Denormal
fn sub_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal
Sub
. Read moreSource§unsafe fn sub_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)
unsafe fn sub_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)
SubAssign
. Read moreSource§fn mul_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> OUT::Denormal
fn mul_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal
Mul
. Read moreSource§unsafe fn mul_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)
unsafe fn mul_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)
MulAssign
. Read moreSource§fn div_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> OUT::Denormal
fn div_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> OUT::Denormal
Div
. Read moreSource§unsafe fn div_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)
unsafe fn div_assign_inner<RHS: BigInt<BASE>>(&mut self, rhs: RHS)
DivAssign
. Read moreSource§fn from_str_inner(s: &str) -> Result<Self::Denormal, BigIntError>
fn from_str_inner(s: &str) -> Result<Self::Denormal, BigIntError>
FromStr
. Read moreSource§fn from_iter_inner<T: IntoIterator<Item = Digit>>(iter: T) -> Self::Denormal
fn from_iter_inner<T: IntoIterator<Item = Digit>>(iter: T) -> Self::Denormal
FromIterator
. Read moreSource§fn from_u128_inner(value: u128) -> Self::Denormal
fn from_u128_inner(value: u128) -> Self::Denormal
From<_>
for all unsigned primitive int types. Read moreSource§fn from_i128_inner(value: i128) -> Self::Denormal
fn from_i128_inner(value: i128) -> Self::Denormal
From<_>
for all signed primitive int types. Read moreSource§fn into_u128_inner(self) -> u128
fn into_u128_inner(self) -> u128
Into<_>
for all unsigned primitive int types. Read moreSource§fn into_i128_inner(self) -> i128
fn into_i128_inner(self) -> i128
Into<_>
for all signed primitive int types. Read moreSource§fn shl_inner(self, amount: usize) -> Self::Denormal
fn shl_inner(self, amount: usize) -> Self::Denormal
Source§fn div_rem_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> Result<(OUT::Denormal, OUT::Denormal), BigIntError>
fn div_rem_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<(OUT::Denormal, OUT::Denormal), BigIntError>
Source§fn div_rem<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> Result<(OUT, OUT), BigIntError>
fn div_rem<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<(OUT, OUT), BigIntError>
Source§fn exp_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> Result<OUT::Denormal, BigIntError>
fn exp_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT::Denormal, BigIntError>
rhs
.
Returns the result as a denormalized number. Read moreSource§fn exp<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> Result<OUT, BigIntError>
fn exp<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT, BigIntError>
rhs
. Read moreSource§fn log_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> Result<OUT::Denormal, BigIntError>
fn log_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT::Denormal, BigIntError>
rhs
.
Returns the result as a denormalized number. Read moreSource§fn log<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> Result<OUT, BigIntError>
fn log<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT, BigIntError>
rhs
. Read moreSource§fn root_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> Result<OUT::Denormal, BigIntError>
fn root_inner<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT::Denormal, BigIntError>
rhs
.
Returns the result as a denormalized number. Read moreSource§fn root<RHS: BigInt<BASE>, OUT: BigInt<BASE>>(
self,
rhs: RHS,
) -> Result<OUT, BigIntError>
fn root<RHS: BigInt<BASE>, OUT: BigInt<BASE>>( self, rhs: RHS, ) -> Result<OUT, BigIntError>
rhs
. Read moreSource§fn iter<'a>(&'a self) -> BigIntIter<'a, BASE, Self> ⓘ
fn iter<'a>(&'a self) -> BigIntIter<'a, BASE, Self> ⓘ
Source§fn display(&self, alphabet: &str) -> Result<String, BigIntError>
fn display(&self, alphabet: &str) -> Result<String, BigIntError>
alphabet
.
Display
uses this method with the default alphabet STANDARD_ALPHABET
. Read moreSource§fn parse(value: &str, alphabet: &str) -> Result<Self::Denormal, ParseError>
fn parse(value: &str, alphabet: &str) -> Result<Self::Denormal, ParseError>
value: &str
, referencing the provided alphabet
to determine what characters represent which digits. FromStr
uses this method
with the default alphabet STANDARD_ALPHABET
. Read moreSource§fn convert_inner<const TO: usize, OUT: BigInt<TO>>(self) -> OUT::Denormal
fn convert_inner<const TO: usize, OUT: BigInt<TO>>(self) -> OUT::Denormal
BigInt
type, or both at once. Returns the result as
a denormalized number. Read moreSource§fn convert<const TO: usize, OUT: BigInt<TO>>(self) -> OUT
fn convert<const TO: usize, OUT: BigInt<TO>>(self) -> OUT
BigInt
type, or both at once. Read moreSource§impl<const BASE: usize> DivAssign for Tight<BASE>
impl<const BASE: usize> DivAssign for Tight<BASE>
Source§fn div_assign(&mut self, rhs: Self)
fn div_assign(&mut self, rhs: Self)
/=
operation. Read moreSource§impl<const BASE: usize> From<TightBuilder<BASE>> for Tight<BASE>
impl<const BASE: usize> From<TightBuilder<BASE>> for Tight<BASE>
Source§fn from(value: TightBuilder<BASE>) -> Self
fn from(value: TightBuilder<BASE>) -> Self
Source§impl<const BASE: usize> IntoIterator for Tight<BASE>
impl<const BASE: usize> IntoIterator for Tight<BASE>
Source§impl<const BASE: usize> MulAssign for Tight<BASE>
impl<const BASE: usize> MulAssign for Tight<BASE>
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*=
operation. Read moreSource§impl<const BASE: usize> Ord for Tight<BASE>
impl<const BASE: usize> Ord for Tight<BASE>
Source§impl<const BASE: usize> PartialOrd for Tight<BASE>
impl<const BASE: usize> PartialOrd for Tight<BASE>
Source§impl<const BASE: usize> ShlAssign for Tight<BASE>
impl<const BASE: usize> ShlAssign for Tight<BASE>
Source§fn shl_assign(&mut self, rhs: Self)
fn shl_assign(&mut self, rhs: Self)
<<=
operation. Read moreSource§impl<const BASE: usize> ShrAssign for Tight<BASE>
impl<const BASE: usize> ShrAssign for Tight<BASE>
Source§fn shr_assign(&mut self, rhs: Self)
fn shr_assign(&mut self, rhs: Self)
>>=
operation. Read moreSource§impl<const BASE: usize> SubAssign for Tight<BASE>
impl<const BASE: usize> SubAssign for Tight<BASE>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read more