Expand description
Circular (ring) sequence operations for Rust slices.
Reach the circular API by calling AsCircular::circular on any slice,
Vec<T>, array, or Box<[T]>.
The returned Circular wrapper is the single home for every circular
operation; every transform it offers is lazy and allocation-free.
§Quick start
use ring_seq::AsCircular;
let r = [10, 20, 30].circular();
// Indexing wraps in both directions
assert_eq!(*r.apply(4), 20);
assert_eq!(*r.apply(-1), 30);
// Reindexed views — no allocation
let rotated: Vec<_> = r.rotate_right(1).iter().copied().collect();
assert_eq!(rotated, vec![30, 10, 20]);
// Comparisons up to rotation/reflection
assert!(r.is_rotation_of(&[20, 30, 10]));
assert!(r.is_reflection_of(&[10, 30, 20]));
// Canonical (necklace) form — uses Booth's O(n)
assert_eq!(r.canonical(), vec![10, 20, 30]);
// Lazy iterators of views
let firsts: Vec<i32> = r.rotations().map(|v| *v.apply(0)).collect();
assert_eq!(firsts, vec![10, 20, 30]);§no_std
The crate is #![no_std]. The default alloc feature enables the
methods that return owned collections (Circular::to_vec,
Circular::canonical, Circular::bracelet,
Circular::symmetry_indices,
Circular::reflectional_symmetry_axes) and the implementation of
Circular::canonical_index (Booth’s algorithm allocates internally).
With --no-default-features the wrapper and its element/view iterators
remain available and depend only on core.
Structs§
- Circular
- A borrowed view of a slice as a circular sequence.
- Circular
Iter - Iterator over the elements of a
Circularview. - Enumerate
- Iterator over
(element, ring_index)pairs of aCircularview. - Reflections
- Iterator yielding the source
Circularand itsreflect_at(0). - Reversions
- Iterator yielding the source
Circularand its reverse (reflect_at(-1)). - Rotations
- Iterator over the rotations of a
Circularview. - Rotations
AndReflections - Iterator yielding every rotation of the source followed by every rotation of its reflection at position 0.
- Windows
- Iterator yielding circular windows (or chunks) of a
Circularview asCircularIters.
Enums§
- Axis
Location - A location on a circular sequence where a reflectional-symmetry axis passes.
Traits§
- AsCircular
- Extension trait providing
circularon slices.