mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-16 05:28:12 -07:00
global: fixes
This commit is contained in:
@@ -307,84 +307,6 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Compute cumulative extension from a source vec.
|
||||
///
|
||||
/// Used when only cumulative needs to be extended from an existing source.
|
||||
pub fn compute_cumulative<I, T>(
|
||||
max_from: I,
|
||||
source: &impl IterableVec<I, T>,
|
||||
cumulative: &mut EagerVec<PcoVec<I, T>>,
|
||||
exit: &Exit,
|
||||
) -> Result<()>
|
||||
where
|
||||
I: VecIndex,
|
||||
T: ComputedVecValue + JsonSchema,
|
||||
{
|
||||
cumulative.validate_computed_version_or_reset(source.version())?;
|
||||
|
||||
let index = max_from.min(I::from(cumulative.len()));
|
||||
|
||||
let mut cumulative_val = index
|
||||
.decremented()
|
||||
.map_or(T::from(0_usize), |idx| cumulative.iter().get_unwrap(idx));
|
||||
|
||||
source
|
||||
.iter()
|
||||
.enumerate()
|
||||
.skip(index.to_usize())
|
||||
.try_for_each(|(i, v)| -> Result<()> {
|
||||
cumulative_val += v;
|
||||
cumulative.truncate_push_at(i, cumulative_val)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
let _lock = exit.lock();
|
||||
cumulative.write()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Compute cumulative from binary transform of two source vecs.
|
||||
pub fn compute_cumulative_transform2<I, T, S1, S2, F>(
|
||||
max_from: I,
|
||||
source1: &impl IterableVec<I, S1>,
|
||||
source2: &impl IterableVec<I, S2>,
|
||||
cumulative: &mut EagerVec<PcoVec<I, T>>,
|
||||
transform: F,
|
||||
exit: &Exit,
|
||||
) -> Result<()>
|
||||
where
|
||||
I: VecIndex,
|
||||
T: ComputedVecValue + JsonSchema,
|
||||
S1: VecValue,
|
||||
S2: VecValue,
|
||||
F: Fn(S1, S2) -> T,
|
||||
{
|
||||
let combined_version = source1.version() + source2.version();
|
||||
cumulative.validate_computed_version_or_reset(combined_version)?;
|
||||
|
||||
let index = max_from.min(I::from(cumulative.len()));
|
||||
let target_len = source1.len().min(source2.len());
|
||||
|
||||
let mut cumulative_val = index
|
||||
.decremented()
|
||||
.map_or(T::from(0_usize), |idx| cumulative.read_unwrap_once(idx));
|
||||
|
||||
let mut iter1 = source1.iter();
|
||||
let mut iter2 = source2.iter();
|
||||
|
||||
for i in index.to_usize()..target_len {
|
||||
let idx = I::from(i);
|
||||
cumulative_val += transform(iter1.get_unwrap(idx), iter2.get_unwrap(idx));
|
||||
cumulative.truncate_push_at(i, cumulative_val)?;
|
||||
}
|
||||
|
||||
let _lock = exit.lock();
|
||||
cumulative.write()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Compute coarser aggregations from already-aggregated source data.
|
||||
///
|
||||
/// This is used for dateindex → weekindex, monthindex, etc. where we derive
|
||||
|
||||
@@ -16,11 +16,12 @@ use vecdb::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
indexes,
|
||||
internal::{
|
||||
CumulativeVec, Full, LazyBinaryTransformFull, LazyDateDerivedFull, LazyFull,
|
||||
SatsTimesClosePrice, Stats, compute_cumulative,
|
||||
SatsTimesClosePrice, Stats,
|
||||
},
|
||||
ComputeIndexes,
|
||||
};
|
||||
|
||||
/// Lazy dollars at TxIndex: `sats * price[height]`
|
||||
@@ -136,10 +137,9 @@ impl ValueDollarsFromTxFull {
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
// Compute height cumulative by summing lazy height.sum values
|
||||
compute_cumulative(
|
||||
self.height_cumulative.0.compute_cumulative(
|
||||
starting_indexes.height,
|
||||
&self.height.sum,
|
||||
&mut self.height_cumulative.0,
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -9,11 +9,11 @@ use schemars::JsonSchema;
|
||||
use vecdb::{Database, Exit, IterableBoxedVec, IterableCloneableVec, IterableVec};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
indexes,
|
||||
internal::{
|
||||
ComputedVecValue, CumulativeVec, Full, LazyDateDerivedFull, LazyFull, NumericValue,
|
||||
compute_cumulative,
|
||||
},
|
||||
ComputeIndexes,
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
@@ -102,6 +102,9 @@ where
|
||||
height_source: &impl IterableVec<Height, T>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
compute_cumulative(max_from, height_source, &mut self.height_cumulative.0, exit)
|
||||
self.height_cumulative
|
||||
.0
|
||||
.compute_cumulative(max_from, height_source, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,11 @@ use vecdb::{
|
||||
};
|
||||
|
||||
use crate::{
|
||||
ComputeIndexes, indexes,
|
||||
indexes,
|
||||
internal::{
|
||||
ComputedVecValue, CumulativeVec, LazyDateDerivedSumCum, LazySumCum, NumericValue, SumCum,
|
||||
compute_cumulative,
|
||||
},
|
||||
ComputeIndexes,
|
||||
};
|
||||
|
||||
#[derive(Clone, Deref, DerefMut, Traversable)]
|
||||
@@ -99,7 +99,10 @@ where
|
||||
source: &impl IterableVec<Height, T>,
|
||||
exit: &Exit,
|
||||
) -> Result<()> {
|
||||
compute_cumulative(max_from, source, &mut self.height_cumulative.0, exit)
|
||||
self.height_cumulative
|
||||
.0
|
||||
.compute_cumulative(max_from, source, exit)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn compute_dateindex_sum_cum(
|
||||
|
||||
Reference in New Issue
Block a user