Skip to content

Commit

Permalink
Clarify iter and range APIs for multiple version skipmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Dec 8, 2024
1 parent c979294 commit 66ead4a
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 117 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "skl"
version = "0.22.9"
version = "0.22.10"
edition = "2021"
rust-version = "1.81.0"
repository = "https://github.com/al8n/skl"
Expand Down
11 changes: 4 additions & 7 deletions src/dynamic/list/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ where
&self,
version: Version,
) -> Option<EntryRef<'_, MaybeTombstone, C, A, RC>> {
self.iter_with_tombstone(version).next()
self.iter_all(version).next()
}

/// Returns the last entry in the map.
pub fn last_with_tombstone(
&self,
version: Version,
) -> Option<EntryRef<'_, MaybeTombstone, C, A, RC>> {
self.iter_with_tombstone(version).last()
self.iter_all(version).last()
}

/// Returns the value associated with the given key, if it exists.
Expand Down Expand Up @@ -306,10 +306,7 @@ where

/// Returns a new iterator, this iterator will yield all versions for all entries in the map less or equal to the given version.
#[inline]
pub fn iter_with_tombstone(
&self,
version: Version,
) -> iterator::Iter<'_, MaybeTombstone, C, A, RC> {
pub fn iter_all(&self, version: Version) -> iterator::Iter<'_, MaybeTombstone, C, A, RC> {
iterator::Iter::new(version, self, true)
}

Expand All @@ -329,7 +326,7 @@ where

/// Returns a iterator that within the range, this iterator will yield all versions for all entries in the range less or equal to the given version.
#[inline]
pub fn range_with_tombstone<Q, R>(
pub fn range_all<Q, R>(
&self,
version: Version,
range: R,
Expand Down
22 changes: 8 additions & 14 deletions src/dynamic/multiple_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,7 @@ where
return None;
}

self
.as_ref()
.iter_with_tombstone(version)
.seek_upper_bound(upper)
self.as_ref().iter_all(version).seek_upper_bound(upper)
}

/// Returns an `EntryRef` pointing to the lowest element whose key is above the given bound.
Expand All @@ -597,10 +594,7 @@ where
return None;
}

self
.as_ref()
.iter_with_tombstone(version)
.seek_lower_bound(lower)
self.as_ref().iter_all(version).seek_lower_bound(lower)
}

/// Returns a new iterator, this iterator will yield the latest version of all entries in the map less or equal to the given version.
Expand All @@ -609,13 +603,13 @@ where
self.as_ref().iter(version)
}

/// Returns a new iterator, this iterator will yield all versions for all entries in the map less or equal to the given version.
/// Returns a new iterator, this iterator will yield all versions and tombstones for all entries in the map less or equal to the given version.
#[inline]
fn iter_with_tombstone(
fn iter_all(
&self,
version: Version,
) -> Iter<'_, MaybeTombstone, C, Self::Allocator, Self::RefCounter> {
self.as_ref().iter_with_tombstone(version)
self.as_ref().iter_all(version)
}

/// Returns a iterator that within the range, this iterator will yield the latest version of all entries in the range less or equal to the given version.
Expand All @@ -632,9 +626,9 @@ where
self.as_ref().range(version, range)
}

