Skip to content

Commit

Permalink
0.22.4 (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Dec 4, 2024
1 parent 51e57a7 commit ceab0ca
Show file tree
Hide file tree
Showing 27 changed files with 761 additions and 740 deletions.
30 changes: 15 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# CHANGELOG

## 0.22.0
## 0.22

- Improve the flexibility of generic version `SkipMap`

## 0.21.0
## 0.21

- Use state pattern for `EntryRef`

## 0.20.0
## 0.20

- Add dynamic `SkipMap`s
- Support create multiple `SkipMap`s on the same `Allocator`
- Improve docs on some constructor methods

## 0.19.0
## 0.19

- Cleanup structures and remove `Trailer`, `TrailedMap` and `FullMap`
- Add `version` guard for query APIs
Expand All @@ -23,35 +23,35 @@
- Add `data_offset` and `data_offset_unify` method for `Options`
- Renaming types

## 0.17.0
## 0.17

- Refactor to support generic key-value types
- Fix `DoubleEndIterator` implementation
- Lazy init the `V::Ref<'a>` and `K::Ref<'a>` in `EntryRef`

## 0.15.0
## 0.15

- Extract different kinds of `SkipMap` to traits to improve flexibility
- Implementing a builder pattern to construct `SkipMap`s
- Make the crate compatible with [Tree Borrows](https://www.ralfj.de/blog/2023/06/02/tree-borrows.html)

## 0.14.0
## 0.14

- Supports unsync version `SkipMap`s
- Fix: dealloc potential in-unsed memory chunk
- Add `CompressionPolicy` as a configuration
- Increase the discarded tracker when find new version of a key

## 0.13.0
## 0.13

- Remove `Comparator` generic on `Entry*`

## 0.12.0
## 0.12

- Bump `rarena-allocator`'s version
- Change value callback from `impl FnOnce + Copy` to `impl Fn`

## 0.11.0
## 0.11

- Refactor and extract lock-free ARENA allocator implementation to [`rarena-allocator`](https://github.com/al8n/rarena) crate.
- Add an ordered linked list to track segments.
Expand All @@ -62,7 +62,7 @@
- Support specify max key size and max value size
- Support set the max height

## 0.10.0
## 0.10

- Remove `SkipSet`
- Add `insert`, `insert_with`, `insert_with_value`, `get_or_insert`, `get_or_insert` and `get_or_insert_with_value` methods
Expand All @@ -73,7 +73,7 @@
- Add `tracing`
- Add `SkipMap::refs` API to allow users get how many references.

## 0.9.0
## 0.9

- Make file backed mmap `SkipMap` and `SkipSet` still can be reopened even last time the program was aborted.
- Remove checksum validation, users should take care of data integrity by themselves.
Expand Down Expand Up @@ -109,17 +109,17 @@

- Add `entry` method for `MapIterator` and `SetIterator` to support access the last yield entry of the iterator.

## 0.8.0
## 0.8

- Make `SkipMap::insert` and `SkipSet::insert` return the current value if the key and trailer already exist.
- Add the `SkipMap::insert_with` method to support inserting an vacant key first, then write the value in the closure semantic.

## 0.7.0
## 0.7

- Implement `Iterator` for `MapIterator` and `SetIterator`.
- Optimize `Arena::alloc` logic.

## 0.6.0
## 0.6

- Change mmap related API
- Support open exist `SkipMap` and `SkipSet` file in read only mode.
Expand Down
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.3"
version = "0.22.4"
edition = "2021"
rust-version = "1.81.0"
repository = "https://github.com/al8n/skl"
Expand Down
18 changes: 6 additions & 12 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, DefaultComparator,
Ascend, Builder,
},
Arena,
};
Expand All @@ -25,11 +25,8 @@ 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(),
DefaultComparator::new(),
)
.unwrap();
let l2 =
SkipMap::<[u8], [u8]>::create_from_allocator(l.allocator().clone(), Ascend::new()).unwrap();
let h2 = l2.header().copied().unwrap();

let t1 = std::thread::spawn(move || {
Expand Down Expand Up @@ -60,12 +57,9 @@ 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(),
DefaultComparator::new(),
)
.unwrap();
let l2 =
SkipMap::<[u8], [u8]>::open_from_allocator(header, l.allocator().clone(), Ascend::new())
.unwrap();
assert_eq!(500, l.len());
assert_eq!(500, l2.len());

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

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

/// Ascend is a comparator that compares byte slices in ascending order.
pub type Ascend = dbutils::equivalentor::Ascend<[u8]>;

/// Ascend is a comparator that compares byte slices in ascending order.
pub type Descend = dbutils::equivalentor::Descend<[u8]>;

/// Value that can be converted from a byte slice.
pub trait Value<'a>: sealed::Sealed<'a> {}
Expand Down
14 changes: 7 additions & 7 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, DynComparator};
use dbutils::equivalentor::{Ascend, BytesComparator};

