Distinguish between creating a new empty tree and loading data for an existing tree.
This commit is contained in:
parent
e15440bd37
commit
10e5ee59a4
|
@ -1691,8 +1691,9 @@ impl<
|
||||||
const SHARD_HEIGHT: u8,
|
const SHARD_HEIGHT: u8,
|
||||||
> ShardTree<H, C, S, DEPTH, SHARD_HEIGHT>
|
> ShardTree<H, C, S, DEPTH, SHARD_HEIGHT>
|
||||||
{
|
{
|
||||||
/// Creates a new empty tree.
|
/// Creates a new empty tree and establishes a checkpoint for the empty tree at the given
|
||||||
pub fn new(
|
/// checkpoint identifier.
|
||||||
|
pub fn empty(
|
||||||
store: S,
|
store: S,
|
||||||
max_checkpoints: usize,
|
max_checkpoints: usize,
|
||||||
initial_checkpoint_id: C,
|
initial_checkpoint_id: C,
|
||||||
|
@ -1709,6 +1710,19 @@ impl<
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Constructs a wrapper around the provided shard store without initialization.
|
||||||
|
pub fn load(
|
||||||
|
store: S,
|
||||||
|
max_checkpoints: usize,
|
||||||
|
) -> Self {
|
||||||
|
Self {
|
||||||
|
store,
|
||||||
|
max_checkpoints,
|
||||||
|
_hash_type: PhantomData,
|
||||||
|
_checkpoint_id_type: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the root address of the tree.
|
/// Returns the root address of the tree.
|
||||||
pub fn root_addr() -> Address {
|
pub fn root_addr() -> Address {
|
||||||
Address::from_parts(Level::from(DEPTH), 0)
|
Address::from_parts(Level::from(DEPTH), 0)
|
||||||
|
@ -2752,7 +2766,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn shardtree_insertion() {
|
fn shardtree_insertion() {
|
||||||
let mut tree: ShardTree<String, usize, MemoryShardStore<String, usize>, 4, 3> =
|
let mut tree: ShardTree<String, usize, MemoryShardStore<String, usize>, 4, 3> =
|
||||||
ShardTree::new(MemoryShardStore::empty(), 100, 0).unwrap();
|
ShardTree::empty(MemoryShardStore::empty(), 100, 0).unwrap();
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
tree.batch_insert(
|
tree.batch_insert(
|
||||||
Position::from(1),
|
Position::from(1),
|
||||||
|
@ -2900,7 +2914,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn append() {
|
fn append() {
|
||||||
check_append(|m| {
|
check_append(|m| {
|
||||||
ShardTree::<String, usize, MemoryShardStore<String, usize>, 4, 3>::new(
|
ShardTree::<String, usize, MemoryShardStore<String, usize>, 4, 3>::empty(
|
||||||
MemoryShardStore::empty(),
|
MemoryShardStore::empty(),
|
||||||
m,
|
m,
|
||||||
0,
|
0,
|
||||||
|
@ -2912,7 +2926,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn root_hashes() {
|
fn root_hashes() {
|
||||||
check_root_hashes(|m| {
|
check_root_hashes(|m| {
|
||||||
ShardTree::<String, usize, MemoryShardStore<String, usize>, 4, 3>::new(
|
ShardTree::<String, usize, MemoryShardStore<String, usize>, 4, 3>::empty(
|
||||||
MemoryShardStore::empty(),
|
MemoryShardStore::empty(),
|
||||||
m,
|
m,
|
||||||
0,
|
0,
|
||||||
|
@ -2924,7 +2938,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn witnesses() {
|
fn witnesses() {
|
||||||
check_witnesses(|m| {
|
check_witnesses(|m| {
|
||||||
ShardTree::<String, usize, MemoryShardStore<String, usize>, 4, 3>::new(
|
ShardTree::<String, usize, MemoryShardStore<String, usize>, 4, 3>::empty(
|
||||||
MemoryShardStore::empty(),
|
MemoryShardStore::empty(),
|
||||||
m,
|
m,
|
||||||
0,
|
0,
|
||||||
|
@ -2936,7 +2950,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn checkpoint_rewind() {
|
fn checkpoint_rewind() {
|
||||||
check_checkpoint_rewind(|m| {
|
check_checkpoint_rewind(|m| {
|
||||||
ShardTree::<String, usize, MemoryShardStore<String, usize>, 4, 3>::new(
|
ShardTree::<String, usize, MemoryShardStore<String, usize>, 4, 3>::empty(
|
||||||
MemoryShardStore::empty(),
|
MemoryShardStore::empty(),
|
||||||
m,
|
m,
|
||||||
0,
|
0,
|
||||||
|
@ -2948,7 +2962,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn rewind_remove_mark() {
|
fn rewind_remove_mark() {
|
||||||
check_rewind_remove_mark(|m| {
|
check_rewind_remove_mark(|m| {
|
||||||
ShardTree::<String, usize, MemoryShardStore<String, usize>, 4, 3>::new(
|
ShardTree::<String, usize, MemoryShardStore<String, usize>, 4, 3>::empty(
|
||||||
MemoryShardStore::empty(),
|
MemoryShardStore::empty(),
|
||||||
m,
|
m,
|
||||||
0,
|
0,
|
||||||
|
@ -2969,7 +2983,7 @@ mod tests {
|
||||||
> {
|
> {
|
||||||
CombinedTree::new(
|
CombinedTree::new(
|
||||||
CompleteTree::new(max_checkpoints, 0),
|
CompleteTree::new(max_checkpoints, 0),
|
||||||
ShardTree::new(MemoryShardStore::empty(), max_checkpoints, 0).unwrap(),
|
ShardTree::empty(MemoryShardStore::empty(), max_checkpoints, 0).unwrap(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue