global: snapshot

This commit is contained in:
k
2024-10-26 16:41:38 +02:00
parent 7114c3bdf9
commit f5754780a8
30 changed files with 888 additions and 541 deletions

View File

@@ -0,0 +1,20 @@
use super::{Height, MapKey};
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Epoch(pub u16);
impl Epoch {
pub const BLOCKS_PER_EPOCH: usize = 210_000;
}
impl From<Height> for Epoch {
fn from(height: Height) -> Self {
Self(((height.to_usize() / Self::BLOCKS_PER_EPOCH) + 1) as u16)
}
}
impl From<&Height> for Epoch {
fn from(height: &Height) -> Self {
Self(((height.to_usize() / Self::BLOCKS_PER_EPOCH) + 1) as u16)
}
}

View File

@@ -202,10 +202,12 @@ where
}
pub fn insert(&mut self, key: Key, value: Value) -> Value {
self.to_insert
.entry(key.to_chunk_id())
.or_default()
.insert(key.to_serialized_key(), value);
if !self.is_key_safe(key) {
self.to_insert
.entry(key.to_chunk_id())
.or_default()
.insert(key.to_serialized_key(), value);
}
value
}
@@ -443,15 +445,14 @@ where
SourceValue,
&Key,
&mut GenericMap<Key, SourceValue, ChunkId, SourceSerialized>,
&Self,
&mut Self,
),
) -> Value,
{
keys.iter().for_each(|key| {
self.insert(
*key,
transform((source.get_or_import(key).unwrap(), key, source, self)),
);
let value = transform((source.get_or_import(key).unwrap(), key, source, self));
self.insert(*key, value);
});
}

View File

@@ -17,6 +17,7 @@ mod date_data;
mod date_map;
mod date_map_chunk_id;
mod empty_address_data;
mod epoch;
mod exit;
mod generic_map;
mod height;
@@ -53,6 +54,7 @@ pub use date_data::*;
pub use date_map::*;
pub use date_map_chunk_id::*;
pub use empty_address_data::*;
pub use epoch::*;
pub use exit::*;
pub use generic_map::*;
pub use height::*;