Skip to content

Commit

Permalink
0.22.0 (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Dec 1, 2024
1 parent 25b1a60 commit f45fee5
Show file tree
Hide file tree
Showing 29 changed files with 977 additions and 633 deletions.
2 changes: 1 addition & 1 deletion .clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.80.0"
msrv = "1.81.0"
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.22.0

- Improve the flexibility of generic version `SkipMap`

## 0.21.0

- Use state pattern for `EntryRef`
Expand Down
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "skl"
version = "0.21.2"
version = "0.22.2"
edition = "2021"
rust-version = "1.81.0"
repository = "https://github.com/al8n/skl"
Expand Down Expand Up @@ -51,7 +51,9 @@ getrandom = { version = "0.2", features = ["js"] }
among = { version = "0.1", default-features = false, features = ["either"] }
arbitrary-int = { version = "1.2", default-features = false }
bitflags = "2"
dbutils = { version = "0.11", default-features = false }
dbutils = { version = "0.12", default-features = false }
# dbutils = { version = "0.12", path = "../layer0/dbutils", default-features = false }

either = { version = "1", default-features = false }
memchr = { version = "2", default-features = false, optional = true }
rand = { version = "0.8", default-features = false, features = ["getrandom"] }
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@

```toml
[dependencies]
skl = "0.21"
skl = "0.22"
```

- Enable memory map backend

```toml
[dependencies]
skl = { version = "0.21", features = ["memmap"] }
skl = { version = "0.22", features = ["memmap"] }
```

## Features
Expand Down
15 changes: 12 additions & 3 deletions examples/multiple_maps.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use skl::{
generic::{
unique::{sync::SkipMap, Map},
Builder,
Builder, DefaultComparator,
},
Arena,
};
Expand All @@ -25,7 +25,11 @@ fn main() {
.with_capacity(1024 * 1024)
.map_mut::<SkipMap<[u8], [u8]>, _>("multiple_maps.wal")
.unwrap();
let l2 = SkipMap::<[u8], [u8]>::create_from_allocator(l.allocator().clone()).unwrap();
let l2 = SkipMap::<[u8], [u8]>::create_from_allocator(
l.allocator().clone(),
DefaultComparator::new(),
)
.unwrap();
let h2 = l2.header().copied().unwrap();

let t1 = std::thread::spawn(move || {
Expand Down Expand Up @@ -56,7 +60,12 @@ fn main() {
.with_capacity((1024 * 1024 * 2) as u32)
.map_mut::<SkipMap<[u8], [u8]>, _>("multiple_maps.wal")
.unwrap();
let l2 = SkipMap::<[u8], [u8]>::open_from_allocator(header, l.allocator().clone()).unwrap();
let l2 = SkipMap::<[u8], [u8]>::open_from_allocator(
header,
l.allocator().clone(),
DefaultComparator::new(),
)
.unwrap();
assert_eq!(500, l.len());
assert_eq!(500, l2.len());

Expand Down
5 changes: 4 additions & 1 deletion src/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ pub mod entry {
pub use super::list::EntryRef;
}

pub use dbutils::equivalentor::*;
pub use dbutils::equivalentor::{
Ascend, Descend, DynComparator, DynEquivalentor, DynRangeComparator, StaticComparator,
StaticEquivalentor, StaticRangeComparator,
};

/// Value that can be converted from a byte slice.
pub trait Value<'a>: sealed::Sealed<'a> {}
Expand Down
23 changes: 20 additions & 3 deletions src/dynamic/builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::mem;

use dbutils::equivalentor::{Ascend, Comparator};
use dbutils::equivalentor::{Ascend, DynComparator};

use crate::{
allocator::Sealed,
Expand Down Expand Up @@ -61,7 +61,7 @@ impl Builder {
/// ## Example
///
/// ```rust
/// use skl::dynamic::Builder;
/// use skl::dynamic::{Builder, Descend};
///
/// let builder = Builder::new();
/// ```
Expand All @@ -75,6 +75,23 @@ impl Builder {
}

impl<C> Builder<C> {
/// Create a new builder with the given options.
///
/// ## Example
///
/// ```rust
/// use skl::dynamic::{Builder, Descend};
///
/// let builder = Builder::with(Descend);
/// ```
#[inline]
pub const fn with(cmp: C) -> Self {
Self {
options: Options::new(),
cmp,
}
}

/// Get the options of the builder.
///
/// ## Example
Expand Down Expand Up @@ -143,7 +160,7 @@ impl<C> Builder<C> {
crate::__builder_opts!(dynamic::Builder);
}

impl<C: Comparator> Builder<C> {
impl<C: DynComparator<[u8], [u8]>> Builder<C> {
/// Create a new map which is backed by a `AlignedVec`.
///
/// **Note:** The capacity stands for how many memory allocated,
Expand Down
12 changes: 6 additions & 6 deletions src/dynamic/builder/memmap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::mem;

use dbutils::equivalentor::Comparator;
use dbutils::equivalentor::DynComparator;
use either::Either;

use super::Builder;
Expand All @@ -12,7 +12,7 @@ use crate::{
Arena,
};

impl<C: Comparator> Builder<C> {
impl<C: DynComparator<[u8], [u8]>> Builder<C> {
/// Create a new map which is backed by a anonymous memory map.
///
/// **What the difference between this method and [`Builder::alloc`]?**
Expand Down Expand Up @@ -59,7 +59,7 @@ impl<C: Comparator> Builder<C> {
/// Opens a read-only map which backed by file-backed memory map.
///
/// ## Safety
/// - The file must be created with the same [`Comparator`].
/// - The file must be created with the same [`DynComparator`].
/// - All file-backed memory map constructors are marked `unsafe` because of the potential for
/// *Undefined Behavior* (UB) using the map if the underlying file is subsequently modified, in or
/// out of process. Applications must consider the risk and take appropriate precautions when
Expand All @@ -82,7 +82,7 @@ impl<C: Comparator> Builder<C> {
/// Opens a read-only map which backed by file-backed memory map with a path builder.
///
/// ## Safety
/// - The file must be created with the same [`Comparator`].
/// - The file must be created with the same [`DynComparator`].
/// - All file-backed memory map constructors are marked `unsafe` because of the potential for
/// *Undefined Behavior* (UB) using the map if the underlying file is subsequently modified, in or
/// out of process. Applications must consider the risk and take appropriate precautions when
Expand Down Expand Up @@ -146,7 +146,7 @@ impl<C: Comparator> Builder<C> {
/// Creates a new map or reopens a map which backed by a file backed memory map.
///
/// ## Safety
/// - If you are reopening a file, then the file must be created with the same [`Comparator`].
/// - If you are reopening a file, then the file must be created with the same [`DynComparator`].
/// - All file-backed memory map constructors are marked `unsafe` because of the potential for
/// *Undefined Behavior* (UB) using the map if the underlying file is subsequently modified, in or
/// out of process. Applications must consider the risk and take appropriate precautions when
Expand All @@ -169,7 +169,7 @@ impl<C: Comparator> Builder<C> {
/// Creates a new map or reopens a map which backed by a file backed memory map with path builder.
///
/// # Safety
/// - If you are reopening a file, then the file must be created with the same [`Comparator`].
/// - If you are reopening a file, then the file must be created with the same [`DynComparator`].
/// - All file-backed memory map constructors are marked `unsafe` because of the potential for
/// *Undefined Behavior* (UB) using the map if the underlying file is subsequently modified, in or
/// out of process. Applications must consider the risk and take appropriate precautions when
Expand Down
6 changes: 3 additions & 3 deletions src/dynamic/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::{cmp, ptr::NonNull, sync::atomic::Ordering};
use among::Among;
use dbutils::{
buffer::VacantBuffer,
equivalentor::{Ascend, Comparator},
equivalentor::{Ascend, DynComparator},
};
use either::Either;
use rarena_allocator::Allocator as _;
Expand Down Expand Up @@ -312,7 +312,7 @@ where
impl<A, R, C> SkipList<A, R, C>
where
A: Allocator,
C: Comparator,
C: DynComparator<[u8], [u8]>,
R: RefCounter,
{
unsafe fn move_to_prev<'a, V>(
Expand Down Expand Up @@ -1241,7 +1241,7 @@ where
#[inline]
fn compare<C>(this: Either<&'a [u8], &'b [u8]>, other: &'a [u8], cmp: &C) -> cmp::Ordering
where
C: Comparator,
C: DynComparator<[u8], [u8]>,
{
match this {
Either::Left(key) | Either::Right(key) => cmp.compare(key, other),
Expand Down
4 changes: 2 additions & 2 deletions src/dynamic/list/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::{
ops::{Bound, RangeBounds},
};

use dbutils::{buffer::VacantBuffer, equivalentor::Comparator};
use dbutils::{buffer::VacantBuffer, equivalentor::DynComparator};
use rarena_allocator::Allocator as _;

use crate::{
Expand Down Expand Up @@ -155,7 +155,7 @@ where
impl<A, RC, C> SkipList<A, RC, C>
where
A: Allocator,
C: Comparator,
C: DynComparator<[u8], [u8]>,
RC: RefCounter,
{
/// Returns `true` if the key exists in the map.
Expand Down
4 changes: 2 additions & 2 deletions src/dynamic/list/api/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use super::{
use crate::KeyBuilder;
use among::Among;
use core::sync::atomic::Ordering;
use dbutils::{buffer::VacantBuffer, equivalentor::Comparator};
use dbutils::{buffer::VacantBuffer, equivalentor::DynComparator};
use either::Either;

impl<A, R, C> SkipList<A, R, C>
where
A: Allocator,
C: Comparator,
C: DynComparator<[u8], [u8]>,
R: RefCounter,
{
/// 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/dynamic/list/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
ref_counter::RefCounter,
Version,
};
use dbutils::equivalentor::Comparator;
use dbutils::equivalentor::DynComparator;

/// An entry reference of the `SkipMap`.
pub struct EntryRef<'a, V, C, A, R>
Expand Down Expand Up @@ -121,7 +121,7 @@ where

impl<'a, V, C, A, R> EntryRef<'a, V, C, A, R>
where
C: Comparator,
C: DynComparator<[u8], [u8]>,
A: Allocator,
R: RefCounter,
V: Value<'a> + 'a,
Expand Down
34 changes: 25 additions & 9 deletions src/dynamic/list/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::{
borrow::Borrow,
ops::{Bound, RangeBounds},
};
use dbutils::equivalentor::{Comparator, RangeComparator};
use dbutils::equivalentor::{DynComparator, DynRangeComparator};

/// 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.
Expand Down Expand Up @@ -145,7 +145,7 @@ where
impl<'a, V, A, RC, C, Q, R> Iter<'a, V, A, RC, C, Q, R>
where
A: Allocator,
C: Comparator,
C: DynComparator<[u8], [u8]>,
RC: RefCounter,
Q: ?Sized + Borrow<[u8]>,
R: RangeBounds<Q>,
Expand Down Expand Up @@ -373,7 +373,7 @@ where
impl<'a, V, A, RC, C, Q, R> Iter<'a, V, A, RC, C, Q, R>
where
A: Allocator,
C: Comparator,
C: DynComparator<[u8], [u8]>,
RC: RefCounter,
Q: ?Sized + Borrow<[u8]>,
R: RangeBounds<Q>,
Expand Down Expand Up @@ -592,7 +592,7 @@ where
impl<'a, V, A, RC, C, Q, R> Iterator for Iter<'a, V, A, RC, C, Q, R>
where
A: Allocator,
C: Comparator,
C: DynComparator<[u8], [u8]>,
RC: RefCounter,
Q: ?Sized + Borrow<[u8]>,
R: RangeBounds<Q>,
Expand Down Expand Up @@ -639,7 +639,7 @@ where
impl<'a, V, A, RC, C, Q, R> DoubleEndedIterator for Iter<'a, V, A, RC, C, Q, R>
where
A: Allocator,
C: Comparator,
C: DynComparator<[u8], [u8]>,
RC: RefCounter,
Q: ?Sized + Borrow<[u8]>,
R: RangeBounds<Q>,
Expand All @@ -656,7 +656,11 @@ where
}

/// Helper function to check if a value is above a lower bound
fn above_lower_bound_compare<C: Comparator>(cmp: &C, bound: Bound<&[u8]>, other: &[u8]) -> bool {
fn above_lower_bound_compare<C: DynComparator<[u8], [u8]>>(
cmp: &C,
bound: Bound<&[u8]>,
other: &[u8],
) -> bool {
match bound {
Bound::Unbounded => true,
Bound::Included(key) => cmp.compare(key, other).is_le(),
Expand All @@ -665,7 +669,11 @@ fn above_lower_bound_compare<C: Comparator>(cmp: &C, bound: Bound<&[u8]>, other:
}

/// Helper function to check if a value is above a lower bound
fn above_lower_bound<C: Comparator>(cmp: &C, bound: Bound<&[u8]>, other: &[u8]) -> bool {
fn above_lower_bound<C: DynComparator<[u8], [u8]>>(
cmp: &C,
bound: Bound<&[u8]>,
other: &[u8],
) -> bool {
match bound {
Bound::Unbounded => true,
Bound::Included(key) => cmp.compare(key, other).is_le(),
Expand All @@ -674,7 +682,11 @@ fn above_lower_bound<C: Comparator>(cmp: &C, bound: Bound<&[u8]>, other: &[u8])
}

/// Helper function to check if a value is below an upper bound
fn below_upper_bound_compare<C: Comparator>(cmp: &C, bound: Bound<&[u8]>, other: &[u8]) -> bool {
fn below_upper_bound_compare<C: DynComparator<[u8], [u8]>>(
cmp: &C,
bound: Bound<&[u8]>,
other: &[u8],
) -> bool {
match bound {
Bound::Unbounded => true,
Bound::Included(key) => cmp.compare(key, other).is_ge(),
Expand All @@ -683,7 +695,11 @@ fn below_upper_bound_compare<C: Comparator>(cmp: &C, bound: Bound<&[u8]>, other:
}

/// Helper function to check if a value is below an upper bound
fn below_upper_bound<C: Comparator>(cmp: &C, bound: Bound<&[u8]>, other: &[u8]) -> bool {
fn below_upper_bound<C: DynComparator<[u8], [u8]>>(
cmp: &C,
bound: Bound<&[u8]>,
other: &[u8],
) -> bool {
match bound {
Bound::Unbounded => true,
Bound::Included(key) => cmp.compare(key, other).is_ge(),
Expand Down
Loading

0 comments on commit f45fee5

Please sign in to comment.