A lazy '''view''' of a sequence considered circular.
A RingView never copies its elements: it wraps an IndexedSeq together with a rotation offset and a reflected flag, so rotateRight, rotateLeft, startAt, reflectAt and reverse are all O(1) — they return a new view over the same underlying sequence. In particular rotations and rotationsAndReflections produce views in O(1) each, so pipelines like seq.ring.rotations.exists(...) short-circuit without materializing anything.
Because RingView is its own type (not a Seq), the circular operations carry their plain names — no O suffix is needed: seq.ring.slice(-1, 4), seq.ring.sliding(2), and indexing wraps in both directions.
Materialize at the boundary with toSeq, toVector, to or iterator.
Obtain a view with the ring method added to every Seq (and String) by import RingSeq._:
Vector(0, 1, 2, 3).ring.rotateRight(1).toVector // Vector(3, 0, 1, 2)
Attributes
- Note
-
a view over a mutable sequence reflects later mutations of it, exactly like the standard library views. A non-indexed source (e.g.
List) is copied once to aVectoron creation. - Companion
- object
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
Members list
Value members
Concrete methods
Finds the rotation offset that aligns this ring with a given sequence.
Finds the rotation offset that aligns this ring with a given sequence.
Attributes
- Returns
-
Some(k)such thatstartAt(k)equals ''that'', orNoneif no rotation matches (or sizes differ).
Gets the element at some circular index: any integer is valid, wrapping in both directions.
Gets the element at some circular index: any integer is valid, wrapping in both directions.
Attributes
- Throws
-
java.lang.ArithmeticException
if the ring is empty
- Example
-
Seq(0, 1, 2).ring(3) // 0
The lexicographically smallest representative under both rotation and reflection (bracelet canonical form) as a view.
The lexicographically smallest representative under both rotation and reflection (bracelet canonical form) as a view.
Attributes
The lexicographically smallest rotation of this ring (necklace canonical form) as a view.
The lexicographically smallest rotation of this ring (necklace canonical form) as a view.
Attributes
The starting index of the lexicographically smallest rotation of this view (two-pointer minimal rotation, O(n) time).
The starting index of the lexicographically smallest rotation of this view (two-pointer minimal rotation, O(n) time).
Attributes
Tests whether this ring contains a given sequence as a (possibly wrapping) slice.
Tests whether this ring contains a given sequence as a (possibly wrapping) slice.
Attributes
Drops the longest prefix of elements starting at some circular index that satisfy a predicate, as a lazy iterator over the remainder of the lap.
Drops the longest prefix of elements starting at some circular index that satisfy a predicate, as a lazy iterator over the remainder of the lap.
Attributes
Two views are equal iff they present the same elements in the same order, regardless of how they were obtained.
Two views are equal iff they present the same elements in the same order, regardless of how they were obtained.
Attributes
- Definition Classes
-
Any
Partitions the ring into non-overlapping fixed-size blocks, the last wrapping across the seam so every block has exactly size elements. Produces ceil(n / size) blocks, none for an empty ring.
Partitions the ring into non-overlapping fixed-size blocks, the last wrapping across the seam so every block has exactly size elements. Produces ceil(n / size) blocks, none for an empty ring.
Attributes
The number of positions at which corresponding elements differ (Hamming distance).
The number of positions at which corresponding elements differ (Hamming distance).
Attributes
- Throws
-
java.lang.IllegalArgumentException
if the sizes differ
Calculates a hash code value for the object.
Calculates a hash code value for the object.
The default hashing algorithm is platform dependent.
Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.
Attributes
- Returns
-
the hash code value for this object.
- Definition Classes
-
Any
Normalize a given circular index to [0, size).
Normalize a given circular index to [0, size).
Attributes
- Throws
-
java.lang.ArithmeticException
if the ring is empty
Finds the circular index of the first element equal to a given value, searching circularly from a given circular index and wrapping past the end.
Finds the circular index of the first element equal to a given value, searching circularly from a given circular index and wrapping past the end.
Attributes
- Returns
-
the index in
[0, size), or -1 if the element is not in the ring.
Finds the first index at or after a circular start index where this ring contains a given sequence as a (possibly wrapping) slice, or -1 if none exists.
Finds the first index at or after a circular start index where this ring contains a given sequence as a (possibly wrapping) slice, or -1 if none exists.
Attributes
Tests whether the ring is empty.
Tests whether the ring is empty.
Attributes
Tests whether this ring is a reflection of a given sequence.
Tests whether this ring is a reflection of a given sequence.
Attributes
Tests whether this ring is a reversion of a given sequence.
Tests whether this ring is a reversion of a given sequence.
Attributes
Tests whether this ring is a rotation of a given sequence.
Tests whether this ring is a rotation of a given sequence.
Attributes
Tests whether this ring is a rotation or a reflection of a given sequence.
Tests whether this ring is a rotation or a reflection of a given sequence.
Attributes
Iterates once over the ring in view order.
Iterates once over the ring in view order.
Attributes
Finds the last index at or before a circular end index where this ring contains a given sequence as a (possibly wrapping) slice, or -1 if none exists.
Finds the last index at or before a circular end index where this ring contains a given sequence as a (possibly wrapping) slice, or -1 if none exists.
Attributes
The number of elements in the ring.
The number of elements in the ring.
Attributes
Optionally gets the element at some circular index: None only when the ring is empty.
Optionally gets the element at some circular index: None only when the ring is empty.
Attributes
- Example
-
Seq(0, 1, 2).ring.lift(3) // Some(0)
The minimum Hamming distance over all rotations of this ring.
The minimum Hamming distance over all rotations of this ring.
Attributes
- Throws
-
java.lang.IllegalArgumentException
if the sizes differ
Tests whether the ring is not empty.
Tests whether the ring is not empty.
Attributes
A view of this ring reflected (direction flipped) to start at some circular index — O(1), no copy. Applying reflectAt at the same index twice returns the original view.
A view of this ring reflected (direction flipped) to start at some circular index — O(1), no copy. Applying reflectAt at the same index twice returns the original view.
Attributes
- Example
-
Seq(0, 1, 2).ring.reflectAt().toVector // Vector(0, 2, 1)
Calculates the axes of reflectional symmetry of this ring.
Calculates the axes of reflectional symmetry of this ring.
Attributes
The 2 reflections of this ring as views (itself and reflectAt()), or just itself if empty.
The 2 reflections of this ring as views (itself and reflectAt()), or just itself if empty.
Attributes
A view of this ring with the elements in reverse order — O(1), no copy.
A view of this ring with the elements in reverse order — O(1), no copy.
Attributes
The 2 reversions of this ring as views (itself and reverse), or just itself if empty.
The 2 reversions of this ring as views (itself and reverse), or just itself if empty.
Attributes
A view of this ring rotated to the left by some steps (negative = right) — O(1), no copy.
A view of this ring rotated to the left by some steps (negative = right) — O(1), no copy.
Attributes
- Example
-
Seq(0, 1, 2).ring.rotateLeft(1).toVector // Vector(1, 2, 0)
A view of this ring rotated to the right by some steps (negative = left) — O(1), no copy.
A view of this ring rotated to the right by some steps (negative = left) — O(1), no copy.
Attributes
- Example
-
Seq(0, 1, 2).ring.rotateRight(1).toVector // Vector(2, 0, 1)
Computes the order of rotational symmetry possessed by this ring.
Computes the order of rotational symmetry possessed by this ring.
Attributes
All the rotations of this ring as views — O(1) each, starting from this view itself, or just itself if empty.
All the rotations of this ring as views — O(1) each, starting from this view itself, or just itself if empty.
Attributes
- Example
-
Seq(0, 1, 2).ring.rotations.map(_.toVector) // Iterator(Vector(0, 1, 2), Vector(1, 2, 0), Vector(2, 0, 1))
All the rotations and reflections of this ring as views — O(1) each, or just itself if empty.
All the rotations and reflections of this ring as views — O(1) each, or just itself if empty.
Attributes
Computes the length of the longest segment starting at some circular index whose elements all satisfy a predicate (at most one full lap).
Computes the length of the longest segment starting at some circular index whose elements all satisfy a predicate (at most one full lap).
Attributes
The number of elements in the ring.
The number of elements in the ring.
Attributes
Selects an interval of elements as a lazy iterator: circular indices, and the interval may be longer than the ring itself.
Selects an interval of elements as a lazy iterator: circular indices, and the interval may be longer than the ring itself.
Attributes
- Example
-
Seq(0, 1, 2).ring.slice(-1, 4).toList // List(2, 0, 1, 2, 0)
Groups elements in fixed size blocks by passing a "sliding window" over the ring, wrapping past the end.
Groups elements in fixed size blocks by passing a "sliding window" over the ring, wrapping past the end.
Attributes
- Example
-
Seq(0, 1, 2).ring.sliding(2).toList // List(Seq(0, 1), Seq(1, 2), Seq(2, 0))
Splits one lap of the ring at the first element, starting from some circular index, that does not satisfy the predicate.
Splits one lap of the ring at the first element, starting from some circular index, that does not satisfy the predicate.
Attributes
- Returns
-
a pair
(takeWhile(p, from), dropWhile(p, from))of lazy iterators.
A view of this ring rotated to start at some circular index — O(1), no copy.
A view of this ring rotated to start at some circular index — O(1), no copy.
Attributes
- Example
-
Seq(0, 1, 2, 3).ring.startAt(2).toVector // Vector(2, 3, 0, 1)
Computes the order of reflectional (mirror) symmetry possessed by this ring.
Computes the order of reflectional (mirror) symmetry possessed by this ring.
Attributes
Finds the indices of each element of this ring close to an axis of reflectional symmetry.
Finds the indices of each element of this ring close to an axis of reflectional symmetry.
Attributes
Selects the longest prefix of elements starting at some circular index that satisfy a predicate, as a lazy iterator (at most one full lap).
Selects the longest prefix of elements starting at some circular index that satisfy a predicate, as a lazy iterator (at most one full lap).
Attributes
Materializes this view to any collection type.
Materializes this view to any collection type.
Attributes
- Example
-
Seq(0, 1, 2).ring.rotateLeft(1).to(List) // List(1, 2, 0)
Materializes this view to an immutable Seq.
Materializes this view to an immutable Seq.
Attributes
Returns a string representation of the object.
Returns a string representation of the object.
The default representation is platform dependent.
Attributes
- Returns
-
a string representation of the object.
- Definition Classes
-
Any
Materializes this view to a Vector.
Materializes this view to a Vector.
Attributes
Iterates over the elements paired with their view index, starting at some circular index. Indices are in [0, size).
Iterates over the elements paired with their view index, starting at some circular index. Indices are in [0, size).