Skip to main content

ModPowerOf2Sum

Trait ModPowerOf2Sum 

Source
pub trait ModPowerOf2Sum<A = Self>: Sized {
    // Required method
    fn mod_power_of_2_sum<I: Iterator<Item = A>>(xs: I, pow: u64) -> Self;
}
Expand description

Adds up the numbers in an iterator, modulo $2^k$. Every number must be already reduced modulo $2^k$.

Like Sum, this is implemented both for iterators of values and for iterators of references.

Required Methods§

Source

fn mod_power_of_2_sum<I: Iterator<Item = A>>(xs: I, pow: u64) -> Self

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ModPowerOf2Sum for u8

Source§

fn mod_power_of_2_sum<I: Iterator<Item = u8>>(xs: I, pow: u64) -> u8

Adds up all the numbers in an iterator, modulo $2^k$. Every number must be already reduced modulo $2^k$.

$f((x_i)_ {i=0}^{n-1}, k) = y$, where $y < 2^k$ and $\sum_ {i=0}^{n-1} x_i \equiv y \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is xs.count().

§Panics

Panics if pow is greater than Self::WIDTH or if any number is greater than or equal to $2^k$.

§Examples

See here.

Source§

impl ModPowerOf2Sum for u16

Source§

fn mod_power_of_2_sum<I: Iterator<Item = u16>>(xs: I, pow: u64) -> u16

Adds up all the numbers in an iterator, modulo $2^k$. Every number must be already reduced modulo $2^k$.

$f((x_i)_ {i=0}^{n-1}, k) = y$, where $y < 2^k$ and $\sum_ {i=0}^{n-1} x_i \equiv y \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is xs.count().

§Panics

Panics if pow is greater than Self::WIDTH or if any number is greater than or equal to $2^k$.

§Examples

See here.

Source§

impl ModPowerOf2Sum for u32

Source§

fn mod_power_of_2_sum<I: Iterator<Item = u32>>(xs: I, pow: u64) -> u32

Adds up all the numbers in an iterator, modulo $2^k$. Every number must be already reduced modulo $2^k$.

$f((x_i)_ {i=0}^{n-1}, k) = y$, where $y < 2^k$ and $\sum_ {i=0}^{n-1} x_i \equiv y \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is xs.count().

§Panics

Panics if pow is greater than Self::WIDTH or if any number is greater than or equal to $2^k$.

§Examples

See here.

Source§

impl ModPowerOf2Sum for u64

Source§

fn mod_power_of_2_sum<I: Iterator<Item = u64>>(xs: I, pow: u64) -> u64

Adds up all the numbers in an iterator, modulo $2^k$. Every number must be already reduced modulo $2^k$.

$f((x_i)_ {i=0}^{n-1}, k) = y$, where $y < 2^k$ and $\sum_ {i=0}^{n-1} x_i \equiv y \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is xs.count().

§Panics

Panics if pow is greater than Self::WIDTH or if any number is greater than or equal to $2^k$.

§Examples

See here.

Source§

impl ModPowerOf2Sum for u128

Source§

fn mod_power_of_2_sum<I: Iterator<Item = u128>>(xs: I, pow: u64) -> u128

Adds up all the numbers in an iterator, modulo $2^k$. Every number must be already reduced modulo $2^k$.

$f((x_i)_ {i=0}^{n-1}, k) = y$, where $y < 2^k$ and $\sum_ {i=0}^{n-1} x_i \equiv y \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is xs.count().

§Panics

Panics if pow is greater than Self::WIDTH or if any number is greater than or equal to $2^k$.

§Examples

See here.

Source§

impl ModPowerOf2Sum for usize

Source§

fn mod_power_of_2_sum<I: Iterator<Item = usize>>(xs: I, pow: u64) -> usize

Adds up all the numbers in an iterator, modulo $2^k$. Every number must be already reduced modulo $2^k$.

$f((x_i)_ {i=0}^{n-1}, k) = y$, where $y < 2^k$ and $\sum_ {i=0}^{n-1} x_i \equiv y \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is xs.count().

