pub struct Ring<T> { /* private fields */ }Expand description
A ring topology over a collection of elements.
Provides circular access patterns and ring-based distance metrics. Elements are stored contiguously for cache efficiency.
Implementations§
Source§impl<T> Ring<T>
impl<T> Ring<T>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a ring with capacity for n nodes.
Sourcepub fn get_mut(&mut self, idx: usize) -> &mut T
pub fn get_mut(&mut self, idx: usize) -> &mut T
Get a mutable reference to the node at the given index (wrapping).
Sourcepub fn ring_distance(&self, a: usize, b: usize) -> usize
pub fn ring_distance(&self, a: usize, b: usize) -> usize
Compute the ring distance between two indices.
The ring distance is the shortest path between two nodes, going either forward or backward around the ring.
§Example
For a ring of size 5:
ring_distance(0, 1)= 1 (one step forward)ring_distance(0, 4)= 1 (one step backward)ring_distance(0, 2)= 2 (two steps either way)
Sourcepub fn neighbors(&self, idx: usize, radius: usize) -> impl Iterator<Item = &T>
pub fn neighbors(&self, idx: usize, radius: usize) -> impl Iterator<Item = &T>
Iterate over neighbors within a given radius.
Returns an iterator yielding references to nodes within radius
steps in both directions.
§Example
For a ring [0, 1, 2, 3, 4], neighbors(0, 1) yields nodes at indices 4, 1 (previous and next).
Sourcepub fn neighbor_indices(&self, idx: usize, radius: usize) -> Vec<usize>
pub fn neighbor_indices(&self, idx: usize, radius: usize) -> Vec<usize>
Get neighbor indices within a given radius.
Returns indices (not values) of neighbors.
Sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>
Iterate over all nodes mutably in order.
Sourcepub fn iter_from(&self, start: usize) -> impl Iterator<Item = &T>
pub fn iter_from(&self, start: usize) -> impl Iterator<Item = &T>
Iterate starting from a given index, wrapping around.
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Get the underlying nodes as a mutable slice.
Sourcepub fn into_inner(self) -> Vec<T>
pub fn into_inner(self) -> Vec<T>
Into the underlying vector.
Trait Implementations§
Source§impl<T> FromIterator<T> for Ring<T>
impl<T> FromIterator<T> for Ring<T>
Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Auto Trait Implementations§
impl<T> Freeze for Ring<T>
impl<T> RefUnwindSafe for Ring<T>where
T: RefUnwindSafe,
impl<T> Send for Ring<T>where
T: Send,
impl<T> Sync for Ring<T>where
T: Sync,
impl<T> Unpin for Ring<T>where
T: Unpin,
impl<T> UnwindSafe for Ring<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more