Trait malachite_base::num::conversion::traits::SplitInHalf

source ·
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 u32s.

Required Methods§

source

fn lower_half(&self) -> Self::Half

Extracts the lower, or least-significant, half of a number.

source

fn upper_half(&self) -> Self::Half

Extracts the upper, or most-significant half of a number.

Provided Methods§

source

fn split_in_half(&self) -> (Self::Half, Self::Half)

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.

Implementations on Foreign Types§

source§

impl SplitInHalf for u16

source§

fn lower_half(&self) -> Self::Half

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.

source§

fn upper_half(&self) -> Self::Half

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.

source§

impl SplitInHalf for u32

source§

fn lower_half(&self) -> Self::Half

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.

source§

fn upper_half(&self) -> Self::Half

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.

source§

impl SplitInHalf for u64

source§

fn lower_half(&self) -> Self::Half

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.

source§

fn upper_half(&self) -> Self::Half

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.

source§

impl SplitInHalf for u128

source§

fn lower_half(&self) -> Self::Half

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.

source§

fn upper_half(&self) -> Self::Half

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.

Implementors§