Skip to main content

Crate ring_seq

Crate ring_seq 

Source
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.
CircularIter
Iterator over the elements of a Circular view.
Enumerate
Iterator over (element, ring_index) pairs of a Circular view.
Reflections
Iterator yielding the source Circular and its reflect_at(0).
Reversions
Iterator yielding the source Circular and its reverse (reflect_at(-1)).
Rotations
Iterator over the rotations of a Circular view.
RotationsAndReflections
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 Circular view as CircularIters.

Enums§

AxisLocation
A location on a circular sequence where a reflectional-symmetry axis passes.

Traits§

AsCircular
Extension trait providing circular on slices.