computer: indexes + rolling

This commit is contained in:
nym21
2026-02-24 17:07:35 +01:00
parent cefc8cfd42
commit f74115c6e2
160 changed files with 2604 additions and 4739 deletions

View File

@@ -1,21 +1,43 @@
use brk_error::Result;
use brk_indexer::Indexer;
use brk_types::StoredU64;
use vecdb::Exit;
use super::Vecs;
use crate::ComputeIndexes;
use crate::{blocks, ComputeIndexes};
impl Vecs {
pub(crate) fn compute(
&mut self,
indexer: &Indexer,
count_vecs: &blocks::CountVecs,
starting_indexes: &ComputeIndexes,
exit: &Exit,
) -> Result<()> {
self.size
.compute_cumulative(starting_indexes, &indexer.vecs.blocks.total_size, exit)?;
let window_starts = count_vecs.window_starts();
self.vbytes.compute_cumulative(starting_indexes, exit)?;
// vbytes = ceil(weight / 4), stored at height level
self.vbytes.compute(
starting_indexes.height,
&window_starts,
exit,
|height| {
Ok(height.compute_transform(
starting_indexes.height,
&indexer.vecs.blocks.weight,
|(h, weight, ..)| (h, StoredU64::from(weight.to_vbytes_floor())),
exit,
)?)
},
)?;
// size from indexer total_size
self.size.compute(
starting_indexes.height,
&window_starts,
&indexer.vecs.blocks.total_size,
exit,
)?;
Ok(())
}

View File

@@ -4,7 +4,10 @@ use brk_types::Version;
use vecdb::{Database, ReadableCloneableVec};
use super::Vecs;
use crate::{indexes, internal::{ComputedHeightDerivedFull, LazyComputedFromHeightFull, WeightToVbytes}};
use crate::{
indexes,
internal::{ComputedFromHeightCumFull, ComputedHeightDerivedCumFull},
};
impl Vecs {
pub(crate) fn forced_import(
@@ -14,14 +17,13 @@ impl Vecs {
indexes: &indexes::Vecs,
) -> Result<Self> {
Ok(Self {
vbytes: LazyComputedFromHeightFull::forced_import::<WeightToVbytes>(
vbytes: ComputedFromHeightCumFull::forced_import(
db,
"block_vbytes",
version,
&indexer.vecs.blocks.weight,
indexes,
)?,
size: ComputedHeightDerivedFull::forced_import(
size: ComputedHeightDerivedCumFull::forced_import(
db,
"block_size",
indexer.vecs.blocks.total_size.read_only_boxed_clone(),

View File

@@ -1,11 +1,11 @@
use brk_traversable::Traversable;
use brk_types::{StoredU64, Weight};
use brk_types::StoredU64;
use vecdb::{Rw, StorageMode};
use crate::internal::{ComputedHeightDerivedFull, LazyComputedFromHeightFull};
use crate::internal::{ComputedFromHeightCumFull, ComputedHeightDerivedCumFull};
#[derive(Traversable)]
pub struct Vecs<M: StorageMode = Rw> {
pub vbytes: LazyComputedFromHeightFull<StoredU64, Weight, M>,
pub size: ComputedHeightDerivedFull<StoredU64, M>,
pub vbytes: ComputedFromHeightCumFull<StoredU64, M>,
pub size: ComputedHeightDerivedCumFull<StoredU64, M>,
}