mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 07:09:59 -07:00
global: snapshot
This commit is contained in:
@@ -67,21 +67,21 @@ where
|
||||
self.date.multi_insert_const(dates, constant);
|
||||
}
|
||||
|
||||
pub fn multi_insert_simple_transform<F, K>(
|
||||
pub fn multi_insert_simple_transform<F, V>(
|
||||
&mut self,
|
||||
heights: &[Height],
|
||||
dates: &[Date],
|
||||
source: &mut BiMap<K>,
|
||||
source: &mut BiMap<V>,
|
||||
transform: &F,
|
||||
) where
|
||||
Value: Div<Output = Value>,
|
||||
F: Fn(K) -> Value,
|
||||
K: MapValue,
|
||||
F: Fn(V) -> Value,
|
||||
V: MapValue,
|
||||
{
|
||||
self.height
|
||||
.multi_insert_simple_transform(heights, &mut source.height, transform);
|
||||
.multi_insert_simple_transform(heights, &mut source.height, |v, _| transform(v));
|
||||
self.date
|
||||
.multi_insert_simple_transform(dates, &mut source.date, transform);
|
||||
.multi_insert_simple_transform(dates, &mut source.date, |v, _| transform(v));
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
|
||||
@@ -45,6 +45,10 @@ impl Date {
|
||||
pub fn yesterday() -> Self {
|
||||
Self(Self::today().checked_sub_days(Days::new(1)).unwrap())
|
||||
}
|
||||
|
||||
pub fn difference_in_days_between(&self, older: Self) -> u32 {
|
||||
(**self - *older).num_days() as u32
|
||||
}
|
||||
}
|
||||
|
||||
impl MapKey<DateMapChunkId> for Date {
|
||||
|
||||
@@ -21,8 +21,8 @@ impl MapChunkId for DateMapChunkId {
|
||||
self.0.to_string()
|
||||
}
|
||||
|
||||
fn from_path(path: &Path) -> Self {
|
||||
Self(
|
||||
fn from_path(path: &Path) -> color_eyre::Result<Self> {
|
||||
Ok(Self(
|
||||
path.file_name()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
@@ -30,9 +30,8 @@ impl MapChunkId for DateMapChunkId {
|
||||
.split(".")
|
||||
.next()
|
||||
.unwrap()
|
||||
.parse::<i32>()
|
||||
.unwrap(),
|
||||
)
|
||||
.parse::<i32>()?,
|
||||
))
|
||||
}
|
||||
|
||||
fn to_usize(self) -> usize {
|
||||
|
||||
@@ -63,7 +63,7 @@ where
|
||||
Self: Ord + Debug + Copy + Clone,
|
||||
{
|
||||
fn to_name(&self) -> String;
|
||||
fn from_path(path: &Path) -> Self;
|
||||
fn from_path(path: &Path) -> color_eyre::Result<Self>;
|
||||
fn to_usize(self) -> usize;
|
||||
fn from_usize(id: usize) -> Self;
|
||||
}
|
||||
@@ -189,9 +189,12 @@ where
|
||||
.unwrap()
|
||||
.map(|entry| entry.unwrap().path())
|
||||
.filter(|path| serialization.is_serializable(path))
|
||||
.map(|path| {
|
||||
let chunk_id = ChunkId::from_path(&path);
|
||||
(chunk_id, path)
|
||||
.flat_map(|path| {
|
||||
if let Ok(chunk_id) = ChunkId::from_path(&path) {
|
||||
Some((chunk_id, path))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -414,10 +417,10 @@ where
|
||||
) where
|
||||
SourceValue: MapValue,
|
||||
SourceSerialized: MapSerialized<Key, SourceValue, ChunkId>,
|
||||
F: Fn(SourceValue) -> Value,
|
||||
F: Fn(SourceValue, &Key) -> Value,
|
||||
{
|
||||
keys.iter().for_each(|key| {
|
||||
self.insert(*key, transform(source.get_or_import(key).unwrap()));
|
||||
self.insert(*key, transform(source.get_or_import(key).unwrap(), key));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -434,13 +437,14 @@ where
|
||||
SourceValue,
|
||||
&Key,
|
||||
&mut GenericMap<Key, SourceValue, ChunkId, SourceSerialized>,
|
||||
&Self,
|
||||
),
|
||||
) -> Value,
|
||||
{
|
||||
keys.iter().for_each(|key| {
|
||||
self.insert(
|
||||
*key,
|
||||
transform((source.get_or_import(key).unwrap(), key, source)),
|
||||
transform((source.get_or_import(key).unwrap(), key, source, self)),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -823,31 +827,27 @@ where
|
||||
where
|
||||
Value: Default + PartialOrd,
|
||||
{
|
||||
let mut max = None;
|
||||
let mut previous_max = None;
|
||||
|
||||
keys.iter().for_each(|key| {
|
||||
let previous_max = max.unwrap_or_else(|| {
|
||||
if previous_max.is_none() {
|
||||
key.checked_sub(1)
|
||||
.and_then(|previous_max_key| self.get(&previous_max_key))
|
||||
.unwrap_or_default()
|
||||
});
|
||||
.and_then(|v| previous_max.replace(v));
|
||||
}
|
||||
|
||||
let last_value = source.get_or_import(key).unwrap_or_else(|| {
|
||||
dbg!(key);
|
||||
panic!()
|
||||
});
|
||||
|
||||
if max.is_none() || last_value > previous_max {
|
||||
max.replace(last_value);
|
||||
if previous_max.is_none()
|
||||
|| previous_max.is_some_and(|previous_max| previous_max < last_value)
|
||||
{
|
||||
previous_max.replace(last_value);
|
||||
}
|
||||
|
||||
self.insert(
|
||||
*key,
|
||||
max.unwrap_or_else(|| {
|
||||
dbg!(previous_max, last_value, max);
|
||||
panic!();
|
||||
}),
|
||||
);
|
||||
self.insert(*key, previous_max.unwrap());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ impl MapChunkId for HeightMapChunkId {
|
||||
format!("{start}..{end}")
|
||||
}
|
||||
|
||||
fn from_path(path: &Path) -> Self {
|
||||
Self(Height::new(
|
||||
fn from_path(path: &Path) -> color_eyre::Result<Self> {
|
||||
Ok(Self(Height::new(
|
||||
path.file_name()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
@@ -37,12 +37,8 @@ impl MapChunkId for HeightMapChunkId {
|
||||
.split("..")
|
||||
.next()
|
||||
.unwrap()
|
||||
.parse::<u32>()
|
||||
.unwrap_or_else(|_| {
|
||||
dbg!(path);
|
||||
panic!()
|
||||
}),
|
||||
))
|
||||
.parse::<u32>()?,
|
||||
)))
|
||||
}
|
||||
|
||||
fn to_usize(self) -> usize {
|
||||
|
||||
Reference in New Issue
Block a user