pub trait SplitInHalf: HasHalf {
// Required methods
fn lower_half(&self) -> Self::Half;
fn upper_half(&self) -> Self::Half;
// Provided method
fn split_in_half(&self) -> (Self::Half, Self::Half) { ... }
}
Expand description
Provides functions to split a number into two pieces. For example, a u64
may be split into
two u32
s.
Extracts the lower, or least-significant, half of a number.
Extracts the upper, or most-significant half of a number.
Extracts both halves of a number; the upper, or most-significant, half comes first.
§Worst-case complexity
$T(n) = O(\max(T_U(n), T_L(n)))$
$M(n) = O(\max(M_U(n), M_L(n)))$
where $T$ is time, $M$ is additional memory, $T_U$ and $T_L$ are the time complexities of
the upper_half
and lower_half
functions,
respectively, and $M_U$ and $M_L$ are the memory complexities of the
upper_half
and lower_half
functions,
respectively.
Extracts the lower, or least significant, half of an unsigned integer.
Let $W$ be the width of Self
(the input type).
$f(n) = m$, where $m < 2^{W/2}$ and $n + 2^{W/2} k = m$ for some $k \in \Z$.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Extracts the upper, or most-significant, half of an unsigned integer.
Let $W$ be the width of Self
(the input type).
$f(n) = \lfloor \frac{n}{2^{W/2}} \rfloor$.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Extracts the lower, or least significant, half of an unsigned integer.
Let $W$ be the width of Self
(the input type).
$f(n) = m$, where $m < 2^{W/2}$ and $n + 2^{W/2} k = m$ for some $k \in \Z$.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Extracts the upper, or most-significant, half of an unsigned integer.
Let $W$ be the width of Self
(the input type).
$f(n) = \lfloor \frac{n}{2^{W/2}} \rfloor$.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Extracts the lower, or least significant, half of an unsigned integer.
Let $W$ be the width of Self
(the input type).
$f(n) = m$, where $m < 2^{W/2}$ and $n + 2^{W/2} k = m$ for some $k \in \Z$.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Extracts the upper, or most-significant, half of an unsigned integer.
Let $W$ be the width of Self
(the input type).
$f(n) = \lfloor \frac{n}{2^{W/2}} \rfloor$.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Extracts the lower, or least significant, half of an unsigned integer.
Let $W$ be the width of Self
(the input type).
$f(n) = m$, where $m < 2^{W/2}$ and $n + 2^{W/2} k = m$ for some $k \in \Z$.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
Extracts the upper, or most-significant, half of an unsigned integer.
Let $W$ be the width of Self
(the input type).
$f(n) = \lfloor \frac{n}{2^{W/2}} \rfloor$.
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.