Skip to content

Commit

Permalink
make <Type>::new() lazyable
Browse files Browse the repository at this point in the history
  • Loading branch information
haxjump committed Oct 12, 2024
1 parent bf0d621 commit 541e119
Show file tree
Hide file tree
Showing 21 changed files with 147 additions and 372 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# CHANGE LOG

## v1.0.x
## v3.x.x

Simplify functions and release v1.0.0
- Make `<Type>::new()` lazyable
- 'Copy On Write' style
- Set `paritydb` as the default backend to save compilation time

## v1.x.x

- Simplify functions and release v1.0.0

## v0.70.x

Backport the changes of the `mmdb` crate.
- Backport the changes of the `mmdb` crate.

## v0.61.x

Expand Down
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ members = [
resolver = "2"

[workspace.dependencies]
ruc = "7.0.1"
ruc = "7.5.1"
rand = "0.8.5"
parking_lot = "0.12.1"

Expand All @@ -20,16 +20,16 @@ parity-scale-codec = "3.6.12"

threadpool = "1.8.1" # used in a background cleaner

parity-db = "0.4.13"
parity-db = "0.5.0"
rocksdb = { version = "0.22.0", default-features = false }

keccak-hasher = "0.16.0"
hash-db = "0.16.0"
trie-db = "0.29.1"
trie-root = "0.18.0"

vsdb = { path = "wrappers", version = "2.0", default-features = false }
vsdb_core = { path = "core", version = "2.0", default-features = false }
vsdb = { path = "wrappers", version = "3.0", default-features = false }
vsdb_core = { path = "core", version = "3.0", default-features = false }

vsdb_trie_db = { path = "utils/trie_db", version = "2.0", default-features = false }
vsdb_hash_db = { path = "utils/hash_db", version = "2.0", default-features = false }
vsdb_trie_db = { path = "utils/trie_db", version = "3.0", default-features = false }
vsdb_hash_db = { path = "utils/hash_db", version = "3.0", default-features = false }
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ lint:
cargo check --workspace --benches

lintall: lint
cargo clippy --workspace --no-default-features --features "parity_backend,compress,msgpack_codec"
cargo check --workspace --tests --no-default-features --features "parity_backend,json_codec"
cargo clippy --workspace --no-default-features --features "rocks_backend,compress,msgpack_codec"
cargo check --workspace --tests --no-default-features --features "rocks_backend,json_codec"

lintmusl:
cargo clippy --workspace --target x86_64-unknown-linux-musl \
Expand All @@ -26,7 +26,7 @@ testall: test
- rm -rf ~/.vsdb /tmp/.vsdb /tmp/vsdb_testing $(VSDB_BASE_DIR)
cargo test --workspace --tests \
--no-default-features \
--features "parity_backend,msgpack_codec" \
--features "rocks_backend,msgpack_codec" \
-- --test-threads=1 #--nocapture

testmusl:
Expand All @@ -38,13 +38,13 @@ testmusl:

bench:
- rm -rf ~/.vsdb /tmp/.vsdb /tmp/vsdb_testing $(VSDB_BASE_DIR)
cargo bench --workspace --no-default-features --features "parity_backend,msgpack_codec"
cargo bench --workspace --no-default-features --features "rocks_backend,msgpack_codec"
du -sh ~/.vsdb
- rm -rf ~/.vsdb /tmp/.vsdb /tmp/vsdb_testing $(VSDB_BASE_DIR)
cargo bench --workspace --no-default-features --features "parity_backend,compress,msgpack_codec"
cargo bench --workspace
du -sh ~/.vsdb
- rm -rf ~/.vsdb /tmp/.vsdb /tmp/vsdb_testing $(VSDB_BASE_DIR)
cargo bench --workspace
cargo bench --workspace --no-default-features --features "rocks_backend,compress,msgpack_codec"
du -sh ~/.vsdb
- rm -rf ~/.vsdb /tmp/.vsdb /tmp/vsdb_testing $(VSDB_BASE_DIR)
cargo bench --workspace --features "compress"
Expand Down
8 changes: 4 additions & 4 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vsdb_core"
version = "2.0.0"
version = "3.0.0"
authors = ["[email protected]"]
edition = "2021"
description = "A std-collection-like database"
Expand All @@ -18,19 +18,19 @@ parking_lot = { workspace = true }

threadpool = { workspace = true } # used in a background cleaner

rocksdb = { workspace = true, optional = true }
parity-db = { workspace = true, optional = true }
rocksdb = { workspace = true, optional = true }

[dev-dependencies]
msgpack = { workspace = true }
hex = "0.4.3"
criterion = "0.5.1"

[features]
default = ["compress", "rocks_backend"]
default = ["compress", "parity_backend"]

rocks_backend = ["rocksdb"]
parity_backend = ["parity-db"]
rocks_backend = ["rocksdb"]

compress = ["rocksdb?/zstd"]

Expand Down
12 changes: 6 additions & 6 deletions core/src/basic/mapx_raw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#[cfg(test)]
mod test;

use crate::common::{engines, RawKey, RawValue};
use crate::common::{engines, PreBytes, RawKey, RawValue};
use serde::{Deserialize, Serialize};
use std::{borrow::Cow, ops::RangeBounds};

Expand Down Expand Up @@ -78,8 +78,8 @@ impl MapxRaw {
}

#[inline(always)]
pub fn gen_mut(&mut self, key: RawValue, value: RawValue) -> ValueMut {
self.inner.gen_mut(key, value)
pub fn mock_value_mut(&mut self, key: RawValue, value: RawValue) -> ValueMut {
self.inner.mock_value_mut(key, value)
}

#[inline(always)]
Expand Down Expand Up @@ -183,7 +183,7 @@ impl MapxRaw {
}

#[inline(always)]
pub fn as_prefix_slice(&self) -> &[u8] {
pub fn as_prefix_slice(&self) -> &PreBytes {
self.inner.as_prefix_slice()
}

Expand All @@ -210,7 +210,7 @@ impl<'a> Entry<'a> {
if let Some(v) = unsafe { &mut *hdr }.get_mut(self.key) {
v
} else {
unsafe { &mut *hdr }.gen_mut(self.key.to_vec(), default.to_vec())
unsafe { &mut *hdr }.mock_value_mut(self.key.to_vec(), default.to_vec())
}
}

Expand All @@ -222,7 +222,7 @@ impl<'a> Entry<'a> {
if let Some(v) = unsafe { &mut *hdr }.get_mut(self.key) {
v
} else {
unsafe { &mut *hdr }.gen_mut(self.key.to_vec(), f())
unsafe { &mut *hdr }.mock_value_mut(self.key.to_vec(), f())
}
}
}
Loading

0 comments on commit 541e119

Please sign in to comment.