Skip to content

Commit

Permalink
update perf
Browse files Browse the repository at this point in the history
  • Loading branch information
XiangpengHao committed Oct 16, 2024
1 parent 6598df8 commit 2bcdd85
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
12 changes: 3 additions & 9 deletions src/node_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,11 @@ impl Node16 {
fn get_child_pos(&self, key: u8) -> Option<usize> {
// TODO: xiangpeng check this code is being auto-vectorized
let target = Self::flip_sign(key);
for (i, k) in self
.keys

self.keys
.iter()
.enumerate()
.take(self.base.meta.count as usize)
{
if *k == target {
return Some(i);
}
}
None
.position(|k| *k == target)
}
}

Expand Down
11 changes: 3 additions & 8 deletions src/node_4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,12 @@ impl Node for Node4 {
}

fn get_child(&self, key: u8) -> Option<NodePtr> {
for (k, c) in self
.keys
self.keys
.iter()
.zip(self.children.iter())
.take(self.base.meta.count as usize)
{
if *k == key {
return Some(*c);
}
}
None
.find(|(k, _)| **k == key)
.map(|(_, c)| *c)
}

#[cfg(feature = "db_extension")]
Expand Down
23 changes: 18 additions & 5 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,18 +302,31 @@ impl<T: RawKey, A: Allocator + Clone + Send> RawTree<T, A> {
}
}

#[inline]
fn check_prefix(node: &BaseNode, key: &T, mut level: u32) -> Option<u32> {
let n_prefix = node.prefix();
let k_prefix = key.as_bytes();
let k_iter = k_prefix.iter().skip(level as usize);
let node_prefix = node.prefix();
let key_prefix = key.as_bytes();

// let found = node_prefix
// .iter()
// .zip(key_prefix)
// .skip(level as usize)
// .find(|(n, k)| n != k);

// debug_assert!(key_prefix.len() >= node_prefix.len());

// if found.is_some() {
// return None;
// } else {
// Some(node_prefix.len() as u32)
// }

for (n, k) in n_prefix.iter().skip(level as usize).zip(k_iter) {
for (n, k) in node_prefix.iter().zip(key_prefix).skip(level as usize) {
if n != k {
return None;
}
level += 1;
}
debug_assert!(level == node_prefix.len() as u32);
Some(level)
}

Expand Down

0 comments on commit 2bcdd85

Please sign in to comment.