Skip to content

Add range methods to RingMap and RingSet#23

Merged
cuviper merged 1 commit intoindexmap-rs:mainfrom
cuviper:range
Jan 8, 2026
Merged

Add range methods to RingMap and RingSet#23
cuviper merged 1 commit intoindexmap-rs:mainfrom
cuviper:range

Conversation

@cuviper
Copy link
Member

@cuviper cuviper commented Jan 8, 2026

impl<K, V, S> RingMap<K, V, S> {
    pub fn range<R>(&self, range: R) -> Iter<'_, K, V>;
    pub fn range_mut<R>(&mut self, range: R) -> IterMut<'_, K, V>;

    pub fn get_range<R>(&self, range: R) -> Option<(&Slice<K, V>, &Slice<K, V>)>;
    pub fn get_range_mut<R>(&mut self, range: R) -> Option<(&mut Slice<K, V>, &mut Slice<K, V>)>;
}

impl<T, S> RingSet<T, S> {
    pub fn range<R>(&self, range: R) -> Iter<'_, T>;
    pub fn get_range<R>(&self, range: R) -> Option<(&Slice<T>, &Slice<T>)>;
}

All of these are bounded where R: RangeBounds<usize> too.

Note that the get_range and get_range_mut methods are similar to indexmap, as well as our existing Slice methods, except here we need to return a pair of slices.

The range and range_mut methods are more like those on VecDeque, where you don't have to worry about the head+tail pair yourself.

```
impl<K, V, S> RingMap<K, V, S> {
    pub fn range<R>(&self, range: R) -> Iter<'_, K, V>;
    pub fn range_mut<R>(&mut self, range: R) -> IterMut<'_, K, V>;

    pub fn get_range<R>(&self, range: R) -> Option<(&Slice<K, V>, &Slice<K, V>)>;
    pub fn get_range_mut<R>(&mut self, range: R) -> Option<(&mut Slice<K, V>, &mut Slice<K, V>)>;
}

impl<T, S> RingSet<T, S> {
    pub fn range<R>(&self, range: R) -> Iter<'_, T>;
    pub fn get_range<R>(&self, range: R) -> Option<(&Slice<T>, &Slice<T>)>;
}
```

All of these are bounded `where R: RangeBounds<usize>` too.

Note that the `get_range` and `get_range_mut` methods are similar to
`indexmap`, as well as our existing `Slice` methods, except here we
need to return a pair of slices.

The `range` and `range_mut` methods are more like those on `VecDeque`,
where you don't have to worry about the head+tail pair yourself.
@cuviper cuviper added this pull request to the merge queue Jan 8, 2026
Merged via the queue into indexmap-rs:main with commit ae5792e Jan 8, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant