Struct libp2p::multihash::typenum::UInt [−][src]
pub struct UInt<U, B> { /* fields omitted */ }
Expand description
UInt
is defined recursively, where B
is the least significant bit and U
is the rest
of the number. Conceptually, U
should be bound by the trait Unsigned
and B
should
be bound by the trait Bit
, but enforcing these bounds causes linear instead of
logrithmic scaling in some places, so they are left off for now. They may be enforced in
future.
In order to keep numbers unique, leading zeros are not allowed, so UInt<UTerm, B0>
is
forbidden.
Example
use typenum::{UInt, UTerm, B0, B1};
type U6 = UInt<UInt<UInt<UTerm, B1>, B1>, B0>;
Implementations
Trait Implementations
U + B0 = U
UInt<U, B0> + B1 = UInt<U + B1>
UInt<U, B1> + B1 = UInt<U + B1, B0>
UInt<Ul, B1> + UInt<Ur, B0> = UInt<Ul + Ur, B1>
UInt<Ul, B0> + UInt<Ur, B0> = UInt<Ul + Ur, B0>
UInt<Ul, B1> + UInt<Ur, B1> = UInt<(Ul + Ur) + B1, B0>
UInt<Ul, B0> + UInt<Ur, B1> = UInt<Ul + Ur, B1>
UInt<U, B> + UTerm = UInt<U, B>
type ArrayType
type ArrayType
Associated type representing the array type for the number
type ArrayType
type ArrayType
Associated type representing the array type for the number
Anding unsigned integers.
We use our PrivateAnd
operator and then Trim
the output.
UInt<Ul, B1> | UInt<Ur, B0> = UInt<Ul | Ur, B1>
UInt<Ul, B0> | UInt<Ur, B0> = UInt<Ul | Ur, B0>
UInt<Ul, B1> | UInt<Ur, B1> = UInt<Ul | Ur, B1>
UInt<Ul, B0> | UInt<Ur, B1> = UInt<Ul | Ur, B1>
X | UTerm = X
Xoring unsigned integers.
We use our PrivateXor
operator and then Trim
the output.
Zero < Nonzero
UInt<Ul, B1>
cmp with UInt<Ur, B0>
: SoFar
is Greater
UInt<Ul, B0>
cmp with UInt<Ur, B0>
: SoFar
is Equal
UInt<Ul, B1>
cmp with UInt<Ur, B1>
: SoFar
is Equal
UInt<Ul, B0>
cmp with UInt<Ur, B1>
: SoFar
is Less
Nonzero > Zero
The resulting type after applying the /
operator.
gcd(x, y) = 2*gcd(x/2, y/2) if both x and y even
gcd(x, y) = gcd(x, y/2) if x odd and y even
gcd(x, y) = gcd(x/2, y) if x even and y odd
impl<Xp, Yp> Gcd<UInt<Yp, B1>> for UInt<Xp, B1> where
UInt<Xp, B1>: Max<UInt<Yp, B1>>,
UInt<Xp, B1>: Min<UInt<Yp, B1>>,
UInt<Yp, B1>: Max<UInt<Xp, B1>>,
UInt<Yp, B1>: Min<UInt<Xp, B1>>,
<UInt<Xp, B1> as Max<UInt<Yp, B1>>>::Output: Sub<<UInt<Xp, B1> as Min<UInt<Yp, B1>>>::Output>,
<<UInt<Xp, B1> as Max<UInt<Yp, B1>>>::Output as Sub<<UInt<Xp, B1> as Min<UInt<Yp, B1>>>::Output>>::Output: Gcd<<UInt<Xp, B1> as Min<UInt<Yp, B1>>>::Output>,
impl<Xp, Yp> Gcd<UInt<Yp, B1>> for UInt<Xp, B1> where
UInt<Xp, B1>: Max<UInt<Yp, B1>>,
UInt<Xp, B1>: Min<UInt<Yp, B1>>,
UInt<Yp, B1>: Max<UInt<Xp, B1>>,
UInt<Yp, B1>: Min<UInt<Xp, B1>>,
<UInt<Xp, B1> as Max<UInt<Yp, B1>>>::Output: Sub<<UInt<Xp, B1> as Min<UInt<Yp, B1>>>::Output>,
<<UInt<Xp, B1> as Max<UInt<Yp, B1>>>::Output as Sub<<UInt<Xp, B1> as Min<UInt<Yp, B1>>>::Output>>::Output: Gcd<<UInt<Xp, B1> as Min<UInt<Yp, B1>>>::Output>,
gcd(x, y) = gcd([max(x, y) - min(x, y)], min(x, y)) if both x and y odd
This will immediately invoke the case for x even and y odd because the difference of two odd numbers is an even number.
Length of a bit is 1
UInt * B0 = UTerm
UInt * B1 = UInt
UInt<Ul, B0> * UInt<Ur, B> = UInt<(Ul * UInt<Ur, B>), B0>
UInt<Ul, B1> * UInt<Ur, B> = UInt<(Ul * UInt<Ur, B>), B0> + UInt<Ur, B>
UInt<U, B> * UTerm = UTerm
Method for performing the division
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
The resulting type after applying the %
operator.
Shifting left any unsigned by a zero bit: U << B0 = U
Shifting left a UInt
by a one bit: UInt<U, B> << B1 = UInt<UInt<U, B>, B0>
Shifting left UInt
by UInt
: X << Y
= UInt(X, B0) << (Y - 1)
Shifting left UInt
by UTerm
: UInt<U, B> << UTerm = UInt<U, B>
Shifting right any unsigned by a zero bit: U >> B0 = U
Shifting right a UInt
by a 1 bit: UInt<U, B> >> B1 = U
Shifting right UInt
by UInt
: UInt(U, B) >> Y
= U >> (Y - 1)
Shifting right UInt
by UTerm
: UInt<U, B> >> UTerm = UInt<U, B>
UInt - B0 = UInt
UInt<UTerm, B1> - B1 = UTerm
UInt<U, B1> - B1 = UInt<U, B0>
UInt<U, B0> - B1 = UInt<U - B1, B1>
Subtracting unsigned integers. We just do our PrivateSub
and then Trim
the output.
Auto Trait Implementations
impl<U, B> RefUnwindSafe for UInt<U, B> where
B: RefUnwindSafe,
U: RefUnwindSafe,
impl<U, B> UnwindSafe for UInt<U, B> where
B: UnwindSafe,
U: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
type Output = X
type Output = X
The greatest common divisor.
type Output = <N as PrivateLogarithm2>::Output
type Output = <N as PrivateLogarithm2>::Output
The result of the integer binary logarithm.
type Output = <N as PrivateSquareRoot>::Output
type Output = <N as PrivateSquareRoot>::Output
The result of the integer square root.