pub struct SlidingRing<T: Copy, const DEPTH: u8> { /* private fields */ }Expand description
Ring that slides over signed coordinates while keeping slot access O(1).
Implementations§
Source§impl<T: Copy, const DEPTH: u8> SlidingRing<T, DEPTH>
impl<T: Copy, const DEPTH: u8> SlidingRing<T, DEPTH>
Sourcepub fn borrow_anchor(&self) -> &T
pub fn borrow_anchor(&self) -> &T
Borrow the slot at the anchor.
Sourcepub fn borrow_anchor_mut(&mut self) -> &mut T
pub fn borrow_anchor_mut(&mut self) -> &mut T
Borrow the slot at the anchor mutably.
Sourcepub fn slot(&self, offset: RingIndex) -> &T
pub fn slot(&self, offset: RingIndex) -> &T
Immutable access to the slot for offset (measured from the anchor).
Sourcepub fn slot_mut(&mut self, offset: RingIndex) -> &mut T
pub fn slot_mut(&mut self, offset: RingIndex) -> &mut T
Mutable access to the slot for offset (measured from the anchor).
Sourcepub fn shift_by(&mut self, delta: i128)
pub fn shift_by(&mut self, delta: i128)
Shift the anchor by delta, clearing only the slots that newly enter the window.
Sourcepub fn shift_by_keep_anchor(&mut self, delta: i128)
pub fn shift_by_keep_anchor(&mut self, delta: i128)
Shift by delta while preserving the new anchor slot on backward moves.
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 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 anchor slot; the second slice wraps around to index 0 (and may be empty). This is ideal for SIMD scans.
const DEPTH: u8 = 16;
let mut ring = SlidingRing::<u64, DEPTH>::new(0);
*ring.slot_mut(0) = 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.
const DEPTH: u8 = 16;
let mut ring = SlidingRing::<u64, DEPTH>::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, DEPTH> ⓘ
pub fn iter_from_anchor(&self, direction: Direction) -> AnchorIter<'_, T, DEPTH> ⓘ
Iterate starting at the anchor in the desired direction (wrapping once).
const DEPTH: u8 = 16;
let mut ring = SlidingRing::<u64, DEPTH>::new(0);
*ring.slot_mut(0) = 1;
*ring.slot_mut(1) = 2;
let mut iter = ring.iter_from_anchor(Direction::Forward);
assert_eq!(iter.next().unwrap().1, &1);
assert_eq!(iter.next().unwrap().0, 1);Sourcepub fn iter_from_anchor_mut(
&mut self,
direction: Direction,
) -> AnchorIterMut<'_, T, DEPTH> ⓘ
pub fn iter_from_anchor_mut( &mut self, direction: Direction, ) -> AnchorIterMut<'_, T, DEPTH> ⓘ
Mutable iteration starting at the anchor in the desired direction.
const DEPTH: u8 = 16;
let mut ring = SlidingRing::<u64, DEPTH>::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);