Skip to content

Commit

Permalink
Add missing methods for unique::SkipMaps
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Dec 8, 2024
1 parent 23c4cbf commit c979294
Show file tree
Hide file tree
Showing 15 changed files with 551 additions and 258 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.8"
version = "0.22.9"
edition = "2021"
rust-version = "1.81.0"
repository = "https://github.com/al8n/skl"
Expand Down
31 changes: 14 additions & 17 deletions src/dynamic/list.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use core::{cmp, ptr::NonNull, sync::atomic::Ordering};

use among::Among;
use dbutils::{
buffer::VacantBuffer,
equivalentor::{Ascend, BytesComparator},
};
use dbutils::{buffer::VacantBuffer, equivalentor::BytesComparator};
use either::Either;
use rarena_allocator::Allocator as _;

Expand All @@ -27,15 +24,15 @@ pub use entry::EntryRef;
mod api;
pub(super) mod iterator;

type UpdateOk<'a, 'b, A, RC, C> = Either<
type UpdateOk<'a, 'b, C, A, RC> = Either<
Option<EntryRef<'a, MaybeTombstone, C, A, RC>>,
Result<EntryRef<'a, MaybeTombstone, C, A, RC>, EntryRef<'a, MaybeTombstone, C, A, RC>>,
>;

/// A fast, cocnurrent map implementation based on skiplist that supports forward
/// and backward iteration.
#[derive(Debug)]
pub struct SkipList<A, R, C = Ascend>
pub struct SkipList<C, A, R>
where
A: Allocator,
R: RefCounter,
Expand All @@ -55,23 +52,23 @@ where
cmp: C,
}

unsafe impl<A, R, C> Send for SkipList<A, R, C>
unsafe impl<C, A, R> Send for SkipList<C, A, R>
where
C: Send,
A: Allocator + Send,
R: RefCounter + Send,
{
}

unsafe impl<A, R, C> Sync for SkipList<A, R, C>
unsafe impl<C, A, R> Sync for SkipList<C, A, R>
where
C: Sync,
A: Allocator + Sync,
R: RefCounter + Sync,
{
}

impl<A, R, C> Clone for SkipList<A, R, C>
impl<C, A, R> Clone for SkipList<C, A, R>
where
C: Clone,
A: Allocator,
Expand All @@ -93,7 +90,7 @@ where
}
}

impl<A, R, C> SkipList<A, R, C>
impl<C, A, R> SkipList<C, A, R>
where
A: Allocator,
R: RefCounter,
Expand All @@ -104,7 +101,7 @@ where
}
}

impl<A, R, C> Constructable for SkipList<A, R, C>
impl<C, A, R> Constructable for SkipList<C, A, R>
where
A: Allocator,
R: RefCounter,
Expand Down Expand Up @@ -171,7 +168,7 @@ where
}
}

impl<A, R, C> SkipList<A, R, C>
impl<C, A, R> SkipList<C, A, R>
where
A: Allocator,
R: RefCounter,
Expand Down Expand Up @@ -256,7 +253,7 @@ where
}
}

impl<A, R, C> SkipList<A, R, C>
impl<C, A, R> SkipList<C, A, R>
where
A: Allocator,
R: RefCounter,
Expand Down Expand Up @@ -308,7 +305,7 @@ where
}
}

