[−][src]Struct bee_crypto::ternary::bigint::u384::U384
A big integer encoding an unsigned integer with 384 bits.
T
is usually taken as a [u32; 12]
or [u8; 48]
.
E
refers to the endianness of the digits in T
. This means that in the case of [u32; 12]
, if E == BigEndian
,
that the u32
at position i=0 is considered the most significant digit. The endianness E
here makes no statement
about the endianness of each single digit within itself (this is then dependent on the endianness of the platform
this code is run on).
For E == LittleEndian
the digit at the last position is considered to be the most significant.
Implementations
impl U384<BigEndian, U32Repr>
[src]
pub fn as_i384(self) -> I384<BigEndian, U32Repr>
[src]
Reinterprets the U384
as an I384
.
pub fn shift_into_i384(self) -> I384<BigEndian, U32Repr>
[src]
Shifts the U384
into signed space.
pub fn add_inplace(&mut self, other: Self)
[src]
Adds other
onto self
in place.
pub fn add_digit_inplace<T: Into<u32>>(&mut self, other: T) -> usize
[src]
Adds other
in place, returning the number of digits required to accomodate other
(starting from the least
significant one).
pub fn divide_by_two(&mut self)
[src]
Divides the U384
by 2 by bitshifting all bits one position to the right.
pub fn from_t242(trits: T242<Utrit>) -> Self
[src]
Creates an U384
from an unbalanced T242
.
pub fn sub_inplace(&mut self, other: Self)
[src]
Subtract other
from self
inplace.
This function is defined in terms of overflowing_add
by making use of the following identity (in terms of
Two's complement, and where !
is logical bitwise negation):
!x = -x - 1 => -x = !x + 1
pub fn try_from_t243(trits: T243<Utrit>) -> Result<Self, Error>
[src]
Converts a signed integer represented by the balanced trits in T243
to the unsigned binary integer U384
.
It does this by shifting the T243
into signed range (by adding 1 to all its trits). T243
is assumed to be
in little endian representation, with the most significant trit being at the largest index in the array.
This is done in the following steps:
1
is added to all balanced trits, making them unsigned:{-1, 0, 1} -> {0, 1, 2}
.- The
T243
are converted to base 10 and through this immediately toI384
by calculating the sum `s
s = t_242 * 3^241 + t_241 * 3^240 + ... + t_{i+1} * 3^{i} + t_i * 3^{i-1} + t_{i-1} * 3^{i-2} + ... + t_1 * 3 + t_0
To perform this sum efficiently, its accumulation is staggered, so that each multiplication by 3 is done in each iteration of accumulating loop. This can be understood by factoring the powers of 3 from the previous sum:
s = (...((t_242 * 3 + t_241) * 3 + t_240) * 3 + ... + ...((t_{i+1} * 3 + t_i) * 3 + t_{i-1}) * 3 + ... + ...t_1) * 3 + t_0
Expressed in procedural form, this is the sum accumulated in acc
with the index i
running from [242..0
]:
acc = 0 for i, trit in trits.rev(): acc := acc + trit * 3^i
impl U384<LittleEndian, U32Repr>
[src]
pub fn as_i384(self) -> I384<LittleEndian, U32Repr>
[src]
Reinterprets the U384
as an I384
.
pub fn add_inplace(&mut self, other: Self)
[src]
Adds other
onto self
in place.
pub fn add_digit_inplace<T: Into<u32>>(&mut self, other: T) -> usize
[src]
Adds other
in place, returning the number of digits required to accomodate other
(starting from the least
significant one).
pub fn divide_by_two(&mut self)
[src]
Divides the U384
by 2 by bitshifting all bits one position to the right.
pub fn from_t242(trits: T242<Utrit>) -> Self
[src]
Creates an U384
from an unbalanced T242
.
pub fn shift_into_i384(self) -> I384<LittleEndian, U32Repr>
[src]
Shifts the U384
into signed space.
pub fn sub_inplace(&mut self, other: Self)
[src]
Subtract other
from self
inplace.
This function is defined in terms of overflowing_add
by making use of the following identity (in terms of
Two's complement, and where !
is logical bitwise negation):
!x = -x -1 => -x = !x + 1
pub fn try_from_t243(trits: T243<Utrit>) -> Result<Self, Error>
[src]
Converts a signed integer represented by the balanced trits in T243
to the unsigned binary integer U384
.
It does this by shifting the T243
into signed range (by adding 1 to all its trits). T243
is assumed to be
in little endian representation, with the most significant trit being at the largest index in the array.
This is done in the following steps:
1
is added to all balanced trits, making them unsigned:{-1, 0, 1} -> {0, 1, 2}
.- The
T243
are converted to base 10 and through this immediately toI384
by calculating the sum `s
s = t_242 * 3^241 + t_241 * 3^240 + ... + t_{i+1} * 3^{i} + t_i * 3^{i-1} + t_{i-1} * 3^{i-2} + ... + t_1 * 3 + t_0
To perform this sum efficiently, its accumulation is staggered, so that each multiplication by 3 is done in each iteration of accumulating loop. This can be understood by factoring the powers of 3 from the previous sum:
s = (...((t_242 * 3 + t_241) * 3 + t_240) * 3 + ... + ...((t_{i+1} * 3 + t_i) * 3 + t_{i-1}) * 3 + ... + ...t_1) * 3 + t_0
Expressed in procedural form, this is the sum accumulated in acc
with the index i
running from [242..0
]:
acc = 0 for i, trit in trits.rev(): acc := acc + trit * 3^i
impl U384<BigEndian, U8Repr>
[src]
pub const fn from_array(inner: U8Repr) -> Self
[src]
Creates an instance from an array of inner representation.
impl U384<BigEndian, U32Repr>
[src]
pub const fn from_array(inner: U32Repr) -> Self
[src]
Creates an instance from an array of inner representation.
impl U384<LittleEndian, U8Repr>
[src]
pub const fn from_array(inner: U8Repr) -> Self
[src]
Creates an instance from an array of inner representation.
impl U384<LittleEndian, U32Repr>
[src]
pub const fn from_array(inner: U32Repr) -> Self
[src]
Creates an instance from an array of inner representation.
impl U384<BigEndian, U8Repr>
[src]
pub const fn zero() -> Self
[src]
Returns the appropriate constant value.
pub const fn one() -> Self
[src]
Returns the appropriate constant value.
pub const fn two() -> Self
[src]
Returns the appropriate constant value.
pub const fn max() -> Self
[src]
Returns the appropriate constant value.
impl U384<LittleEndian, U8Repr>
[src]
pub const fn zero() -> Self
[src]
Returns the appropriate constant value.
pub const fn one() -> Self
[src]
Returns the appropriate constant value.
pub const fn two() -> Self
[src]
Returns the appropriate constant value.
pub const fn max() -> Self
[src]
Returns the appropriate constant value.
impl U384<BigEndian, U32Repr>
[src]
pub const fn zero() -> Self
[src]
Returns the appropriate constant value.
pub const fn one() -> Self
[src]
Returns the appropriate constant value.
pub const fn two() -> Self
[src]
Returns the appropriate constant value.
pub const fn max() -> Self
[src]
Returns the appropriate constant value.
impl U384<LittleEndian, U32Repr>
[src]
pub const fn zero() -> Self
[src]
Returns the appropriate constant value.
pub const fn one() -> Self
[src]
Returns the appropriate constant value.
pub const fn two() -> Self
[src]
Returns the appropriate constant value.
pub const fn max() -> Self
[src]
Returns the appropriate constant value.
Trait Implementations
impl<E: Clone, T: Clone> Clone for U384<E, T>
[src]
impl<E: Copy, T: Copy> Copy for U384<E, T>
[src]
impl<E, T, D> Debug for U384<E, T> where
E: Debug,
T: BinaryRepresentation<Inner = D>,
D: Debug,
[src]
E: Debug,
T: BinaryRepresentation<Inner = D>,
D: Debug,
impl<E, T> Deref for U384<E, T>
[src]
impl<E, T> DerefMut for U384<E, T>
[src]
impl Eq for U384<LittleEndian, U32Repr>
[src]
impl From<T242<Utrit>> for U384<LittleEndian, U32Repr>
[src]
impl From<U384<BigEndian, [u32; 12]>> for T243<Utrit>
[src]
impl From<U384<BigEndian, [u32; 12]>> for U384<BigEndian, U8Repr>
[src]
impl From<U384<BigEndian, [u32; 12]>> for U384<LittleEndian, U32Repr>
[src]
impl From<U384<BigEndian, [u8; 48]>> for U384<LittleEndian, U8Repr>
[src]
impl From<U384<LittleEndian, [u32; 12]>> for T242<Utrit>
[src]
fn from(binary_value: U384<LittleEndian, U32Repr>) -> Self
[src]
impl From<U384<LittleEndian, [u32; 12]>> for T243<Utrit>
[src]
fn from(value: U384<LittleEndian, U32Repr>) -> Self
[src]
impl From<U384<LittleEndian, [u32; 12]>> for U384<BigEndian, U32Repr>
[src]
fn from(value: U384<LittleEndian, U32Repr>) -> Self
[src]
impl From<U384<LittleEndian, [u8; 48]>> for U384<LittleEndian, U32Repr>
[src]
fn from(value: U384<LittleEndian, U8Repr>) -> Self
[src]
impl From<U384<LittleEndian, [u8; 48]>> for U384<BigEndian, U8Repr>
[src]
fn from(value: U384<LittleEndian, U8Repr>) -> Self
[src]
impl Ord for U384<LittleEndian, U32Repr>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl PartialEq<U384<LittleEndian, [u32; 12]>> for U384<LittleEndian, U32Repr>
[src]
impl PartialOrd<U384<LittleEndian, [u32; 12]>> for U384<LittleEndian, U32Repr>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl TryFrom<T243<Utrit>> for U384<LittleEndian, U32Repr>
[src]
Auto Trait Implementations
impl<E, T> RefUnwindSafe for U384<E, T> where
E: RefUnwindSafe,
T: RefUnwindSafe,
E: RefUnwindSafe,
T: RefUnwindSafe,
impl<E, T> Send for U384<E, T> where
E: Send,
T: Send,
E: Send,
T: Send,
impl<E, T> Sync for U384<E, T> where
E: Sync,
T: Sync,
E: Sync,
T: Sync,
impl<E, T> Unpin for U384<E, T> where
E: Unpin,
T: Unpin,
E: Unpin,
T: Unpin,
impl<E, T> UnwindSafe for U384<E, T> where
E: UnwindSafe,
T: UnwindSafe,
E: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> Sponge for U where
T: Sponge,
U: DerefMut<Target = T>,
[src]
T: Sponge,
U: DerefMut<Target = T>,
type Error = <T as Sponge>::Error
An error indicating that a failure has occured during a sponge operation.
fn reset(&mut Self)
[src]
fn absorb(&mut Self, &Trits<T1B1<Btrit>>) -> Result<(), <U as Sponge>::Error>
[src]
fn squeeze_into(
&mut Self,
&mut Trits<T1B1<Btrit>>
) -> Result<(), <U as Sponge>::Error>
[src]
&mut Self,
&mut Trits<T1B1<Btrit>>
) -> Result<(), <U as Sponge>::Error>
fn squeeze(&mut self) -> Result<TritBuf, Self::Error>
[src]
fn digest_into(
&mut self,
input: &Trits,
buf: &mut Trits
) -> Result<(), Self::Error>
[src]
&mut self,
input: &Trits,
buf: &mut Trits
) -> Result<(), Self::Error>
fn digest(&mut self, input: &Trits) -> Result<TritBuf, Self::Error>
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,