[][src]Struct bee_crypto::ternary::bigint::u384::U384

pub struct U384<E, T> { /* fields omitted */ }

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. 1 is added to all balanced trits, making them unsigned: {-1, 0, 1} -> {0, 1, 2}.
  2. The T243 are converted to base 10 and through this immediately to I384 by calculating the sum `s
This example is not tested
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:

This example is not tested
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]:

This example is not tested
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. 1 is added to all balanced trits, making them unsigned: {-1, 0, 1} -> {0, 1, 2}.
  2. The T243 are converted to base 10 and through this immediately to I384 by calculating the sum `s
This example is not tested
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:

This example is not tested
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]:

This example is not tested
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]

impl<E, T> Deref for U384<E, T>[src]

type Target = T

The resulting type after dereferencing.

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]

impl From<U384<LittleEndian, [u32; 12]>> for T243<Utrit>[src]

impl From<U384<LittleEndian, [u32; 12]>> for U384<BigEndian, U32Repr>[src]

impl From<U384<LittleEndian, [u8; 48]>> for U384<LittleEndian, U32Repr>[src]

impl From<U384<LittleEndian, [u8; 48]>> for U384<BigEndian, U8Repr>[src]

impl Ord for U384<LittleEndian, U32Repr>[src]

impl PartialEq<U384<LittleEndian, [u32; 12]>> for U384<LittleEndian, U32Repr>[src]

impl PartialOrd<U384<LittleEndian, [u32; 12]>> for U384<LittleEndian, U32Repr>[src]

impl TryFrom<T243<Utrit>> for U384<LittleEndian, U32Repr>[src]

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations

impl<E, T> RefUnwindSafe for U384<E, T> where
    E: RefUnwindSafe,
    T: RefUnwindSafe

impl<E, T> Send for U384<E, T> where
    E: Send,
    T: Send

impl<E, T> Sync for U384<E, T> where
    E: Sync,
    T: Sync

impl<E, T> Unpin for U384<E, T> where
    E: Unpin,
    T: Unpin

impl<E, T> UnwindSafe for U384<E, T> where
    E: UnwindSafe,
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> Sponge for U where
    T: Sponge,
    U: DerefMut<Target = T>, 
[src]

type Error = <T as Sponge>::Error

An error indicating that a failure has occured during a sponge operation.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.