impl<A, R, C> SkipList<A, R, C>
impl<C, A, R> SkipList<C, A, R>
where
A: Allocator,
C: BytesComparator,
Expand Down Expand Up @@ -855,7 +852,7 @@ where
failure: Ordering,
mut ins: Inserter<'a, <A::Node as Node>::Pointer>,
upsert: bool,
) -> Result<UpdateOk<'a, 'b, A, R, C>, Either<E, Error>> {
) -> Result<UpdateOk<'a, 'b, C, A, R>, Either<E, Error>> {
let is_remove = key.is_remove();

// Safety: a fresh new Inserter, so safe here
Expand Down Expand Up @@ -1128,7 +1125,7 @@ where
value_size: u32,
success: Ordering,
failure: Ordering,
) -> Result<UpdateOk<'a, 'b, A, R, C>, Error> {
) -> Result<UpdateOk<'a, 'b, C, A, R>, Error> {
match key {
Key::Occupied(_) | Key::Vacant { .. } | Key::Pointer { .. } => {
old_node.update_value(&self.arena, value_offset, value_size);
Expand Down Expand Up @@ -1168,7 +1165,7 @@ where
value_builder: Option<ValueBuilder<impl FnOnce(&mut VacantBuffer<'a>) -> Result<usize, E>>>,
success: Ordering,
failure: Ordering,
) -> Result<UpdateOk<'a, 'b, A, R, C>, Either<E, Error>> {
) -> Result<UpdateOk<'a, 'b, C, A, R>, Either<E, Error>> {
match key {
Key::Occupied(_) | Key::Vacant { .. } | Key::Pointer { .. } => self
.arena
Expand Down
14 changes: 7 additions & 7 deletions src/dynamic/list/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod update;
type RemoveValueBuilder<E> =
ValueBuilder<std::boxed::Box<dyn Fn(&mut VacantBuffer<'_>) -> Result<usize, E>>>;

impl<A, R, C> SkipList<A, R, C>
impl<C, A, R> SkipList<C, A, R>
where
A: Allocator,
R: RefCounter,
Expand Down Expand Up @@ -152,7 +152,7 @@ where
}
}

impl<A, RC, C> SkipList<A, RC, C>
impl<C, A, RC> SkipList<C, A, RC>
where
A: Allocator,
RC: RefCounter,
Expand Down Expand Up @@ -293,14 +293,14 @@ where
}
}

impl<A, RC, C> SkipList<A, RC, C>
impl<C, A, RC> SkipList<C, A, RC>
where
A: Allocator,
RC: RefCounter,
{
/// Returns a new iterator, this iterator will yield the latest version of all entries in the map less or equal to the given version.
#[inline]
pub fn iter(&self, version: Version) -> iterator::Iter<'_, Active, A, RC, C> {
pub fn iter(&self, version: Version) -> iterator::Iter<'_, Active, C, A, RC> {
iterator::Iter::new(version, self, false)
}

Expand All @@ -309,7 +309,7 @@ where
pub fn iter_with_tombstone(
&self,
version: Version,
) -> iterator::Iter<'_, MaybeTombstone, A, RC, C> {
) -> iterator::Iter<'_, MaybeTombstone, C, A, RC> {
iterator::Iter::new(version, self, true)
}

Expand All @@ -319,7 +319,7 @@ where
&self,
version: Version,
range: R,
) -> iterator::Iter<'_, Active, A, RC, C, Q, R>
) -> iterator::Iter<'_, Active, C, A, RC, Q, R>
where
Q: ?Sized + Borrow<[u8]>,
R: RangeBounds<Q>,
Expand All @@ -333,7 +333,7 @@ where
&self,
version: Version,
range: R,
) -> iterator::Iter<'_, MaybeTombstone, A, RC, C, Q, R>
) -> iterator::Iter<'_, MaybeTombstone, C, A, RC, Q, R>
where
Q: ?Sized + Borrow<[u8]>,
R: RangeBounds<Q>,
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic/list/api/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use core::sync::atomic::Ordering;
use dbutils::{buffer::VacantBuffer, equivalentor::BytesComparator};
use either::Either;

