# Struct mostinefficientsha::u::U
[−]
[src]

pub struct U { pub bits: ArrayVec<[RTerm; 32]>, }

This type represents a u32, an unsigned number made of 32 bits.
The bits are not boolean, but represented by a lazily evaluated tree of
`Term`

s.

This type implements some arithmetic operations on `u32`

s that translate
into bit operations under the hood. For example the + operation is translated
into half adders and full adders, that themselves consist of bit operations
like and and or.

This type implements all operations needed to calculate a sha256 hash:
`rotate_right`

, `shift_right >>`

, Addition `+`

and the bitwise operations
`and &`

, `xor ^`

and `not !`

. Use the member functions or the implemented
operators. See `sha.rs`

for example use.

This U can be constructed from a u32 constant number. The bits of that
number will translate into `Term`

s of type `Constant`

.

It can be constructed by creating 32 new symbolic `Term`

s.

It can also be constructed by using operations like `>>`

.

After construction, the bits can be manipulated using the `bits`

field
of this struct.

## Fields

`bits: ArrayVec<[RTerm; 32]>`

The LSBit is bits[0], the MSBit is bits[31]. The byte order is big endian. Push LSB first.

## Methods

`impl U`

[src]

`fn new_symbolic() -> U`

Create a new `U`

with 32 `Term`

s of type `Symbol`

. Do not forget to
set the value of each symbol afterwards. You can set the value of each
bit by using `my_u.bits[22].set(0.3f64)`

. Or set 8 bits of this `U`

with
`my_u.set_byte('e', 2)`

.

`fn from_const(c: u32) -> U`

Create a new `U`

with 32 `Term`

s of type `Constant`

.

`fn set_byte(&self, set_value: u8, bytenum: usize)`

Sets the bits of one byte of this u32 to their min/max values 1.0 and 0.0 depending on `set_value`

.
`bytenum`

must be one of 0, 1, 2, 3.
Byte 0 is the most significant byte of the four byte representation of this u32.

Panics if the relevant bits/`Term`

s of this `U`

are not of type `Symbol`

.

`fn set_bytes(&self, bytes: &[u8])`

Sets all bits of this `U`

to a value dependend on `bytes`

. See `set_byte()`

for details.

Panics if any bit/`Term`

of this `U`

is not of type `Symbol`

.

`fn reset(&self)`

Recursively resets the cache of this self's bits/`Term`

s and the `Term`

s self's `Term`

s depend on.

This need to be called after and before using `nr_of_terms()`

,
`nr_of_terms_flattened()`

and `max_logic_depth_and_max_stack_size()`

.

It also needs to be called before `evaluate()`

and `eval_to_u32()`

, but
only if a symbolic `Term`

has been modified.

`fn evaluate<'a>(&self, out: &mut Vec<f64>)`

Evaluates all bits to a f64 value. Push these values to `out`

.
Pushes the MSBit first.

`fn eval_to_u32(&self) -> u32`

Evaluate all bits to a `f64`

value, then round that value to 0 or 1
and assemble a `u32`

with these bits.

`fn max_logic_depth_and_max_stack_size(&self) -> (usize, usize)`

Max stack size needed when evaluating each bit of this `U`

recursively.

It also returns the maximum logic depth.

Returns: (max_logic_depth, max_stacksize)

Note: manually call reset() before using this function.

`fn nr_of_terms(&self) -> usize`

Returns the number of `RTerms`

that contribute to the evaluation of this `U`

.

Note: manually call reset() before using this function.

`fn nr_of_terms_flattened(&self) -> usize`

Returns the number of `Term`

s that contribute to the evaluation of this `U`

if the
tree would have been flattened for each bit and subtree.

Note: manually call reset() before using this function.

`fn rotate_right(&self, x: usize) -> U`

Returns a new `U`

that evaluates to `self`

s value, but bitrotated by `x`

to the right. Rotation happens without any carry bit.
`x`

must be less or equal 32.

`fn shift_right(&self, x: usize) -> U`

Returns a new `U`

that evaluates to `self`

s value, but bitshifted by `x`

to the right.
`x`

must be less than 32.

`fn xor(&self, rhs: &U) -> U`

Returns a new `U`

that evaluates to the bitwise xor with `rhs`

.

`fn and(&self, rhs: &U) -> U`

Returns a new `U`

that evaluates to the bitwise and with `rhs`

.

`fn not(&self) -> U`

Returns a new `U`

that evaluates to the bitwise not with `rhs`

.

`fn add(&self, rhs: &U) -> U`

Returns a new `U`

that evaluates to the arithmethic addition with `rhs`

.

## Trait Implementations

`impl Clone for U`

[src]

`fn clone(&self) -> U`

Returns a copy of the value. Read more

`fn clone_from(&mut self, source: &Self)`

1.0.0

Performs copy-assignment from `source`

. Read more

`impl From<u32> for U`

[src]

`impl Debug for U`

[src]

`impl Shr<usize> for U`

[src]

`type Output = U`

The resulting type after applying the `>>`

operator

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

The method for the `>>`

operator

`impl<'a> Shr<usize> for &'a U`

[src]

`type Output = U`

The resulting type after applying the `>>`

operator

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

The method for the `>>`

operator

`impl Add<U> for U`

[src]

`type Output = U`

The resulting type after applying the `+`

operator

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

The method for the `+`

operator

`impl<'a> Add<U> for &'a U`

[src]

`type Output = U`

The resulting type after applying the `+`

operator

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

The method for the `+`

operator

`impl<'a> Add<&'a U> for U`

[src]

`type Output = U`

The resulting type after applying the `+`

operator

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

The method for the `+`

operator

`impl<'a, 'b> Add<&'a U> for &'b U`

[src]

`type Output = U`

The resulting type after applying the `+`

operator

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

The method for the `+`

operator

`impl Not for U`

[src]

`type Output = U`

The resulting type after applying the `!`

operator

`fn not(self) -> Self::Output`

The method for the unary `!`

operator

`impl<'a> Not for &'a U`

[src]

`type Output = U`

The resulting type after applying the `!`

operator

`fn not(self) -> Self::Output`

The method for the unary `!`

operator

`impl BitXor<U> for U`

[src]

`type Output = U`

The resulting type after applying the `^`

operator

`fn bitxor(self, rhs: U) -> Self::Output`

The method for the `^`

operator

`impl<'a> BitXor<U> for &'a U`

[src]

`type Output = U`

The resulting type after applying the `^`

operator

`fn bitxor(self, rhs: U) -> Self::Output`

The method for the `^`

operator

`impl<'a> BitXor<&'a U> for U`

[src]

`type Output = U`

The resulting type after applying the `^`

operator

`fn bitxor(self, rhs: &U) -> Self::Output`

The method for the `^`

operator

`impl<'a, 'b> BitXor<&'a U> for &'b U`

[src]

`type Output = U`

The resulting type after applying the `^`

operator

`fn bitxor(self, rhs: &U) -> Self::Output`

The method for the `^`

operator

`impl BitAnd<U> for U`

[src]

`type Output = U`

The resulting type after applying the `&`

operator

`fn bitand(self, rhs: U) -> Self::Output`

The method for the `&`

operator

`impl<'a> BitAnd<U> for &'a U`

[src]

`type Output = U`

The resulting type after applying the `&`

operator

`fn bitand(self, rhs: U) -> Self::Output`

The method for the `&`

operator

`impl<'a> BitAnd<&'a U> for U`

[src]

`type Output = U`

The resulting type after applying the `&`

operator

`fn bitand(self, rhs: &U) -> Self::Output`

The method for the `&`

operator