Skip to content

Commit

Permalink
streamline dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
XiangpengHao committed Aug 9, 2024
1 parent c168553 commit 2263792
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 115 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
Cargo.lock
.vscode
.idea
15 changes: 7 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ license = "MIT"
[dependencies]
crossbeam-epoch = "0.9.18"
rand = { version = "0.8.5", optional = true }
serde = { version = "1.0.196", features = ["derive"], optional = true }
serde = { version = "1.0.205", features = ["derive"], optional = true }

[dev-dependencies]
rand = "0.8.5"
shumai = "0.2.14"
serde = "1.0.196"
serde_json = "1.0.113"
flurry = "0.5.0"
mimalloc = { version = "0.1.39", default-features = false }
shumai = "0.2.15"
serde = "1.0.205"
serde_json = "1.0.122"
flurry = "0.5.1"
mimalloc = { version = "0.1.43", default-features = false }
selfsimilar = "0.1.0"
static_assertions = "1.1.0"
shuttle = "0.7.0"
shuttle = "0.7.1"

[[bench]]
name = "basic"
Expand Down
12 changes: 6 additions & 6 deletions src/base_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ pub(crate) struct NodeMeta {
prefix: Prefix,
}

#[cfg(all(test, not(feature = "shuttle")))]
mod const_assert {
#[cfg(not(feature = "shuttle"))]
mod layout_assertion {
use super::*;
static_assertions::const_assert_eq!(std::mem::size_of::<NodeMeta>(), 16);
static_assertions::const_assert_eq!(std::mem::align_of::<NodeMeta>(), 4);
static_assertions::const_assert_eq!(std::mem::size_of::<BaseNode>(), 24);
static_assertions::const_assert_eq!(std::mem::align_of::<BaseNode>(), 8);
const _: () = assert!(std::mem::size_of::<NodeMeta>() == 16);
const _: () = assert!(std::mem::align_of::<NodeMeta>() == 4);
const _: () = assert!(std::mem::size_of::<BaseNode>() == 24);
const _: () = assert!(std::mem::align_of::<BaseNode>() == 8);
}

macro_rules! gen_method {
Expand Down
30 changes: 15 additions & 15 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ pub trait RawKey: Eq + PartialEq + Default + PartialOrd + Ord {
}

#[derive(Clone)]
pub struct GeneralKey {
pub(crate) struct TestingKey {
len: usize,
stack_keys: [u8; STACK_KEY_LEN],
}

impl RawKey for GeneralKey {
impl RawKey for TestingKey {
fn len(&self) -> usize {
self.len
}

fn key_from(tid: usize) -> GeneralKey {
fn as_bytes(&self) -> &[u8] {
self.stack_keys[..self.len].as_ref()
}

fn key_from(tid: usize) -> TestingKey {
let mut stack_keys = [0; STACK_KEY_LEN];

let swapped = tid.swap_bytes();
Expand All @@ -29,17 +33,13 @@ impl RawKey for GeneralKey {
stack_keys[i] = *v;
}

GeneralKey {
TestingKey {
len: std::mem::size_of::<usize>(),
stack_keys,
}
}

fn as_bytes(&self) -> &[u8] {
self.stack_keys[..self.len].as_ref()
}
}
impl Ord for GeneralKey {
impl Ord for TestingKey {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
for i in 0..std::cmp::min(self.len(), other.len()) {
if self.as_bytes()[i] > other.as_bytes()[i] {
Expand All @@ -56,13 +56,13 @@ impl Ord for GeneralKey {
}
}

impl PartialOrd for GeneralKey {
impl PartialOrd for TestingKey {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl PartialEq for GeneralKey {
impl PartialEq for TestingKey {
fn eq(&self, other: &Self) -> bool {
if self.len != other.len {
return false;
Expand All @@ -76,17 +76,17 @@ impl PartialEq for GeneralKey {
}
}

impl Eq for GeneralKey {}
impl Eq for TestingKey {}

impl Default for GeneralKey {
impl Default for TestingKey {
fn default() -> Self {
Self::new()
}
}

impl GeneralKey {
impl TestingKey {
fn new() -> Self {
GeneralKey {
TestingKey {
len: 0,
stack_keys: [0; STACK_KEY_LEN],
}
Expand Down
13 changes: 6 additions & 7 deletions src/node_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ use crate::{
};

#[repr(C)]
#[repr(align(8))] // Node 16 doesn't need to align to 64 bc it occupies 3 cachelines anyway
#[repr(align(8))] // Node 16 doesn't need to align to 64 bc it occupies 3 cache lines anyway
pub(crate) struct Node16 {
base: BaseNode,
children: [NodePtr; 16],
keys: [u8; 16],
}

#[cfg(all(test, not(feature = "shuttle")))]
mod const_assert {
use super::*;
static_assertions::const_assert_eq!(std::mem::size_of::<Node16>(), 168);
static_assertions::const_assert_eq!(std::mem::align_of::<Node16>(), 8);
}
#[cfg(not(feature = "shuttle"))]
const _: () = assert!(std::mem::size_of::<Node16>() == 168);

#[cfg(not(feature = "shuttle"))]
const _: () = assert!(std::mem::align_of::<Node16>() == 8);

impl Node16 {
fn flip_sign(val: u8) -> u8 {
Expand Down
10 changes: 4 additions & 6 deletions src/node_256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ pub(crate) struct Node256 {
children: [NodePtr; 256],
}

#[cfg(all(test, not(feature = "shuttle")))]
mod const_assert {
use super::*;
static_assertions::const_assert_eq!(std::mem::size_of::<Node256>(), 2104);
static_assertions::const_assert_eq!(std::mem::align_of::<Node256>(), 8);
}
#[cfg(not(feature = "shuttle"))]
const _: () = assert!(std::mem::size_of::<Node256>() == 2104);
#[cfg(not(feature = "shuttle"))]
const _: () = assert!(std::mem::align_of::<Node256>() == 8);

impl Node256 {
#[inline]
Expand Down
11 changes: 5 additions & 6 deletions src/node_4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ pub(crate) struct Node4 {
children: [NodePtr; 4],
}

#[cfg(all(test, not(feature = "shuttle")))]
mod const_assert {
use super::*;
static_assertions::const_assert_eq!(std::mem::size_of::<Node4>(), 64);
static_assertions::const_assert_eq!(std::mem::align_of::<Node4>(), 64);
}
#[cfg(not(feature = "shuttle"))]
const _: () = assert!(std::mem::size_of::<Node4>() == 64);

#[cfg(not(feature = "shuttle"))]
const _: () = assert!(std::mem::align_of::<Node4>() == 64);

pub(crate) struct Node4Iter<'a> {
start: u8,
Expand Down
10 changes: 4 additions & 6 deletions src/node_48.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ pub(crate) struct Node48 {
next_empty: u8,
children: [NodePtr; 48],
}
#[cfg(not(feature = "shuttle"))]
const _: () = assert!(std::mem::size_of::<Node48>() == 672);

#[cfg(all(test, not(feature = "shuttle")))]
mod const_assert {
use super::*;
static_assertions::const_assert_eq!(std::mem::size_of::<Node48>(), 672);
static_assertions::const_assert_eq!(std::mem::align_of::<Node48>(), 8);
}
#[cfg(not(feature = "shuttle"))]
const _: () = assert!(std::mem::align_of::<Node48>() == 8);

impl Node48 {
pub(crate) fn init_empty(&mut self) {
Expand Down
Loading

0 comments on commit 2263792

Please sign in to comment.