Skip to main content

ModSum

Trait ModSum 

Source
pub trait ModSum<A = Self, M = Self>: Sized {
    // Required method
    fn mod_sum<I: Iterator<Item = A>>(xs: I, m: M) -> Self;
}
Expand description

Adds up the numbers in an iterator, modulo another number $m$. Every number must be already reduced modulo $m$.

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

Required Methods§

Source

fn mod_sum<I: Iterator<Item = A>>(xs: I, m: M) -> 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 ModSum for u8

Source§

fn mod_sum<I: Iterator<Item = u8>>(xs: I, m: u8) -> u8

Adds up all the numbers in an iterator, modulo another number $m$. Every number must be already reduced modulo $m$.

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

§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 m is zero or if any number is greater than or equal to m.

§Examples

See here.

Source§

impl ModSum for u16

Source§

fn mod_sum<I: Iterator<Item = u16>>(xs: I, m: u16) -> u16

Adds up all the numbers in an iterator, modulo another number $m$. Every number must be already reduced modulo $m$.

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

§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 m is zero or if any number is greater than or equal to m.

§Examples

See here.

Source§

impl ModSum for u32

Source§

fn mod_sum<I: Iterator<Item = u32>>(xs: I, m: u32) -> u32

Adds up all the numbers in an iterator, modulo another number $m$. Every number must be already reduced modulo $m$.

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

§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 m is zero or if any number is greater than or equal to m.

§Examples

See here.

Source§

impl ModSum for u64

Source§

fn mod_sum<I: Iterator<Item = u64>>(xs: I, m: u64) -> u64

Adds up all the numbers in an iterator, modulo another number $m$. Every number must be already reduced modulo $m$.

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

§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 m is zero or if any number is greater than or equal to m.

§Examples

See here.

Source§

impl ModSum for u128

Source§

fn mod_sum<I: Iterator<Item = u128>>(xs: I, m: u128) -> u128

Adds up all the numbers in an iterator, modulo another number $m$. Every number must be already reduced modulo $m$.

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

§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 m is zero or if any number is greater than or equal to m.

§Examples

See here.

Source§

impl ModSum for usize

Source§

fn mod_sum<I: Iterator<Item = usize>>(xs: I, m: usize) -> usize

Adds up all the numbers in an iterator, modulo another number $m$. Every number must be already reduced modulo $m$.

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

§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 m is zero or if any number is greater than or equal to m.

§Examples

See here.

Source§

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

Source§

fn mod_sum<I: Iterator<Item = &'a u8>>(xs: I, m: u8) -> u8

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

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

§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 m is zero or if any number is greater than or equal to m.

§Examples

See here.

Source§

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

Source§

fn mod_sum<I: Iterator<Item = &'a u16>>(xs: I, m: u16) -> u16

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

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

§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 m is zero or if any number is greater than or equal to m.

§Examples

See here.

Source§

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

Source§

fn mod_sum<I: Iterator<Item = &'a u32>>(xs: I, m: u32) -> u32

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

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

§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 m is zero or if any number is greater than or equal to m.

§Examples

See here.

Source§

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

Source§

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

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

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

§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 m is zero or if any number is greater than or equal to m.

§Examples

See here.

Source§

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

Source§

fn mod_sum<I: Iterator<Item = &'a u128>>(xs: I, m: u128) -> u128

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

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

§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 m is zero or if any number is greater than or equal to m.

§Examples

See here.

Source§

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

Source§

fn mod_sum<I: Iterator<Item = &'a usize>>(xs: I, m: usize) -> usize

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

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

§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 m is zero or if any number is greater than or equal to m.

§Examples

See here.

Implementors§