use crate::{
allocator::Sealed,
Expand All @@ -17,7 +17,7 @@ mod memmap;

/// A builder for creating a dynamic key-value `SkipMap`.
#[derive(Debug, Clone)]
pub struct Builder<C = Ascend> {
pub struct Builder<C = Ascend<[u8]>> {
options: Options,
cmp: C,
}
Expand Down Expand Up @@ -69,7 +69,7 @@ impl Builder {
pub const fn new() -> Self {
Self {
options: Options::new(),
cmp: Ascend,
cmp: Ascend::new(),
}
}
}
Expand All @@ -82,7 +82,7 @@ impl<C> Builder<C> {
/// ```rust
/// use skl::dynamic::{Builder, Descend};
///
/// let builder = Builder::with(Descend);
/// let builder = Builder::with(Descend::new());
/// ```
#[inline]
pub const fn with(cmp: C) -> Self {
Expand Down Expand Up @@ -145,9 +145,9 @@ impl<C> Builder<C> {
/// ```rust
/// use skl::dynamic::{Builder, Descend};
///
/// let builder = Builder::new().with_comparator(Descend);
/// let builder = Builder::new().with_comparator(Descend::new());
///
/// assert_eq!(builder.comparator(), &Descend);
/// assert_eq!(builder.comparator(), &Descend::new());
/// ```
#[inline]
pub fn with_comparator<NC>(self, cmp: NC) -> Builder<NC> {
Expand All @@ -160,7 +160,7 @@ impl<C> Builder<C> {
crate::__builder_opts!(dynamic::Builder);
}

impl<C: DynComparator<[u8], [u8]>> Builder<C> {
impl<C: BytesComparator> 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::DynComparator;
use dbutils::equivalentor::BytesComparator;
use either::Either;

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

impl<C: DynComparator<[u8], [u8]>> Builder<C> {
impl<C: BytesComparator> 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: DynComparator<[u8], [u8]>> Builder<C> {
/// Opens a read-only map which backed by file-backed memory map.
///
/// ## Safety
/// - The file must be created with the same [`DynComparator`].
/// - The file must be created with the same [`BytesComparator`].
/// - 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: DynComparator<[u8], [u8]>> 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 [`DynComparator`].
/// - The file must be created with the same [`BytesComparator`].
/// - 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: DynComparator<[u8], [u8]>> 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 [`DynComparator`].
/// - If you are reopening a file, then the file must be created with the same [`BytesComparator`].
/// - 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: DynComparator<[u8], [u8]>> 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 [`DynComparator`].
/// - If you are reopening a file, then the file must be created with the same [`BytesComparator`].
/// - 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
8 changes: 4 additions & 4 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, DynComparator},
equivalentor::{Ascend, BytesComparator},
};
use either::Either;
use rarena_allocator::Allocator as _;
Expand Down Expand Up @@ -36,7 +36,7 @@ type UpdateOk<'a, 'b, A, RC, C> = Either<
/// 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<A, R, C = Ascend<[u8]>>
where
A: Allocator,
R: RefCounter,
Expand Down Expand Up @@ -312,7 +312,7 @@ where
impl<A, R, C> SkipList<A, R, C>
where
A: Allocator,
C: DynComparator<[u8], [u8]>,
C: BytesComparator,
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: DynComparator<[u8], [u8]>,
C: BytesComparator,
{
match this {
Either::Left(key) | Either::Right(key) => cmp.compare(key, other),
Expand Down
10 changes: 8 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::DynComparator};
use dbutils::{buffer::VacantBuffer, equivalentor::BytesComparator};
use rarena_allocator::Allocator as _;

use crate::{
Expand Down Expand Up @@ -155,8 +155,8 @@ where
impl<A, RC, C> SkipList<A, RC, C>
where
A: Allocator,
C: DynComparator<[u8], [u8]>,
RC: RefCounter,
C: BytesComparator,
{
/// Returns `true` if the key exists in the map.
///
Expand Down Expand Up @@ -285,7 +285,13 @@ where
) -> Option<EntryRef<'_, &[u8], C, A, RC>> {
self.iter(version).seek_lower_bound(lower)
}
}

impl<A, RC, C> SkipList<A, RC, C>
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<'_, &[u8], A, RC, C> {
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::DynComparator};
use dbutils::{buffer::VacantBuffer, equivalentor::BytesComparator};
use either::Either;

impl<A, R, C> SkipList<A, R, C>
where
A: Allocator,
C: DynComparator<[u8], [u8]>,
C: BytesComparator,
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::DynComparator;
use dbutils::equivalentor::BytesComparator;

/// 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: DynComparator<[u8], [u8]>,
C: BytesComparator,
A: Allocator,
R: RefCounter,
V: Value<'a> + 'a,
Expand Down
Loading

0 comments on commit ceab0ca

Please sign in to comment.