/// Returns a iterator that within the range, this iterator will yield all versions for all entries in the range less or equal to the given version.
/// Returns a iterator that within the range, this iterator will yield all versions and tombstones for all entries in the range less or equal to the given version.
#[inline]
fn range_with_tombstone<Q, R>(
fn range_all<Q, R>(
&self,
version: Version,
range: R,
Expand All @@ -643,7 +637,7 @@ where
Q: ?Sized + Borrow<[u8]>,
R: RangeBounds<Q>,
{
self.as_ref().range_with_tombstone(version, range)
self.as_ref().range_all(version, range)
}

/// Upserts a new key-value pair if it does not yet exist, if the key with the given version already exists, it will update the value.
Expand Down
8 changes: 4 additions & 4 deletions src/dynamic/unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ where
Q: ?Sized + Borrow<[u8]>,
C: BytesComparator,
{
self.as_ref().iter_with_tombstone(0).seek_upper_bound(upper)
self.as_ref().iter_all(0).seek_upper_bound(upper)
}

/// Returns an `EntryRef` pointing to the lowest element whose key is above the given bound.
Expand All @@ -492,7 +492,7 @@ where
Q: ?Sized + Borrow<[u8]>,
C: BytesComparator,
{
self.as_ref().iter_with_tombstone(0).seek_lower_bound(lower)
self.as_ref().iter_all(0).seek_lower_bound(lower)
}

/// Returns a new iterator, this iterator will yield only active entries of all entries in the map less or equal to the given version.
Expand All @@ -504,7 +504,7 @@ where
/// Returns a new iterator, this iterator will yield with tombstones for all entries in the map less or equal to the given version.
#[inline]
fn iter_with_tombstone(&self) -> Iter<'_, MaybeTombstone, C, Self::Allocator, Self::RefCounter> {
self.as_ref().iter_with_tombstone(0)
self.as_ref().iter_all(0)
}

/// Returns a iterator that within the range, this iterator will yield only active entries of all entries in the range less or equal to the given version.
Expand All @@ -527,7 +527,7 @@ where
Q: ?Sized + Borrow<[u8]>,
R: RangeBounds<Q>,
{
self.as_ref().range_with_tombstone(MIN_VERSION, range)
self.as_ref().range_all(MIN_VERSION, range)
}

/// Upserts a new key-value pair if it does not yet exist, if the key with the given version already exists, it will update the value.
Expand Down
21 changes: 6 additions & 15 deletions src/generic/list/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ where
where
C: TypeRefQueryComparator<'a, K, K::Ref<'a>>,
{
self.iter_with_tombstone(version).next()
self.iter_all(version).next()
}

/// Returns the last entry in the map.
Expand All @@ -219,7 +219,7 @@ where
where
C: TypeRefQueryComparator<'a, K, K::Ref<'a>>,
{
self.iter_with_tombstone(version).last()
self.iter_all(version).last()
}

/// Returns the value associated with the given key, if it exists.
Expand Down Expand Up @@ -357,10 +357,7 @@ where
Q: ?Sized,
C: TypeRefQueryComparator<'a, K, Q>,
{
self
.iter_with_tombstone(version)
.map()
.seek_upper_bound(upper)
self.iter_all(version).map().seek_upper_bound(upper)
}

/// Returns an `EntryRef` pointing to the lowest element whose key is above the given bound.
Expand All @@ -374,10 +371,7 @@ where
Q: ?Sized,
C: TypeRefQueryComparator<'a, K, Q>,
{
self
.iter_with_tombstone(version)
.map()
.seek_lower_bound(lower)
self.iter_all(version).map().seek_lower_bound(lower)
}

/// Returns a new iterator, this iterator will yield the latest version of all entries in the map less or equal to the given version.
Expand All @@ -388,10 +382,7 @@ where

/// Returns a new iterator, this iterator will yield all versions for all entries in the map less or equal to the given version.
#[inline]
pub fn iter_with_tombstone(
&self,
version: Version,
) -> iterator::Iter<'_, K, V, MaybeTombstone, C, A, RC>
pub fn iter_all(&self, version: Version) -> iterator::Iter<'_, K, V, MaybeTombstone, C, A, RC>
where {
iterator::Iter::new(version, self, true)
}
Expand All @@ -412,7 +403,7 @@ where {

/// Returns a iterator that within the range, this iterator will yield all versions for all entries in the range less or equal to the given version.
#[inline]
pub fn range_with_tombstone<Q, R>(
pub fn range_all<Q, R>(
&self,
version: Version,
range: R,
Expand Down
8 changes: 4 additions & 4 deletions src/generic/multiple_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,15 +650,15 @@ where

/// Returns a new iterator, this iterator will yield all versions for all entries in the map less or equal to the given version.
#[inline]
fn iter_with_tombstone(
fn iter_all(
&self,
version: Version,
) -> Iter<'_, K, V, MaybeTombstone, C, Self::Allocator, Self::RefCounter>
where
K: Type,
V: Type,
{
self.as_ref().iter_with_tombstone(version)
self.as_ref().iter_all(version)
}

/// Returns a iterator that within the range, this iterator will yield the latest version of all entries in the range less or equal to the given version.
Expand All @@ -679,7 +679,7 @@ where

/// Returns a iterator that within the range, this iterator will yield all versions for all entries in the range less or equal to the given version.
#[inline]
fn range_with_tombstone<Q, R>(
fn range_all<Q, R>(
&self,
version: Version,
range: R,
Expand All @@ -690,7 +690,7 @@ where
Q: ?Sized,
R: RangeBounds<Q>,
{
self.as_ref().range_with_tombstone(version, range)
self.as_ref().range_all(version, range)
}

/// Upserts a new key-value pair if it does not yet exist, if the key with the given version already exists, it will update the value.
Expand Down
4 changes: 2 additions & 2 deletions src/generic/unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ where
K: Type,
V: Type,
{
self.as_ref().iter_with_tombstone(0)
self.as_ref().iter_all(0)
}

/// Returns a iterator that within the range, this iterator will yield only active entries of all entries in the range less or equal to the given version.
Expand Down Expand Up @@ -588,7 +588,7 @@ where
Q: ?Sized,
R: RangeBounds<Q>,
{
self.as_ref().range_with_tombstone(MIN_VERSION, range)
self.as_ref().range_all(MIN_VERSION, range)
}

/// Upserts a new key-value pair if it does not yet exist, if the key with the given version already exists, it will update the value.
Expand Down
Loading

0 comments on commit 66ead4a

Please sign in to comment.