mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 06:39:58 -07:00
vec: compression part 1
This commit is contained in:
@@ -9,7 +9,7 @@ use std::{
|
||||
|
||||
use brk_core::CheckedSub;
|
||||
use brk_exit::Exit;
|
||||
use brk_vec::{Error, Result, StoredIndex, StoredType, Version};
|
||||
use brk_vec::{Compressed, Error, Result, StoredIndex, StoredType, Version};
|
||||
|
||||
const FLUSH_EVERY: usize = 10_000;
|
||||
|
||||
@@ -25,7 +25,7 @@ where
|
||||
T: StoredType,
|
||||
{
|
||||
pub fn import(path: &Path, version: Version) -> brk_vec::Result<Self> {
|
||||
let vec = brk_vec::StorableVec::forced_import(path, version)?;
|
||||
let vec = brk_vec::StorableVec::forced_import(path, version, Compressed::YES)?;
|
||||
|
||||
Ok(Self {
|
||||
computed_version: None,
|
||||
@@ -103,14 +103,14 @@ where
|
||||
where
|
||||
A: StoredIndex,
|
||||
B: StoredType,
|
||||
F: FnMut((A, &B, &mut Self, &mut brk_vec::StorableVec<A, B>)) -> (I, T),
|
||||
F: FnMut((A, B, &mut Self, &mut brk_vec::StorableVec<A, B>)) -> (I, T),
|
||||
{
|
||||
self.validate_computed_version_or_reset_file(
|
||||
Version::from(0) + self.version() + other.version(),
|
||||
)?;
|
||||
|
||||
let index = max_from.min(A::from(self.len()));
|
||||
other.iter_from(index, |(a, b, other)| {
|
||||
other.iter_from_cloned(index, |(a, b, other)| {
|
||||
let (i, v) = t((a, b, self, other));
|
||||
self.push_and_flush_if_needed(i, v, exit)
|
||||
})?;
|
||||
|
||||
@@ -100,7 +100,7 @@ impl Vecs {
|
||||
self.height_to_real_date.compute_transform(
|
||||
starting_indexes.height,
|
||||
&mut indexer_vecs.height_to_timestamp,
|
||||
|(h, t, ..)| (h, Date::from(*t)),
|
||||
|(h, t, ..)| (h, Date::from(t)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -112,7 +112,10 @@ impl Vecs {
|
||||
.decremented()
|
||||
.and_then(|h| s.read(h).ok())
|
||||
.flatten()
|
||||
.map_or(*d, |prev_d| if prev_d > d { *prev_d } else { *d });
|
||||
.map_or(d, |prev_d| {
|
||||
let prev_d = *prev_d;
|
||||
if prev_d > d { prev_d } else { d }
|
||||
});
|
||||
(h, d)
|
||||
},
|
||||
exit,
|
||||
@@ -121,7 +124,7 @@ impl Vecs {
|
||||
self.height_to_dateindex.compute_transform(
|
||||
starting_indexes.height,
|
||||
&mut self.height_to_fixed_date,
|
||||
|(h, d, ..)| (h, Dateindex::try_from(*d).unwrap()),
|
||||
|(h, d, ..)| (h, Dateindex::try_from(d).unwrap()),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ impl Vecs {
|
||||
let ohlc = fetcher
|
||||
.get_height(
|
||||
h,
|
||||
*t,
|
||||
t,
|
||||
h.decremented().map(|prev_h| {
|
||||
height_to_timestamp
|
||||
.get(prev_h)
|
||||
@@ -215,7 +215,7 @@ impl Vecs {
|
||||
self.height_to_sats_per_dollar.compute_transform(
|
||||
starting_indexes.height,
|
||||
&mut self.height_to_close,
|
||||
|(di, close, ..)| (di, Close::from(Sats::ONE_BTC / **close)),
|
||||
|(di, close, ..)| (di, Close::from(Sats::ONE_BTC / *close)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -223,7 +223,7 @@ impl Vecs {
|
||||
starting_indexes.dateindex,
|
||||
&mut indexes.dateindex_to_date,
|
||||
|(di, d, ..)| {
|
||||
let ohlc = fetcher.get_date(*d).unwrap();
|
||||
let ohlc = fetcher.get_date(d).unwrap();
|
||||
(di, ohlc)
|
||||
},
|
||||
exit,
|
||||
@@ -295,7 +295,7 @@ impl Vecs {
|
||||
self.dateindex_to_sats_per_dollar.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
&mut self.dateindex_to_close,
|
||||
|(di, close, ..)| (di, Close::from(Sats::ONE_BTC / **close)),
|
||||
|(di, close, ..)| (di, Close::from(Sats::ONE_BTC / *close)),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user