Skip to content

Commit

Permalink
use u5 and u27 in public API
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Jun 19, 2024
1 parent bdb3b85 commit 8d21265
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 23 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.11.2"
version = "0.11.4"
edition = "2021"
rust-version = "1.56.0"
repository = "https://github.com/al8n/skl"
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ pub use options::{MmapOptions, OpenOptions};
mod types;
pub use types::*;

pub use rarena_allocator::{Arena, Error as ArenaError};

pub use either;
pub use map::{AllVersionsIter, SkipMap};

pub use rarena_allocator::{Arena, Error as ArenaError};
pub use ux2::{u27, u5};

const MAX_HEIGHT: usize = 32;
Expand Down
7 changes: 3 additions & 4 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl<T> NodePtr<T> {
///
/// - The caller must ensure that the node is allocated by the arena.
/// - The caller must ensure that the offset is less than the capacity of the arena and larger than 0.
unsafe fn cas_next_offset_weak(
unsafe fn cas_next_offset(
&self,
arena: &Arena,
idx: usize,
Expand All @@ -296,11 +296,10 @@ impl<T> NodePtr<T> {
success: Ordering,
failure: Ordering,
) -> Result<u32, u32> {
#[cfg(not(feature = "unaligned"))]
self
.tower(arena, idx)
.next_offset
.compare_exchange_weak(current, new, success, failure)
.compare_exchange(current, new, success, failure)
}
}

Expand Down Expand Up @@ -1864,7 +1863,7 @@ impl<T: Trailer, C: Comparator> SkipMap<T, C> {
}
}

match prev.cas_next_offset_weak(
match prev.cas_next_offset(
&self.arena,
i,
next.offset,
Expand Down
2 changes: 1 addition & 1 deletion src/map/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ux2::u27;

use super::*;

impl SkipMap {
impl<T> SkipMap<T> {
/// Create a new skipmap with default options.
///
/// **Note:** The capacity stands for how many memory allocated,
Expand Down
50 changes: 36 additions & 14 deletions src/map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::format;

use std::sync::Arc;

use rarena_allocator::Freelist;
#[cfg(feature = "std")]
use wg::WaitGroup;

Expand Down Expand Up @@ -180,12 +181,30 @@ fn full_in(l: impl FnOnce(usize) -> SkipMap) {

#[test]
fn test_full() {
run(|| full_in(|n| SkipMap::with_options(Options::new().with_capacity(n as u32)).unwrap()))
run(|| {
full_in(|n| {
SkipMap::with_options(
Options::new()
.with_capacity(n as u32)
.with_freelist(Freelist::None),
)
.unwrap()
})
})
}

#[test]
fn test_full_unify() {
run(|| full_in(|n| SkipMap::with_options(UNIFY_TEST_OPTIONS.with_capacity(n as u32)).unwrap()))
run(|| {
full_in(|n| {
SkipMap::with_options(
UNIFY_TEST_OPTIONS
.with_capacity(n as u32)
.with_freelist(Freelist::None),
)
.unwrap()
})
})
}

#[test]
Expand All @@ -202,7 +221,13 @@ fn test_full_map_mut() {
.read(true)
.write(true);
let map_options = MmapOptions::default();
SkipMap::map_mut(p, open_options, map_options).unwrap()
SkipMap::map_mut_with_options(
p,
Options::new().with_freelist(Freelist::None),
open_options,
map_options,
)
.unwrap()
});
})
}
Expand All @@ -213,7 +238,8 @@ fn test_full_map_anon() {
run(|| {
full_in(|n| {
let map_options = MmapOptions::default().len(n as u32);
SkipMap::map_anon(map_options).unwrap()
SkipMap::map_anon_with_options(Options::new().with_freelist(Freelist::None), map_options)
.unwrap()
});
})
}
Expand All @@ -224,7 +250,8 @@ fn test_full_map_anon_unify() {
run(|| {
full_in(|n| {
let map_options = MmapOptions::default().len(n as u32);
SkipMap::map_anon_with_options(TEST_OPTIONS, map_options).unwrap()
SkipMap::map_anon_with_options(Options::new().with_freelist(Freelist::None), map_options)
.unwrap()
});
})
}
Expand Down Expand Up @@ -2265,8 +2292,7 @@ fn test_reopen_mmap() {
let open_options = OpenOptions::default()
.create(Some(ARENA_SIZE as u32))
.read(true)
.write(true)
.lock_exclusive(true);
.write(true);
let map_options = MmapOptions::default();
let l = SkipMap::map_mut(&p, open_options, map_options).unwrap();
for i in 0..1000 {
Expand All @@ -2275,12 +2301,9 @@ fn test_reopen_mmap() {
l.flush().unwrap();
}

let open_options = OpenOptions::default()
.read(true)
.lock_shared(true)
.shrink_on_drop(true);
let open_options = OpenOptions::default().read(true).shrink_on_drop(true);
let map_options = MmapOptions::default();
let l = SkipMap::map(&p, open_options, map_options, 0).unwrap();
let l = SkipMap::<u64>::map(&p, open_options, map_options, 0).unwrap();
assert_eq!(1000, l.len());
for i in 0..1000 {
let k = key(i);
Expand All @@ -2305,8 +2328,7 @@ fn test_reopen_mmap2() {
let open_options = OpenOptions::default()
.create(Some(ARENA_SIZE as u32))
.read(true)
.write(true)
.lock_shared(true);
.write(true);
let map_options = MmapOptions::default();
let l = SkipMap::map_mut_with_comparator(&p, open_options, map_options, Ascend).unwrap();
let mut data = (0..1000).collect::<Vec<usize>>();
Expand Down

0 comments on commit 8d21265

Please sign in to comment.