pub struct SlidingRing<T: Slot> { /* private fields */ }Expand description
Ring that slides over signed coordinates while keeping slot access O(1).
Implementations§
Source§impl<T: Slot> SlidingRing<T>
impl<T: Slot> SlidingRing<T>
Sourcepub fn slot_at_pointer(&self) -> &T
pub fn slot_at_pointer(&self) -> &T
Return an immutable reference to the slot at the anchor.
Sourcepub fn slot_at_pointer_mut(&mut self) -> &mut T
pub fn slot_at_pointer_mut(&mut self) -> &mut T
Return a mutable reference to the slot at the anchor.
Sourcepub fn index_for(&self, coordinate: i128) -> RingIndex
pub fn index_for(&self, coordinate: i128) -> RingIndex
Map an absolute coordinate to the underlying ring index.
Sourcepub fn slot_mut(&mut self, coordinate: i128) -> &mut T
pub fn slot_mut(&mut self, coordinate: i128) -> &mut T
Mutable access to the slot for coordinate.
Sourcepub fn slot_by_index(&self, index: RingIndex) -> &T
pub fn slot_by_index(&self, index: RingIndex) -> &T
Immutable access by raw ring index (0-255).
Sourcepub fn slot_by_index_mut(&mut self, index: RingIndex) -> &mut T
pub fn slot_by_index_mut(&mut self, index: RingIndex) -> &mut T
Mutable access by raw ring index (0-255).
Sourcepub fn shift_to(&mut self, new_anchor: i128)
pub fn shift_to(&mut self, new_anchor: i128)
Shift the anchor to new_anchor, clearing newly entered slots.
Sourcepub fn shift_to_keep_new_base(&mut self, new_anchor: i128)
pub fn shift_to_keep_new_base(&mut self, new_anchor: i128)
Shift the anchor but keep the newly entered base when moving backward.
Sourcepub fn clear_all(&mut self)
pub fn clear_all(&mut self)
Clear every slot and reset the pointer to zero, preserving the anchor.
Sourcepub fn as_mut_slice(&mut self) -> &mut [T; 256]
pub fn as_mut_slice(&mut self) -> &mut [T; 256]
Expose mutable slice reference for advanced use-cases.
Sourcepub fn slices_from_anchor(&self) -> (&[T], &[T])
pub fn slices_from_anchor(&self) -> (&[T], &[T])
Returns the contiguous slices that cover the ring starting at the anchor.
The first slice begins at the pointer slot; the second slice wraps around to index 0 (and may be empty). This is ideal for SIMD scans.
let mut ring = SlidingRing::<u64>::new(10);
*ring.slot_mut(10) = 42;
let (tail, head) = ring.slices_from_anchor();
assert_eq!(tail.first(), Some(&42));
assert!(head.is_empty());Sourcepub fn slices_from_anchor_mut(&mut self) -> (&mut [T], &mut [T])
pub fn slices_from_anchor_mut(&mut self) -> (&mut [T], &mut [T])
Mutable variant of SlidingRing::slices_from_anchor.
let mut ring = SlidingRing::<u64>::new(0);
{
let (tail, head) = ring.slices_from_anchor_mut();
tail[0] = 7;
assert!(head.is_empty());
}
assert_eq!(*ring.slot(0), 7);Sourcepub fn iter_mut(&mut self) -> SlotsMut<'_, T> ⓘ
pub fn iter_mut(&mut self) -> SlotsMut<'_, T> ⓘ
Mutable iterator over slots in storage order using raw pointers.
Sourcepub fn iter_from_anchor(&self, direction: Direction) -> AnchorIter<'_, T> ⓘ
pub fn iter_from_anchor(&self, direction: Direction) -> AnchorIter<'_, T> ⓘ
Iterate starting at the anchor in the desired direction (wrapping once).
let mut ring = SlidingRing::<u64>::new(100);
*ring.slot_mut(100) = 1;
*ring.slot_mut(101) = 2;
let mut iter = ring.iter_from_anchor(Direction::Forward);
assert_eq!(iter.next().unwrap().1, &1);
assert_eq!(iter.next().unwrap().0, 101);Sourcepub fn iter_from_anchor_mut(
&mut self,
direction: Direction,
) -> AnchorIterMut<'_, T> ⓘ
pub fn iter_from_anchor_mut( &mut self, direction: Direction, ) -> AnchorIterMut<'_, T> ⓘ
Mutable iteration starting at the anchor in the desired direction.
let mut ring = SlidingRing::<u64>::new(0);
for (_, slot) in ring.iter_from_anchor_mut(Direction::Forward).take(2) {
*slot = 5;
}
assert_eq!(*ring.slot(0), 5);
assert_eq!(*ring.slot(1), 5);