Function malachite_base::slices::min_repeating_len

source ·
pub fn min_repeating_len<T: Eq>(xs: &[T]) -> usize
Expand description

Given a slice with nonzero length $\ell$, returns the smallest $n$ such that the slice consists of $n/\ell$ copies of a length-$\ell$ subslice.

Typically $\ell = n$.

§Worst-case complexity

$T(n) = O(n^{1+\varepsilon})$ for all $\varepsilon > 0$

$M(n) = O(n)$

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

§Panics

Panics if xs is empty.

§Examples

use malachite_base::slices::min_repeating_len;

assert_eq!(min_repeating_len(&[1, 2, 1, 2, 1, 2]), 2);
assert_eq!(min_repeating_len(&[1, 2, 1, 2, 1, 3]), 6);
assert_eq!(min_repeating_len(&[5, 5, 5]), 1);