comp + vec: tiny opti

This commit is contained in:
nym21
2025-04-08 15:38:20 +02:00
parent 1323d988af
commit a7f2b24bac
2 changed files with 8 additions and 5 deletions

View File

@@ -10,11 +10,10 @@ use std::{
use brk_core::CheckedSub;
use brk_exit::Exit;
use brk_vec::{
AnyStorableVec, Compressed, Error, Result, StorableVec, StoredIndex, StoredType, Version,
AnyStorableVec, Compressed, Error, MAX_CACHE_SIZE, Result, StorableVec, StoredIndex,
StoredType, Version,
};
const FLUSH_EVERY: usize = 10_000;
#[derive(Debug)]
pub struct ComputedVec<I, T> {
computed_version: Option<Version>,
@@ -26,6 +25,8 @@ where
I: StoredIndex,
T: StoredType,
{
const SIZE_OF: usize = size_of::<T>();
pub fn forced_import(
path: &Path,
version: Version,
@@ -63,7 +64,7 @@ where
}
}
if self.vec.pushed_len() >= FLUSH_EVERY {
if self.vec.pushed_len() * Self::SIZE_OF >= MAX_CACHE_SIZE {
Ok(self.safe_flush(exit)?)
} else {
Ok(())