impl<A, R, C> SkipList<A, R, C>
impl<C, A, R> SkipList<C, A, R>
where
A: Allocator,
C: BytesComparator,
Expand Down
8 changes: 4 additions & 4 deletions src/dynamic/list/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ where
R: RefCounter,
S: State<'a>,
{
pub(super) list: &'a SkipList<A, R, C>,
pub(super) list: &'a SkipList<C, A, R>,
pub(super) key: &'a [u8],
pub(super) value: S::BytesValue,
pub(super) version: Version,
Expand Down Expand Up @@ -57,7 +57,7 @@ where
{
}

impl<'a, A, R, C> EntryRef<'a, MaybeTombstone, C, A, R>
impl<'a, C, A, R> EntryRef<'a, MaybeTombstone, C, A, R>
where
A: Allocator,
R: RefCounter,
Expand Down Expand Up @@ -188,7 +188,7 @@ where
pub(crate) fn from_node(
query_version: Version,
node: <A::Node as Node>::Pointer,
list: &'a SkipList<A, R, C>,
list: &'a SkipList<C, A, R>,
key: Option<&'a [u8]>,
value: S::BytesValue,
) -> Self {
Expand All @@ -213,7 +213,7 @@ where
pub(crate) fn from_node_with_pointer(
query_version: Version,
node: <A::Node as Node>::Pointer,
list: &'a SkipList<A, R, C>,
list: &'a SkipList<C, A, R>,
key: Option<&'a [u8]>,
value: S::BytesValue,
) -> Self {
Expand Down
26 changes: 13 additions & 13 deletions src/dynamic/list/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use dbutils::equivalentor::{BytesComparator, BytesRangeComparator};

/// An iterator over the skipmap (this iterator will yields all versions). The current state of the iterator can be cloned by
/// simply value copying the struct.
pub struct Iter<'a, S, A, RC, C, Q = [u8], R = core::ops::RangeFull>
pub struct Iter<'a, S, C, A, RC, Q = [u8], R = core::ops::RangeFull>
where
A: Allocator,
RC: RefCounter,
Q: ?Sized,
S: State<'a>,
{
pub(super) map: &'a SkipList<A, RC, C>,
pub(super) map: &'a SkipList<C, A, RC>,
pub(super) version: Version,
pub(super) range: Option<R>,
pub(super) all_versions: bool,
Expand All @@ -24,7 +24,7 @@ where
pub(super) _phantom: core::marker::PhantomData<Q>,
}

impl<'a, S, A, RC, C, Q, R> Clone for Iter<'a, S, A, RC, C, Q, R>
impl<'a, S, C, A, RC, Q, R> Clone for Iter<'a, S, C, A, RC, Q, R>
where
A: Allocator,
RC: RefCounter,
Expand All @@ -45,7 +45,7 @@ where
}
}

impl<'a, S, A, RC, C, Q, R> Copy for Iter<'a, S, A, RC, C, Q, R>
impl<'a, S, C, A, RC, Q, R> Copy for Iter<'a, S, C, A, RC, Q, R>
where
A: Allocator,
RC: RefCounter,
Expand All @@ -55,7 +55,7 @@ where
{
}

impl<'a, S, A, RC, C> Iter<'a, S, A, RC, C>
impl<'a, S, C, A, RC> Iter<'a, S, C, A, RC>
where
A: Allocator,
RC: RefCounter,
Expand All @@ -64,7 +64,7 @@ where
#[inline]
pub(crate) const fn new(
version: Version,
map: &'a SkipList<A, RC, C>,
map: &'a SkipList<C, A, RC>,
all_versions: bool,
) -> Self {
Self {
Expand All @@ -79,7 +79,7 @@ where
}
}

impl<'a, S, A, RC, C, Q, R> Iter<'a, S, A, RC, C, Q, R>
impl<'a, S, C, A, RC, Q, R> Iter<'a, S, C, A, RC, Q, R>
where
A: Allocator,
RC: RefCounter,
Expand All @@ -89,7 +89,7 @@ where
#[inline]
pub(crate) fn range(
version: Version,
map: &'a SkipList<A, RC, C>,
map: &'a SkipList<C, A, RC>,
r: R,
all_versions: bool,
) -> Self {
Expand All @@ -105,7 +105,7 @@ where
}
}

impl<'a, S, A, RC, C, Q, R> Iter<'a, S, A, RC, C, Q, R>
impl<'a, S, C, A, RC, Q, R> Iter<'a, S, C, A, RC, Q, R>
where
A: Allocator,
RC: RefCounter,
Expand Down Expand Up @@ -146,7 +146,7 @@ where
}
}

impl<'a, S, A, RC, C, Q, R> Iter<'a, S, A, RC, C, Q, R>
impl<'a, S, C, A, RC, Q, R> Iter<'a, S, C, A, RC, Q, R>
where
A: Allocator,
C: BytesComparator,
Expand Down Expand Up @@ -374,7 +374,7 @@ where
}
}

impl<'a, S, A, RC, C, Q, R> Iter<'a, S, A, RC, C, Q, R>
impl<'a, S, C, A, RC, Q, R> Iter<'a, S, C, A, RC, Q, R>
where
A: Allocator,
C: BytesComparator,
Expand Down Expand Up @@ -593,7 +593,7 @@ where
}
}

impl<'a, S, A, RC, C, Q, R> Iterator for Iter<'a, S, A, RC, C, Q, R>
impl<'a, S, C, A, RC, Q, R> Iterator for Iter<'a, S, C, A, RC, Q, R>
where
A: Allocator,
C: BytesComparator,
Expand Down Expand Up @@ -640,7 +640,7 @@ where
}
}

impl<'a, S, A, RC, C, Q, R> DoubleEndedIterator for Iter<'a, S, A, RC, C, Q, R>
impl<'a, S, C, A, RC, Q, R> DoubleEndedIterator for Iter<'a, S, C, A, RC, Q, R>
where
A: Allocator,
C: BytesComparator,
Expand Down
Loading

0 comments on commit c979294

Please sign in to comment.