Skip to content

Commit

Permalink
Implement clone, scan_at_ts and keys_at_ts for Tree (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsserge authored Oct 24, 2024
1 parent 2f33a89 commit 7933b44
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "vart"
publish = true
version = "0.6.2"
version = "0.6.3"
edition = "2021"
license = "Apache-2.0"
readme = "README.md"
Expand Down
25 changes: 24 additions & 1 deletion src/art.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::cmp::min;
use std::ops::RangeBounds;
use std::sync::Arc;

use crate::iter::{Iter, Range};
use crate::iter::{query_keys_at_node, scan_node, Iter, Range};
use crate::node::{FlatNode, LeafValue, Node256, Node48, NodeTrait, TwigNode, Version};
use crate::snapshot::Snapshot;
use crate::{KeyTrait, TrieError};
Expand Down Expand Up @@ -1028,6 +1028,15 @@ impl<P: KeyTrait, V: Clone> Default for Tree<P, V> {
}
}

impl<P: KeyTrait, V: Clone> Clone for Tree<P, V> {
fn clone(&self) -> Self {
Self {
root: self.root.as_ref().cloned(),
size: self.size,
}
}
}

impl<P: KeyTrait, V: Clone> Tree<P, V> {
pub fn new() -> Self {
Tree {
Expand Down Expand Up @@ -1537,6 +1546,20 @@ impl<P: KeyTrait, V: Clone> Tree<P, V> {
pub fn is_empty(&self) -> bool {
self.size == 0
}

pub fn scan_at_ts<R>(&self, range: R, ts: u64) -> Vec<(Vec<u8>, V)>
where
R: RangeBounds<P>,
{
scan_node(self.root.as_ref(), range, QueryType::LatestByTs(ts))
}

pub fn keys_at_ts<R>(&self, range: R, ts: u64) -> Vec<Vec<u8>>
where
R: RangeBounds<P>,
{
query_keys_at_node(self.root.as_ref(), range, QueryType::LatestByTs(ts))
}
}

/*
Expand Down

0 comments on commit 7933b44

Please sign in to comment.