Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LayeredMap: carries Value instead of Option<Value> #13980

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions experimental/storage/layered-map/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ where
NodeStrongRef::Empty => return None,
NodeStrongRef::Leaf(leaf) => {
return if &leaf.key == key {
leaf.value.clone()
Some(leaf.value.clone())
} else {
None
}
Expand All @@ -217,7 +217,7 @@ where
} // end loop
}

fn new_leaf(&self, item: &(K, Option<V>)) -> NodeRef<K, V> {
fn new_leaf(&self, item: &(K, V)) -> NodeRef<K, V> {
let (key, value) = item.clone();
NodeRef::new_leaf(key, value, self.top_layer() + 1)
}
Expand Down Expand Up @@ -264,7 +264,7 @@ where
&self,
depth: usize,
current_root: NodeStrongRef<K, V>,
items: &[(K, Option<V>)],
items: &[(K, V)],
) -> NodeRef<K, V> {
if items.is_empty() {
return current_root.weak_ref();
Expand Down Expand Up @@ -292,7 +292,7 @@ where
)
}

pub fn new_layer(&self, items: &[(K, Option<V>)]) -> MapLayer<K, V> {
pub fn new_layer(&self, items: &[(K, V)]) -> MapLayer<K, V> {
let _timer = TIMER.timer_with(&[self.top_layer.inner.use_case, "new_layer"]);
let root = self.create_tree(0, self.root(), items);
MapLayer {
Expand Down
4 changes: 2 additions & 2 deletions experimental/storage/layered-map/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) struct InternalNode<K, V> {
#[derive(Debug)]
pub(crate) struct LeafNode<K, V> {
pub key: K,
pub value: Option<V>,
pub value: V,
pub layer: u64,
}

Expand All @@ -26,7 +26,7 @@ pub(crate) enum NodeRef<K, V> {
}

impl<K, V> NodeRef<K, V> {
pub fn new_leaf(key: K, value: Option<V>, layer: u64) -> Self {
pub fn new_leaf(key: K, value: V, layer: u64) -> Self {
Self::Leaf(Ref::Strong(Arc::new(LeafNode { key, value, layer })))
}

Expand Down
12 changes: 5 additions & 7 deletions experimental/storage/layered-map/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ impl crate::Key for u8 {
}
}

fn naive_view_layers<K: Ord, V>(
layers: impl Iterator<Item = BTreeMap<K, Option<V>>>,
) -> BTreeMap<K, Option<V>> {
fn naive_view_layers<K: Ord, V>(layers: impl Iterator<Item = BTreeMap<K, V>>) -> BTreeMap<K, V> {
layers.flat_map(|layer| layer.into_iter()).collect()
}

Expand All @@ -47,7 +45,7 @@ fn arb_test_case() -> impl Strategy<Value = (Vec<BTreeMap<u8, Option<u8>>>, usiz
fn layers(
items_per_layer: &[BTreeMap<u8, Option<u8>>],
max_base_layer: u64,
) -> Vec<MapLayer<u8, u8>> {
) -> Vec<MapLayer<u8, Option<u8>>> {
let mut base_layer = MapLayer::new_family("test");
let mut latest_layer = base_layer.clone();

Expand All @@ -61,7 +59,7 @@ fn layers(
.new_layer(&items_vec);
layers.push(latest_layer.clone());

// advance base layer occationally to expose more edge cases
// advance base layer occasionally to expose more edge cases
if base_layer_idx < max_base_layer as usize && layer_idx % 2 == 1 {
base_layer_idx += 1;
base_layer = layers[base_layer_idx].clone();
Expand All @@ -83,10 +81,10 @@ proptest! {

let layered_map = top_layer.into_layers_view_since(bottom_layer);

for (key, value ) in naive_view_layers(
for (key, value_opt) in naive_view_layers(
items_per_layer.drain(bottom..=top)
) {
prop_assert_eq!(layered_map.get(&key), value);
prop_assert_eq!(layered_map.get(&key), Some(value_opt));
}

// TODO(aldenhu): test that layered_map doesn't have any unexpected keys -- need ability to traverse
Expand Down
Loading