mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 22:59:58 -07:00
global: snapshot
This commit is contained in:
35
crates/brk_computer/src/internal/vec/sum.rs
Normal file
35
crates/brk_computer/src/internal/vec/sum.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use brk_error::Result;
|
||||
use brk_traversable::Traversable;
|
||||
use derive_more::{Deref, DerefMut};
|
||||
use schemars::JsonSchema;
|
||||
use vecdb::{
|
||||
Database, EagerVec, ImportableVec, PcoVec, Ro, Rw, StorageMode, StoredVec, VecIndex, Version,
|
||||
};
|
||||
|
||||
use crate::internal::ComputedVecValue;
|
||||
|
||||
/// Sum of values in an aggregation period
|
||||
#[derive(Deref, DerefMut, Traversable)]
|
||||
#[traversable(transparent)]
|
||||
pub struct SumVec<I: VecIndex, T: ComputedVecValue + JsonSchema, M: StorageMode = Rw>(
|
||||
pub M::Stored<EagerVec<PcoVec<I, T>>>,
|
||||
);
|
||||
|
||||
impl<I: VecIndex, T: ComputedVecValue + JsonSchema> SumVec<I, T> {
|
||||
pub(crate) fn forced_import(db: &Database, name: &str, version: Version) -> Result<Self> {
|
||||
Ok(Self(EagerVec::forced_import(
|
||||
db,
|
||||
&format!("{name}_sum"),
|
||||
version,
|
||||
)?))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn inner(&self) -> &EagerVec<PcoVec<I, T>> {
|
||||
&self.0
|
||||
}
|
||||
|
||||
pub fn read_only_clone(&self) -> SumVec<I, T, Ro> {
|
||||
SumVec(StoredVec::read_only_clone(&self.0))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user