§Panics

Panics if pow is greater than Self::WIDTH or if any number is greater than or equal to $2^k$.

§Examples

See here.

Source§

impl<'a> ModPowerOf2Sum<&'a u8> for u8

Source§

fn mod_power_of_2_sum<I: Iterator<Item = &'a u8>>(xs: I, pow: u64) -> u8

Adds up all the numbers in an iterator of references, modulo $2^k$. Every number must be already reduced modulo $2^k$.

$f((x_i)_ {i=0}^{n-1}, k) = y$, where $y < 2^k$ and $\sum_ {i=0}^{n-1} x_i \equiv y \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is xs.count().

§Panics

Panics if pow is greater than Self::WIDTH or if any number is greater than or equal to $2^k$.

§Examples

See here.

Source§

impl<'a> ModPowerOf2Sum<&'a u16> for u16

Source§

fn mod_power_of_2_sum<I: Iterator<Item = &'a u16>>(xs: I, pow: u64) -> u16

Adds up all the numbers in an iterator of references, modulo $2^k$. Every number must be already reduced modulo $2^k$.

$f((x_i)_ {i=0}^{n-1}, k) = y$, where $y < 2^k$ and $\sum_ {i=0}^{n-1} x_i \equiv y \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is xs.count().

§Panics

Panics if pow is greater than Self::WIDTH or if any number is greater than or equal to $2^k$.

§Examples

See here.

Source§

impl<'a> ModPowerOf2Sum<&'a u32> for u32

Source§

fn mod_power_of_2_sum<I: Iterator<Item = &'a u32>>(xs: I, pow: u64) -> u32

Adds up all the numbers in an iterator of references, modulo $2^k$. Every number must be already reduced modulo $2^k$.

$f((x_i)_ {i=0}^{n-1}, k) = y$, where $y < 2^k$ and $\sum_ {i=0}^{n-1} x_i \equiv y \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is xs.count().

§Panics

Panics if pow is greater than Self::WIDTH or if any number is greater than or equal to $2^k$.

§Examples

See here.

Source§

impl<'a> ModPowerOf2Sum<&'a u64> for u64

Source§

fn mod_power_of_2_sum<I: Iterator<Item = &'a u64>>(xs: I, pow: u64) -> u64

Adds up all the numbers in an iterator of references, modulo $2^k$. Every number must be already reduced modulo $2^k$.

$f((x_i)_ {i=0}^{n-1}, k) = y$, where $y < 2^k$ and $\sum_ {i=0}^{n-1} x_i \equiv y \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is xs.count().

§Panics

Panics if pow is greater than Self::WIDTH or if any number is greater than or equal to $2^k$.

§Examples

See here.

Source§

impl<'a> ModPowerOf2Sum<&'a u128> for u128

Source§

fn mod_power_of_2_sum<I: Iterator<Item = &'a u128>>(xs: I, pow: u64) -> u128

Adds up all the numbers in an iterator of references, modulo $2^k$. Every number must be already reduced modulo $2^k$.

$f((x_i)_ {i=0}^{n-1}, k) = y$, where $y < 2^k$ and $\sum_ {i=0}^{n-1} x_i \equiv y \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is xs.count().

§Panics

Panics if pow is greater than Self::WIDTH or if any number is greater than or equal to $2^k$.

§Examples

See here.

Source§

impl<'a> ModPowerOf2Sum<&'a usize> for usize

Source§

fn mod_power_of_2_sum<I: Iterator<Item = &'a usize>>(xs: I, pow: u64) -> usize

Adds up all the numbers in an iterator of references, modulo $2^k$. Every number must be already reduced modulo $2^k$.

$f((x_i)_ {i=0}^{n-1}, k) = y$, where $y < 2^k$ and $\sum_ {i=0}^{n-1} x_i \equiv y \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is xs.count().

§Panics

Panics if pow is greater than Self::WIDTH or if any number is greater than or equal to $2^k$.

§Examples

See here.

Implementors§