diff --git a/CHANGELOG.md b/CHANGELOG.md index de2b3eff..0bf24695 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## 0.12.0 + +- Bump `rarena-allocator`'s version +- Change value callback from `impl FnOnce + Copy` to `impl Fn` + ## 0.11.0 - Refactor and extract lock-free ARENA allocator implementation to [`rarena-allocator`](https://github.com/al8n/rarena) crate. diff --git a/Cargo.toml b/Cargo.toml index fa55e65d..978cc8fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "skl" -version = "0.11.4" +version = "0.12.0" edition = "2021" rust-version = "1.56.0" repository = "https://github.com/al8n/skl" diff --git a/src/map.rs b/src/map.rs index adc9e6b3..c1af1a5f 100644 --- a/src/map.rs +++ b/src/map.rs @@ -400,7 +400,7 @@ impl Node { arena: &'a Arena, trailer: T, value_size: u32, - f: impl FnOnce(&mut VacantBuffer<'a>) -> Result<(), E>, + f: &impl Fn(&mut VacantBuffer<'a>) -> Result<(), E>, ) -> Result<(), Either> { let mut bytes = arena .alloc_aligned_bytes::(value_size) @@ -1151,7 +1151,7 @@ impl SkipMap { key: &Key<'a, 'b>, trailer: T, value_size: u32, - f: impl FnOnce(&mut VacantBuffer<'a>) -> Result<(), E>, + f: &impl Fn(&mut VacantBuffer<'a>) -> Result<(), E>, ) -> Result<(NodePtr, u32, Deallocator), Either> { let height = super::random_height(self.opts.max_height().into()); let (nd, deallocator) = match key { @@ -1732,7 +1732,7 @@ impl SkipMap { trailer: T, key: Key<'a, 'b>, value_size: u32, - f: impl FnOnce(&mut VacantBuffer<'a>) -> Result<(), E> + Copy, + f: impl Fn(&mut VacantBuffer<'a>) -> Result<(), E>, success: Ordering, failure: Ordering, ins: &mut Inserter, @@ -1751,7 +1751,7 @@ impl SkipMap { if upsert { return self.upsert( - old, node_ptr, &key, trailer, value_size, f, success, failure, + old, node_ptr, &key, trailer, value_size, &f, success, failure, ); } @@ -1792,10 +1792,11 @@ impl SkipMap { } }; - let (nd, height, mut deallocator) = self.new_node(&k, trailer, value_size, f).map_err(|e| { - k.on_fail(&self.arena); - e - })?; + let (nd, height, mut deallocator) = + self.new_node(&k, trailer, value_size, &f).map_err(|e| { + k.on_fail(&self.arena); + e + })?; // We always insert from the base level and up. After you add a node in base // level, we cannot create a node in the level above because it would have @@ -1913,7 +1914,7 @@ impl SkipMap { if upsert { deallocator.dealloc(&self.arena); - return self.upsert(old, node_ptr, &k, trailer, value_size, f, success, failure); + return self.upsert(old, node_ptr, &k, trailer, value_size, &f, success, failure); } deallocator.dealloc(&self.arena); @@ -1973,7 +1974,7 @@ impl SkipMap { key: &Key<'a, 'b>, trailer: T, value_size: u32, - f: impl FnOnce(&mut VacantBuffer<'a>) -> Result<(), E>, + f: &impl Fn(&mut VacantBuffer<'a>) -> Result<(), E>, success: Ordering, failure: Ordering, ) -> Result, Either> { diff --git a/src/map/api.rs b/src/map/api.rs index 43a18551..6a67efe4 100644 --- a/src/map/api.rs +++ b/src/map/api.rs @@ -536,7 +536,7 @@ impl SkipMap { trailer: T, key: &'b [u8], value_size: u32, - f: impl FnOnce(&mut VacantBuffer<'a>) -> Result<(), E> + Copy, + f: impl Fn(&mut VacantBuffer<'a>) -> Result<(), E>, ) -> Result>, Either> { if self.arena.read_only() { return Err(Either::Right(Error::read_only())); @@ -660,7 +660,7 @@ impl SkipMap { trailer: T, key: &'b [u8], value_size: u32, - f: impl FnOnce(&mut VacantBuffer<'a>) -> Result<(), E> + Copy, + f: impl Fn(&mut VacantBuffer<'a>) -> Result<(), E>, ) -> Result>, Either> { if self.arena.read_only() { return Err(Either::Right(Error::read_only())); @@ -742,7 +742,7 @@ impl SkipMap { key_size: u27, key: impl FnOnce(&mut VacantBuffer<'a>) -> Result<(), E>, val_size: u32, - val: impl FnOnce(&mut VacantBuffer<'a>) -> Result<(), E> + Copy, + val: impl Fn(&mut VacantBuffer<'a>) -> Result<(), E>, ) -> Result>, Either> { let vk = self.fetch_vacant_key(u32::from(key_size), key)?; @@ -820,7 +820,7 @@ impl SkipMap { key_size: u27, key: impl FnOnce(&mut VacantBuffer<'a>) -> Result<(), E>, val_size: u32, - val: impl FnOnce(&mut VacantBuffer<'a>) -> Result<(), E> + Copy, + val: impl Fn(&mut VacantBuffer<'a>) -> Result<(), E>, ) -> Result>, Either> { let vk = self.fetch_vacant_key(u32::from(key_size), key)?; diff --git a/src/map/tests.rs b/src/map/tests.rs index 1d317fc0..f4a083bf 100644 --- a/src/map/tests.rs +++ b/src/map/tests.rs @@ -154,7 +154,6 @@ fn full_in(l: impl FnOnce(usize) -> SkipMap) { let l = l(1000); let mut found_arena_full = false; - let mut full_at = 0; for i in 0..100 { if let Err(e) = l.get_or_insert(0, &make_int_key(i), &make_value(i)) { assert!(matches!( @@ -162,21 +161,11 @@ fn full_in(l: impl FnOnce(usize) -> SkipMap) { Error::Arena(ArenaError::InsufficientSpace { .. }) )); found_arena_full = true; - full_at = i; break; } } assert!(found_arena_full); - - let e = l - .get_or_insert(0, &make_int_key(full_at + 1), &make_value(full_at + 1)) - .unwrap_err(); - - assert!(matches!( - e, - Error::Arena(ArenaError::InsufficientSpace { .. }) - )); } #[test] @@ -1502,8 +1491,7 @@ fn test_concurrent_one_key_map_mut() { let open_options = OpenOptions::default() .create(Some(ARENA_SIZE as u32)) .read(true) - .write(true) - .shrink_on_drop(true); + .write(true); let map_options = MmapOptions::default(); concurrent_one_key(Arc::new( SkipMap::map_mut(p, open_options, map_options) @@ -2301,7 +2289,7 @@ fn test_reopen_mmap() { l.flush().unwrap(); } - let open_options = OpenOptions::default().read(true).shrink_on_drop(true); + let open_options = OpenOptions::default().read(true); let map_options = MmapOptions::default(); let l = SkipMap::::map(&p, open_options, map_options, 0).unwrap(); assert_eq!(1000, l.len());