computer: part 4

This commit is contained in:
nym21
2025-04-05 12:12:55 +02:00
parent 6b1863d3b4
commit 0d4f4aec4e
22 changed files with 822 additions and 750 deletions

View File

@@ -9,17 +9,19 @@ use std::{
use brk_core::CheckedSub;
use brk_exit::Exit;
use brk_vec::{AnyStorableVec, Compressed, Error, Result, StoredIndex, StoredType, Version};
use brk_vec::{
AnyStorableVec, Compressed, Error, Result, StorableVec, StoredIndex, StoredType, Version,
};
const FLUSH_EVERY: usize = 10_000;
#[derive(Debug)]
pub struct StorableVec<I, T> {
pub struct ComputedVec<I, T> {
computed_version: Option<Version>,
vec: brk_vec::StorableVec<I, T>,
vec: StorableVec<I, T>,
}
impl<I, T> StorableVec<I, T>
impl<I, T> ComputedVec<I, T>
where
I: StoredIndex,
T: StoredType,
@@ -316,7 +318,7 @@ where
}
}
impl<I, T> Clone for StorableVec<I, T>
impl<I, T> Clone for ComputedVec<I, T>
where
I: StoredIndex,
T: StoredType,

View File

@@ -1,21 +1,21 @@
use std::{fs, path::Path};
use brk_core::{CheckedSub, Dateindex, Height, Timestamp};
use brk_core::{CheckedSub, Dateindex, Timestamp};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyStorableVec, Compressed, Version};
use super::{
Indexes, StorableVec, indexes,
stats::{StorableVecGeneatorOptions, StorableVecsStatsFromHeight},
ComputedVec, Indexes,
grouped::{ComputedVecsFromHeight, StorableVecGeneatorOptions},
indexes,
};
#[derive(Clone)]
pub struct Vecs {
pub height_to_block_interval: StorableVec<Height, Timestamp>,
pub indexes_to_block_interval_stats: StorableVecsStatsFromHeight<Timestamp>,
pub dateindex_to_block_count: StorableVec<Dateindex, u16>,
pub dateindex_to_total_block_count: StorableVec<Dateindex, u32>,
pub indexes_to_block_interval: ComputedVecsFromHeight<Timestamp>,
pub dateindex_to_block_count: ComputedVec<Dateindex, u16>,
pub dateindex_to_total_block_count: ComputedVec<Dateindex, u32>,
}
impl Vecs {
@@ -23,25 +23,22 @@ impl Vecs {
fs::create_dir_all(path)?;
Ok(Self {
height_to_block_interval: StorableVec::forced_import(
&path.join("height_to_block_interval"),
indexes_to_block_interval: ComputedVecsFromHeight::forced_import(
path,
"block_interval",
Version::ONE,
compressed,
)?,
indexes_to_block_interval_stats: StorableVecsStatsFromHeight::forced_import(
&path.join("block_interval"),
compressed,
StorableVecGeneatorOptions::default()
.add_percentiles()
.add_minmax()
.add_average(),
)?,
dateindex_to_block_count: StorableVec::forced_import(
dateindex_to_block_count: ComputedVec::forced_import(
&path.join("dateindex_to_block_count"),
Version::ONE,
compressed,
)?,
dateindex_to_total_block_count: StorableVec::forced_import(
dateindex_to_total_block_count: ComputedVec::forced_import(
&path.join("dateindex_to_total_block_count"),
Version::ONE,
compressed,
@@ -58,23 +55,23 @@ impl Vecs {
) -> color_eyre::Result<()> {
let indexer_vecs = indexer.mut_vecs();
self.height_to_block_interval.compute_transform(
starting_indexes.height,
indexer_vecs.height_to_timestamp.mut_vec(),
|(height, timestamp, _, height_to_timestamp)| {
let interval = height.decremented().map_or(Timestamp::ZERO, |prev_h| {
let prev_timestamp = *height_to_timestamp.get(prev_h).unwrap().unwrap();
timestamp
.checked_sub(prev_timestamp)
.unwrap_or(Timestamp::ZERO)
});
(height, interval)
self.indexes_to_block_interval.compute(
|v| {
v.compute_transform(
starting_indexes.height,
indexer_vecs.height_to_timestamp.mut_vec(),
|(height, timestamp, _, height_to_timestamp)| {
let interval = height.decremented().map_or(Timestamp::ZERO, |prev_h| {
let prev_timestamp = *height_to_timestamp.get(prev_h).unwrap().unwrap();
timestamp
.checked_sub(prev_timestamp)
.unwrap_or(Timestamp::ZERO)
});
(height, interval)
},
exit,
)
},
exit,
)?;
self.indexes_to_block_interval_stats.compute(
&mut self.height_to_block_interval,
indexes,
starting_indexes,
exit,
@@ -86,11 +83,10 @@ impl Vecs {
pub fn as_any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[
vec![
self.height_to_block_interval.any_vec(),
self.dateindex_to_block_count.any_vec(),
self.dateindex_to_total_block_count.any_vec(),
],
self.indexes_to_block_interval_stats.as_any_vecs(),
self.indexes_to_block_interval.any_vecs(),
]
.concat()
}

View File

@@ -3,40 +3,41 @@ use std::path::Path;
use brk_exit::Exit;
use brk_vec::{AnyStorableVec, Compressed, Result, StoredIndex, StoredType, Version};
use crate::storage::vecs::base::StorableVec;
use crate::storage::vecs::base::ComputedVec;
use super::ComputedType;
#[derive(Clone, Debug)]
pub struct StorableVecBuilder<I, T>
pub struct ComputedVecBuilder<I, T>
where
I: StoredIndex,
T: ComputedType,
{
pub first: Option<StorableVec<I, T>>,
pub average: Option<StorableVec<I, T>>,
pub sum: Option<StorableVec<I, T>>,
pub max: Option<StorableVec<I, T>>,
pub _90p: Option<StorableVec<I, T>>,
pub _75p: Option<StorableVec<I, T>>,
pub median: Option<StorableVec<I, T>>,
pub _25p: Option<StorableVec<I, T>>,
pub _10p: Option<StorableVec<I, T>>,
pub min: Option<StorableVec<I, T>>,
pub last: Option<StorableVec<I, T>>,
pub first: Option<ComputedVec<I, T>>,
pub average: Option<ComputedVec<I, T>>,
pub sum: Option<ComputedVec<I, T>>,
pub max: Option<ComputedVec<I, T>>,
pub _90p: Option<ComputedVec<I, T>>,
pub _75p: Option<ComputedVec<I, T>>,
pub median: Option<ComputedVec<I, T>>,
pub _25p: Option<ComputedVec<I, T>>,
pub _10p: Option<ComputedVec<I, T>>,
pub min: Option<ComputedVec<I, T>>,
pub last: Option<ComputedVec<I, T>>,
}
impl<I, T> StorableVecBuilder<I, T>
impl<I, T> ComputedVecBuilder<I, T>
where
I: StoredIndex,
T: ComputedType,
{
pub fn forced_import(
path: &Path,
name: &str,
compressed: Compressed,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
let name = path.file_name().unwrap().to_str().unwrap().to_string();
// let name = path.file_name().unwrap().to_str().unwrap().to_string();
let key = I::to_string().split("::").last().unwrap().to_lowercase();
let only_one_active = options.is_only_one_active();
@@ -59,10 +60,10 @@ where
let s = Self {
first: options.first.then(|| {
StorableVec::forced_import(&prefix("first"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&prefix("first"), Version::ONE, compressed).unwrap()
}),
last: options.last.then(|| {
StorableVec::forced_import(
ComputedVec::forced_import(
&path.with_file_name(format!("{key}_to_{name}")),
Version::ONE,
compressed,
@@ -70,31 +71,31 @@ where
.unwrap()
}),
min: options.min.then(|| {
StorableVec::forced_import(&suffix("min"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&suffix("min"), Version::ONE, compressed).unwrap()
}),
max: options.max.then(|| {
StorableVec::forced_import(&suffix("max"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&suffix("max"), Version::ONE, compressed).unwrap()
}),
median: options.median.then(|| {
StorableVec::forced_import(&suffix("median"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&suffix("median"), Version::ONE, compressed).unwrap()
}),
average: options.average.then(|| {
StorableVec::forced_import(&suffix("average"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&suffix("average"), Version::ONE, compressed).unwrap()
}),
sum: options.sum.then(|| {
StorableVec::forced_import(&suffix("sum"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&suffix("sum"), Version::ONE, compressed).unwrap()
}),
_90p: options._90p.then(|| {
StorableVec::forced_import(&suffix("90p"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&suffix("90p"), Version::ONE, compressed).unwrap()
}),
_75p: options._75p.then(|| {
StorableVec::forced_import(&suffix("75p"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&suffix("75p"), Version::ONE, compressed).unwrap()
}),
_25p: options._25p.then(|| {
StorableVec::forced_import(&suffix("25p"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&suffix("25p"), Version::ONE, compressed).unwrap()
}),
_10p: options._10p.then(|| {
StorableVec::forced_import(&suffix("10p"), Version::ONE, compressed).unwrap()
ComputedVec::forced_import(&suffix("10p"), Version::ONE, compressed).unwrap()
}),
};
@@ -104,7 +105,7 @@ where
pub fn compute<I2>(
&mut self,
max_from: I,
source: &mut StorableVec<I2, T>,
source: &mut ComputedVec<I2, T>,
first_indexes: &mut brk_vec::StorableVec<I, I2>,
last_indexes: &mut brk_vec::StorableVec<I, I2>,
exit: &Exit,
@@ -211,7 +212,7 @@ where
pub fn from_aligned<I2>(
&mut self,
max_from: I,
source: &mut StorableVecBuilder<I2, T>,
source: &mut ComputedVecBuilder<I2, T>,
first_indexes: &mut brk_vec::StorableVec<I, I2>,
last_indexes: &mut brk_vec::StorableVec<I, I2>,
exit: &Exit,
@@ -352,15 +353,11 @@ where
fn starting_index(&self, max_from: I) -> I {
max_from.min(I::from(
self.as_any_vecs()
.into_iter()
.map(|v| v.len())
.min()
.unwrap(),
self.any_vecs().into_iter().map(|v| v.len()).min().unwrap(),
))
}
pub fn as_any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
pub fn any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
let mut v: Vec<&dyn AnyStorableVec> = vec![];
if let Some(first) = self.first.as_ref() {

View File

@@ -2,55 +2,68 @@ use std::path::Path;
use brk_core::{Dateindex, Decadeindex, Monthindex, Quarterindex, Weekindex, Yearindex};
use brk_exit::Exit;
use brk_vec::{AnyStorableVec, Compressed};
use brk_vec::{AnyStorableVec, Compressed, Result, Version};
use crate::storage::vecs::{Indexes, base::StorableVec, indexes};
use crate::storage::vecs::{Indexes, base::ComputedVec, indexes};
use super::{ComputedType, StorableVecBuilder, StorableVecGeneatorOptions};
use super::{ComputedType, ComputedVecBuilder, StorableVecGeneatorOptions};
#[derive(Clone)]
pub struct StorableVecsStatsFromDate<T>
pub struct ComputedVecsFromDateindex<T>
where
T: ComputedType + PartialOrd,
{
pub weekindex: StorableVecBuilder<Weekindex, T>,
pub monthindex: StorableVecBuilder<Monthindex, T>,
pub quarterindex: StorableVecBuilder<Quarterindex, T>,
pub yearindex: StorableVecBuilder<Yearindex, T>,
pub decadeindex: StorableVecBuilder<Decadeindex, T>,
pub dateindex: ComputedVec<Dateindex, T>,
pub weekindex: ComputedVecBuilder<Weekindex, T>,
pub monthindex: ComputedVecBuilder<Monthindex, T>,
pub quarterindex: ComputedVecBuilder<Quarterindex, T>,
pub yearindex: ComputedVecBuilder<Yearindex, T>,
pub decadeindex: ComputedVecBuilder<Decadeindex, T>,
}
impl<T> StorableVecsStatsFromDate<T>
impl<T> ComputedVecsFromDateindex<T>
where
T: ComputedType + Ord + From<f64>,
f64: From<T>,
{
pub fn forced_import(
path: &Path,
name: &str,
version: Version,
compressed: Compressed,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
let options = options.remove_percentiles();
Ok(Self {
weekindex: StorableVecBuilder::forced_import(path, compressed, options)?,
monthindex: StorableVecBuilder::forced_import(path, compressed, options)?,
quarterindex: StorableVecBuilder::forced_import(path, compressed, options)?,
yearindex: StorableVecBuilder::forced_import(path, compressed, options)?,
decadeindex: StorableVecBuilder::forced_import(path, compressed, options)?,
dateindex: ComputedVec::forced_import(
&path.join(format!("dateindex_to_{name}")),
version,
compressed,
)?,
weekindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
monthindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
quarterindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
yearindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
decadeindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
})
}
pub fn compute(
pub fn compute<F>(
&mut self,
source: &mut StorableVec<Dateindex, T>,
mut compute: F,
indexes: &mut indexes::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> color_eyre::Result<()> {
) -> color_eyre::Result<()>
where
F: FnMut(&mut ComputedVec<Dateindex, T>) -> Result<()>,
{
compute(&mut self.dateindex)?;
self.weekindex.compute(
starting_indexes.weekindex,
source,
&mut self.dateindex,
indexes.weekindex_to_first_dateindex.mut_vec(),
indexes.weekindex_to_last_dateindex.mut_vec(),
exit,
@@ -58,7 +71,7 @@ where
self.monthindex.compute(
starting_indexes.monthindex,
source,
&mut self.dateindex,
indexes.monthindex_to_first_dateindex.mut_vec(),
indexes.monthindex_to_last_dateindex.mut_vec(),
exit,
@@ -91,13 +104,14 @@ where
Ok(())
}
pub fn as_any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
pub fn any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[
self.weekindex.as_any_vecs(),
self.monthindex.as_any_vecs(),
self.quarterindex.as_any_vecs(),
self.yearindex.as_any_vecs(),
self.decadeindex.as_any_vecs(),
vec![self.dateindex.any_vec()],
self.weekindex.any_vecs(),
self.monthindex.any_vecs(),
self.quarterindex.any_vecs(),
self.yearindex.any_vecs(),
self.decadeindex.any_vecs(),
]
.concat()
}

View File

@@ -4,63 +4,78 @@ use brk_core::{
Dateindex, Decadeindex, Difficultyepoch, Height, Monthindex, Quarterindex, Weekindex, Yearindex,
};
use brk_exit::Exit;
use brk_vec::{AnyStorableVec, Compressed};
use brk_vec::{AnyStorableVec, Compressed, Result, Version};
use crate::storage::vecs::{Indexes, base::StorableVec, indexes};
use crate::storage::vecs::{Indexes, base::ComputedVec, indexes};
use super::{ComputedType, StorableVecBuilder, StorableVecGeneatorOptions};
use super::{ComputedType, ComputedVecBuilder, StorableVecGeneatorOptions};
#[derive(Clone)]
pub struct StorableVecsStatsFromHeight<T>
pub struct ComputedVecsFromHeight<T>
where
T: ComputedType + PartialOrd,
{
pub dateindex: StorableVecBuilder<Dateindex, T>,
pub weekindex: StorableVecBuilder<Weekindex, T>,
pub difficultyepoch: StorableVecBuilder<Difficultyepoch, T>,
pub monthindex: StorableVecBuilder<Monthindex, T>,
pub quarterindex: StorableVecBuilder<Quarterindex, T>,
pub yearindex: StorableVecBuilder<Yearindex, T>,
pub height: ComputedVec<Height, T>,
pub dateindex: ComputedVecBuilder<Dateindex, T>,
pub weekindex: ComputedVecBuilder<Weekindex, T>,
pub difficultyepoch: ComputedVecBuilder<Difficultyepoch, T>,
pub monthindex: ComputedVecBuilder<Monthindex, T>,
pub quarterindex: ComputedVecBuilder<Quarterindex, T>,
pub yearindex: ComputedVecBuilder<Yearindex, T>,
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
pub decadeindex: StorableVecBuilder<Decadeindex, T>,
pub decadeindex: ComputedVecBuilder<Decadeindex, T>,
}
impl<T> StorableVecsStatsFromHeight<T>
impl<T> ComputedVecsFromHeight<T>
where
T: ComputedType + Ord + From<f64>,
f64: From<T>,
{
pub fn forced_import(
path: &Path,
name: &str,
version: Version,
compressed: Compressed,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
let dateindex = StorableVecBuilder::forced_import(path, compressed, options)?;
let height = ComputedVec::forced_import(
&path.join(format!("height_to_{name}")),
version,
compressed,
)?;
let dateindex = ComputedVecBuilder::forced_import(path, name, compressed, options)?;
let options = options.remove_percentiles();
Ok(Self {
height,
dateindex,
weekindex: StorableVecBuilder::forced_import(path, compressed, options)?,
difficultyepoch: StorableVecBuilder::forced_import(path, compressed, options)?,
monthindex: StorableVecBuilder::forced_import(path, compressed, options)?,
quarterindex: StorableVecBuilder::forced_import(path, compressed, options)?,
yearindex: StorableVecBuilder::forced_import(path, compressed, options)?,
// halvingepoch: StorableVecGeneator::forced_import(path, compressed, options)?,
decadeindex: StorableVecBuilder::forced_import(path, compressed, options)?,
weekindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
difficultyepoch: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
monthindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
quarterindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
yearindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
// halvingepoch: StorableVecGeneator::forced_import(path, name, compressed, options)?,
decadeindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
})
}
pub fn compute(
pub fn compute<F>(
&mut self,
source: &mut StorableVec<Height, T>,
mut compute: F,
indexes: &mut indexes::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> color_eyre::Result<()> {
) -> color_eyre::Result<()>
where
F: FnMut(&mut ComputedVec<Height, T>) -> Result<()>,
{
compute(&mut self.height)?;
self.dateindex.compute(
starting_indexes.dateindex,
source,
&mut self.height,
indexes.dateindex_to_first_height.mut_vec(),
indexes.dateindex_to_last_height.mut_vec(),
exit,
@@ -108,7 +123,7 @@ where
self.difficultyepoch.compute(
starting_indexes.difficultyepoch,
source,
&mut self.height,
indexes.difficultyepoch_to_first_height.mut_vec(),
indexes.difficultyepoch_to_last_height.mut_vec(),
exit,
@@ -117,16 +132,17 @@ where
Ok(())
}
pub fn as_any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
pub fn any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[
self.dateindex.as_any_vecs(),
self.weekindex.as_any_vecs(),
self.difficultyepoch.as_any_vecs(),
self.monthindex.as_any_vecs(),
self.quarterindex.as_any_vecs(),
self.yearindex.as_any_vecs(),
vec![self.height.any_vec()],
self.dateindex.any_vecs(),
self.weekindex.any_vecs(),
self.difficultyepoch.any_vecs(),
self.monthindex.any_vecs(),
self.quarterindex.any_vecs(),
self.yearindex.any_vecs(),
// self.halvingepoch.as_any_vecs(),
self.decadeindex.as_any_vecs(),
self.decadeindex.any_vecs(),
]
.concat()
}

View File

@@ -0,0 +1,79 @@
use std::path::Path;
use brk_core::{Difficultyepoch, Height};
use brk_exit::Exit;
use brk_vec::{AnyStorableVec, Compressed, Result, Version};
use crate::storage::vecs::{Indexes, base::ComputedVec, indexes};
use super::{ComputedType, ComputedVecBuilder, StorableVecGeneatorOptions};
#[derive(Clone)]
pub struct ComputedVecsFromHeightStrict<T>
where
T: ComputedType + PartialOrd,
{
pub height: ComputedVec<Height, T>,
pub difficultyepoch: ComputedVecBuilder<Difficultyepoch, T>,
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
}
impl<T> ComputedVecsFromHeightStrict<T>
where
T: ComputedType + Ord + From<f64>,
f64: From<T>,
{
pub fn forced_import(
path: &Path,
name: &str,
version: Version,
compressed: Compressed,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
let height = ComputedVec::forced_import(
&path.join(format!("height_to_{name}")),
version,
compressed,
)?;
let options = options.remove_percentiles();
Ok(Self {
height,
difficultyepoch: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
// halvingepoch: StorableVecGeneator::forced_import(path, name, compressed, options)?,
})
}
pub fn compute<F>(
&mut self,
mut compute: F,
indexes: &mut indexes::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> color_eyre::Result<()>
where
F: FnMut(&mut ComputedVec<Height, T>) -> Result<()>,
{
compute(&mut self.height)?;
self.difficultyepoch.compute(
starting_indexes.difficultyepoch,
&mut self.height,
indexes.difficultyepoch_to_first_height.mut_vec(),
indexes.difficultyepoch_to_last_height.mut_vec(),
exit,
)?;
Ok(())
}
pub fn any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[
vec![self.height.any_vec()],
self.difficultyepoch.any_vecs(),
// self.halvingepoch.as_any_vecs(),
]
.concat()
}
}

View File

@@ -0,0 +1,164 @@
use std::path::Path;
use brk_core::{
Dateindex, Decadeindex, Difficultyepoch, Height, Monthindex, Quarterindex, Txindex, Weekindex,
Yearindex,
};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyStorableVec, Compressed, Result, Version};
use crate::storage::vecs::{Indexes, base::ComputedVec, indexes};
use super::{ComputedType, ComputedVecBuilder, StorableVecGeneatorOptions};
#[derive(Clone)]
pub struct ComputedVecsFromTxindex<T>
where
T: ComputedType + PartialOrd,
{
pub txindex: ComputedVec<Txindex, T>,
pub height: ComputedVecBuilder<Height, T>,
pub dateindex: ComputedVecBuilder<Dateindex, T>,
pub weekindex: ComputedVecBuilder<Weekindex, T>,
pub difficultyepoch: ComputedVecBuilder<Difficultyepoch, T>,
pub monthindex: ComputedVecBuilder<Monthindex, T>,
pub quarterindex: ComputedVecBuilder<Quarterindex, T>,
pub yearindex: ComputedVecBuilder<Yearindex, T>,
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
pub decadeindex: ComputedVecBuilder<Decadeindex, T>,
}
impl<T> ComputedVecsFromTxindex<T>
where
T: ComputedType + Ord + From<f64>,
f64: From<T>,
{
pub fn forced_import(
path: &Path,
name: &str,
version: Version,
compressed: Compressed,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
let txindex = ComputedVec::forced_import(
&path.join(format!("txindex_to_{name}")),
version,
compressed,
)?;
let height = ComputedVecBuilder::forced_import(path, name, compressed, options)?;
let dateindex = ComputedVecBuilder::forced_import(path, name, compressed, options)?;
let options = options.remove_percentiles();
Ok(Self {
txindex,
height,
dateindex,
weekindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
difficultyepoch: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
monthindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
quarterindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
yearindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
// halvingepoch: StorableVecGeneator::forced_import(path, name, compressed, options)?,
decadeindex: ComputedVecBuilder::forced_import(path, name, compressed, options)?,
})
}
pub fn compute<F>(
&mut self,
mut compute: F,
indexer: &mut Indexer,
indexes: &mut indexes::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> color_eyre::Result<()>
where
F: FnMut(&mut ComputedVec<Txindex, T>) -> Result<()>,
{
compute(&mut self.txindex)?;
self.height.compute(
starting_indexes.height,
&mut self.txindex,
indexer.mut_vecs().height_to_first_txindex.mut_vec(),
indexes.height_to_last_txindex.mut_vec(),
exit,
)?;
self.dateindex.from_aligned(
starting_indexes.dateindex,
&mut self.height,
indexes.dateindex_to_first_height.mut_vec(),
indexes.dateindex_to_last_height.mut_vec(),
exit,
)?;
self.weekindex.from_aligned(
starting_indexes.weekindex,
&mut self.dateindex,
indexes.weekindex_to_first_dateindex.mut_vec(),
indexes.weekindex_to_last_dateindex.mut_vec(),
exit,
)?;
self.monthindex.from_aligned(
starting_indexes.monthindex,
&mut self.dateindex,
indexes.monthindex_to_first_dateindex.mut_vec(),
indexes.monthindex_to_last_dateindex.mut_vec(),
exit,
)?;
self.quarterindex.from_aligned(
starting_indexes.quarterindex,
&mut self.monthindex,
indexes.quarterindex_to_first_monthindex.mut_vec(),
indexes.quarterindex_to_last_monthindex.mut_vec(),
exit,
)?;
self.yearindex.from_aligned(
starting_indexes.yearindex,
&mut self.monthindex,
indexes.yearindex_to_first_monthindex.mut_vec(),
indexes.yearindex_to_last_monthindex.mut_vec(),
exit,
)?;
self.decadeindex.from_aligned(
starting_indexes.decadeindex,
&mut self.yearindex,
indexes.decadeindex_to_first_yearindex.mut_vec(),
indexes.decadeindex_to_last_yearindex.mut_vec(),
exit,
)?;
self.difficultyepoch.from_aligned(
starting_indexes.difficultyepoch,
&mut self.height,
indexes.difficultyepoch_to_first_height.mut_vec(),
indexes.difficultyepoch_to_last_height.mut_vec(),
exit,
)?;
Ok(())
}
pub fn any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[
vec![self.txindex.any_vec()],
self.height.any_vecs(),
self.dateindex.any_vecs(),
self.weekindex.any_vecs(),
self.difficultyepoch.any_vecs(),
self.monthindex.any_vecs(),
self.quarterindex.any_vecs(),
self.yearindex.any_vecs(),
// self.halvingepoch.as_any_vecs(),
self.decadeindex.any_vecs(),
]
.concat()
}
}

View File

@@ -1,11 +1,13 @@
mod from_date;
mod builder;
mod from_dateindex;
mod from_height;
mod from_height_strict;
mod generic;
mod from_txindex;
mod stored_type;
pub use from_date::*;
pub use builder::*;
pub use from_dateindex::*;
pub use from_height::*;
pub use from_height_strict::*;
pub use generic::*;
pub use from_txindex::*;
pub use stored_type::*;

View File

@@ -8,60 +8,60 @@ use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyStorableVec, Compressed, Version};
use super::StorableVec;
use super::ComputedVec;
#[derive(Clone)]
pub struct Vecs {
// pub height_to_last_addressindex: StorableVec<Height, Addressindex>,
// pub height_to_last_txoutindex: StorableVec<Height, Txoutindex>,
pub dateindex_to_date: StorableVec<Dateindex, Date>,
pub dateindex_to_dateindex: StorableVec<Dateindex, Dateindex>,
pub dateindex_to_first_height: StorableVec<Dateindex, Height>,
pub dateindex_to_last_height: StorableVec<Dateindex, Height>,
pub dateindex_to_monthindex: StorableVec<Dateindex, Monthindex>,
pub dateindex_to_timestamp: StorableVec<Dateindex, Timestamp>,
pub dateindex_to_weekindex: StorableVec<Dateindex, Weekindex>,
pub decadeindex_to_decadeindex: StorableVec<Decadeindex, Decadeindex>,
pub decadeindex_to_first_yearindex: StorableVec<Decadeindex, Yearindex>,
pub decadeindex_to_last_yearindex: StorableVec<Decadeindex, Yearindex>,
pub decadeindex_to_timestamp: StorableVec<Decadeindex, Timestamp>,
pub difficultyepoch_to_difficultyepoch: StorableVec<Difficultyepoch, Difficultyepoch>,
pub difficultyepoch_to_first_height: StorableVec<Difficultyepoch, Height>,
pub difficultyepoch_to_last_height: StorableVec<Difficultyepoch, Height>,
pub difficultyepoch_to_timestamp: StorableVec<Difficultyepoch, Timestamp>,
pub halvingepoch_to_first_height: StorableVec<Halvingepoch, Height>,
pub halvingepoch_to_halvingepoch: StorableVec<Halvingepoch, Halvingepoch>,
pub halvingepoch_to_last_height: StorableVec<Halvingepoch, Height>,
pub halvingepoch_to_timestamp: StorableVec<Halvingepoch, Timestamp>,
pub height_to_dateindex: StorableVec<Height, Dateindex>,
pub height_to_difficultyepoch: StorableVec<Height, Difficultyepoch>,
pub height_to_fixed_date: StorableVec<Height, Date>,
pub height_to_fixed_timestamp: StorableVec<Height, Timestamp>,
pub height_to_halvingepoch: StorableVec<Height, Halvingepoch>,
pub height_to_height: StorableVec<Height, Height>,
pub height_to_last_txindex: StorableVec<Height, Txindex>,
pub height_to_real_date: StorableVec<Height, Date>,
pub monthindex_to_first_dateindex: StorableVec<Monthindex, Dateindex>,
pub monthindex_to_last_dateindex: StorableVec<Monthindex, Dateindex>,
pub monthindex_to_monthindex: StorableVec<Monthindex, Monthindex>,
pub monthindex_to_quarterindex: StorableVec<Monthindex, Quarterindex>,
pub monthindex_to_timestamp: StorableVec<Monthindex, Timestamp>,
pub monthindex_to_yearindex: StorableVec<Monthindex, Yearindex>,
pub quarterindex_to_first_monthindex: StorableVec<Quarterindex, Monthindex>,
pub quarterindex_to_last_monthindex: StorableVec<Quarterindex, Monthindex>,
pub quarterindex_to_quarterindex: StorableVec<Quarterindex, Quarterindex>,
pub quarterindex_to_timestamp: StorableVec<Quarterindex, Timestamp>,
pub txindex_to_last_txinindex: StorableVec<Txindex, Txinindex>,
pub txindex_to_last_txoutindex: StorableVec<Txindex, Txoutindex>,
pub weekindex_to_first_dateindex: StorableVec<Weekindex, Dateindex>,
pub weekindex_to_last_dateindex: StorableVec<Weekindex, Dateindex>,
pub weekindex_to_timestamp: StorableVec<Weekindex, Timestamp>,
pub weekindex_to_weekindex: StorableVec<Weekindex, Weekindex>,
pub yearindex_to_decadeindex: StorableVec<Yearindex, Decadeindex>,
pub yearindex_to_first_monthindex: StorableVec<Yearindex, Monthindex>,
pub yearindex_to_last_monthindex: StorableVec<Yearindex, Monthindex>,
pub yearindex_to_timestamp: StorableVec<Yearindex, Timestamp>,
pub yearindex_to_yearindex: StorableVec<Yearindex, Yearindex>,
pub dateindex_to_date: ComputedVec<Dateindex, Date>,
pub dateindex_to_dateindex: ComputedVec<Dateindex, Dateindex>,
pub dateindex_to_first_height: ComputedVec<Dateindex, Height>,
pub dateindex_to_last_height: ComputedVec<Dateindex, Height>,
pub dateindex_to_monthindex: ComputedVec<Dateindex, Monthindex>,
pub dateindex_to_timestamp: ComputedVec<Dateindex, Timestamp>,
pub dateindex_to_weekindex: ComputedVec<Dateindex, Weekindex>,
pub decadeindex_to_decadeindex: ComputedVec<Decadeindex, Decadeindex>,
pub decadeindex_to_first_yearindex: ComputedVec<Decadeindex, Yearindex>,
pub decadeindex_to_last_yearindex: ComputedVec<Decadeindex, Yearindex>,
pub decadeindex_to_timestamp: ComputedVec<Decadeindex, Timestamp>,
pub difficultyepoch_to_difficultyepoch: ComputedVec<Difficultyepoch, Difficultyepoch>,
pub difficultyepoch_to_first_height: ComputedVec<Difficultyepoch, Height>,
pub difficultyepoch_to_last_height: ComputedVec<Difficultyepoch, Height>,
pub difficultyepoch_to_timestamp: ComputedVec<Difficultyepoch, Timestamp>,
pub halvingepoch_to_first_height: ComputedVec<Halvingepoch, Height>,
pub halvingepoch_to_halvingepoch: ComputedVec<Halvingepoch, Halvingepoch>,
pub halvingepoch_to_last_height: ComputedVec<Halvingepoch, Height>,
pub halvingepoch_to_timestamp: ComputedVec<Halvingepoch, Timestamp>,
pub height_to_dateindex: ComputedVec<Height, Dateindex>,
pub height_to_difficultyepoch: ComputedVec<Height, Difficultyepoch>,
pub height_to_fixed_date: ComputedVec<Height, Date>,
pub height_to_fixed_timestamp: ComputedVec<Height, Timestamp>,
pub height_to_halvingepoch: ComputedVec<Height, Halvingepoch>,
pub height_to_height: ComputedVec<Height, Height>,
pub height_to_last_txindex: ComputedVec<Height, Txindex>,
pub height_to_real_date: ComputedVec<Height, Date>,
pub monthindex_to_first_dateindex: ComputedVec<Monthindex, Dateindex>,
pub monthindex_to_last_dateindex: ComputedVec<Monthindex, Dateindex>,
pub monthindex_to_monthindex: ComputedVec<Monthindex, Monthindex>,
pub monthindex_to_quarterindex: ComputedVec<Monthindex, Quarterindex>,
pub monthindex_to_timestamp: ComputedVec<Monthindex, Timestamp>,
pub monthindex_to_yearindex: ComputedVec<Monthindex, Yearindex>,
pub quarterindex_to_first_monthindex: ComputedVec<Quarterindex, Monthindex>,
pub quarterindex_to_last_monthindex: ComputedVec<Quarterindex, Monthindex>,
pub quarterindex_to_quarterindex: ComputedVec<Quarterindex, Quarterindex>,
pub quarterindex_to_timestamp: ComputedVec<Quarterindex, Timestamp>,
pub txindex_to_last_txinindex: ComputedVec<Txindex, Txinindex>,
pub txindex_to_last_txoutindex: ComputedVec<Txindex, Txoutindex>,
pub weekindex_to_first_dateindex: ComputedVec<Weekindex, Dateindex>,
pub weekindex_to_last_dateindex: ComputedVec<Weekindex, Dateindex>,
pub weekindex_to_timestamp: ComputedVec<Weekindex, Timestamp>,
pub weekindex_to_weekindex: ComputedVec<Weekindex, Weekindex>,
pub yearindex_to_decadeindex: ComputedVec<Yearindex, Decadeindex>,
pub yearindex_to_first_monthindex: ComputedVec<Yearindex, Monthindex>,
pub yearindex_to_last_monthindex: ComputedVec<Yearindex, Monthindex>,
pub yearindex_to_timestamp: ComputedVec<Yearindex, Timestamp>,
pub yearindex_to_yearindex: ComputedVec<Yearindex, Yearindex>,
}
impl Vecs {
@@ -69,242 +69,242 @@ impl Vecs {
fs::create_dir_all(path)?;
Ok(Self {
dateindex_to_date: StorableVec::forced_import(
dateindex_to_date: ComputedVec::forced_import(
&path.join("dateindex_to_date"),
Version::ONE,
compressed,
)?,
dateindex_to_dateindex: StorableVec::forced_import(
dateindex_to_dateindex: ComputedVec::forced_import(
&path.join("dateindex_to_dateindex"),
Version::ONE,
compressed,
)?,
dateindex_to_first_height: StorableVec::forced_import(
dateindex_to_first_height: ComputedVec::forced_import(
&path.join("dateindex_to_first_height"),
Version::ONE,
compressed,
)?,
dateindex_to_last_height: StorableVec::forced_import(
dateindex_to_last_height: ComputedVec::forced_import(
&path.join("dateindex_to_last_height"),
Version::ONE,
compressed,
)?,
height_to_real_date: StorableVec::forced_import(
height_to_real_date: ComputedVec::forced_import(
&path.join("height_to_real_date"),
Version::ONE,
compressed,
)?,
height_to_fixed_date: StorableVec::forced_import(
height_to_fixed_date: ComputedVec::forced_import(
&path.join("height_to_fixed_date"),
Version::ONE,
compressed,
)?,
height_to_dateindex: StorableVec::forced_import(
height_to_dateindex: ComputedVec::forced_import(
&path.join("height_to_dateindex"),
Version::ONE,
compressed,
)?,
height_to_height: StorableVec::forced_import(
height_to_height: ComputedVec::forced_import(
&path.join("height_to_height"),
Version::ONE,
compressed,
)?,
height_to_last_txindex: StorableVec::forced_import(
height_to_last_txindex: ComputedVec::forced_import(
&path.join("height_to_last_txindex"),
Version::ONE,
compressed,
)?,
txindex_to_last_txinindex: StorableVec::forced_import(
txindex_to_last_txinindex: ComputedVec::forced_import(
&path.join("txindex_to_last_txinindex"),
Version::ONE,
compressed,
)?,
txindex_to_last_txoutindex: StorableVec::forced_import(
txindex_to_last_txoutindex: ComputedVec::forced_import(
&path.join("txindex_to_last_txoutindex"),
Version::ONE,
compressed,
)?,
difficultyepoch_to_first_height: StorableVec::forced_import(
difficultyepoch_to_first_height: ComputedVec::forced_import(
&path.join("difficultyepoch_to_first_height"),
Version::ONE,
compressed,
)?,
difficultyepoch_to_last_height: StorableVec::forced_import(
difficultyepoch_to_last_height: ComputedVec::forced_import(
&path.join("difficultyepoch_to_last_height"),
Version::ONE,
compressed,
)?,
halvingepoch_to_first_height: StorableVec::forced_import(
halvingepoch_to_first_height: ComputedVec::forced_import(
&path.join("halvingepoch_to_first_height"),
Version::ONE,
compressed,
)?,
halvingepoch_to_last_height: StorableVec::forced_import(
halvingepoch_to_last_height: ComputedVec::forced_import(
&path.join("halvingepoch_to_last_height"),
Version::ONE,
compressed,
)?,
weekindex_to_first_dateindex: StorableVec::forced_import(
weekindex_to_first_dateindex: ComputedVec::forced_import(
&path.join("weekindex_to_first_dateindex"),
Version::ONE,
compressed,
)?,
weekindex_to_last_dateindex: StorableVec::forced_import(
weekindex_to_last_dateindex: ComputedVec::forced_import(
&path.join("weekindex_to_last_dateindex"),
Version::ONE,
compressed,
)?,
monthindex_to_first_dateindex: StorableVec::forced_import(
monthindex_to_first_dateindex: ComputedVec::forced_import(
&path.join("monthindex_to_first_dateindex"),
Version::ONE,
compressed,
)?,
monthindex_to_last_dateindex: StorableVec::forced_import(
monthindex_to_last_dateindex: ComputedVec::forced_import(
&path.join("monthindex_to_last_dateindex"),
Version::ONE,
compressed,
)?,
yearindex_to_first_monthindex: StorableVec::forced_import(
yearindex_to_first_monthindex: ComputedVec::forced_import(
&path.join("yearindex_to_first_monthindex"),
Version::ONE,
compressed,
)?,
yearindex_to_last_monthindex: StorableVec::forced_import(
yearindex_to_last_monthindex: ComputedVec::forced_import(
&path.join("yearindex_to_last_monthindex"),
Version::ONE,
compressed,
)?,
decadeindex_to_first_yearindex: StorableVec::forced_import(
decadeindex_to_first_yearindex: ComputedVec::forced_import(
&path.join("decadeindex_to_first_yearindex"),
Version::ONE,
compressed,
)?,
decadeindex_to_last_yearindex: StorableVec::forced_import(
decadeindex_to_last_yearindex: ComputedVec::forced_import(
&path.join("decadeindex_to_last_yearindex"),
Version::ONE,
compressed,
)?,
dateindex_to_weekindex: StorableVec::forced_import(
dateindex_to_weekindex: ComputedVec::forced_import(
&path.join("dateindex_to_weekindex"),
Version::ONE,
compressed,
)?,
dateindex_to_monthindex: StorableVec::forced_import(
dateindex_to_monthindex: ComputedVec::forced_import(
&path.join("dateindex_to_monthindex"),
Version::ONE,
compressed,
)?,
monthindex_to_yearindex: StorableVec::forced_import(
monthindex_to_yearindex: ComputedVec::forced_import(
&path.join("monthindex_to_yearindex"),
Version::ONE,
compressed,
)?,
yearindex_to_decadeindex: StorableVec::forced_import(
yearindex_to_decadeindex: ComputedVec::forced_import(
&path.join("yearindex_to_decadeindex"),
Version::ONE,
compressed,
)?,
height_to_difficultyepoch: StorableVec::forced_import(
height_to_difficultyepoch: ComputedVec::forced_import(
&path.join("height_to_difficultyepoch"),
Version::ONE,
compressed,
)?,
height_to_halvingepoch: StorableVec::forced_import(
height_to_halvingepoch: ComputedVec::forced_import(
&path.join("height_to_halvingepoch"),
Version::ONE,
compressed,
)?,
weekindex_to_weekindex: StorableVec::forced_import(
weekindex_to_weekindex: ComputedVec::forced_import(
&path.join("weekindex_to_weekindex"),
Version::ONE,
compressed,
)?,
monthindex_to_monthindex: StorableVec::forced_import(
monthindex_to_monthindex: ComputedVec::forced_import(
&path.join("monthindex_to_monthindex"),
Version::ONE,
compressed,
)?,
yearindex_to_yearindex: StorableVec::forced_import(
yearindex_to_yearindex: ComputedVec::forced_import(
&path.join("yearindex_to_yearindex"),
Version::ONE,
compressed,
)?,
decadeindex_to_decadeindex: StorableVec::forced_import(
decadeindex_to_decadeindex: ComputedVec::forced_import(
&path.join("decadeindex_to_decadeindex"),
Version::ONE,
compressed,
)?,
difficultyepoch_to_difficultyepoch: StorableVec::forced_import(
difficultyepoch_to_difficultyepoch: ComputedVec::forced_import(
&path.join("difficultyepoch_to_difficultyepoch"),
Version::ONE,
compressed,
)?,
halvingepoch_to_halvingepoch: StorableVec::forced_import(
halvingepoch_to_halvingepoch: ComputedVec::forced_import(
&path.join("halvingepoch_to_halvingepoch"),
Version::ONE,
compressed,
)?,
dateindex_to_timestamp: StorableVec::forced_import(
dateindex_to_timestamp: ComputedVec::forced_import(
&path.join("dateindex_to_timestamp"),
Version::ONE,
compressed,
)?,
decadeindex_to_timestamp: StorableVec::forced_import(
decadeindex_to_timestamp: ComputedVec::forced_import(
&path.join("decadeindex_to_timestamp"),
Version::ONE,
compressed,
)?,
difficultyepoch_to_timestamp: StorableVec::forced_import(
difficultyepoch_to_timestamp: ComputedVec::forced_import(
&path.join("difficultyepoch_to_timestamp"),
Version::ONE,
compressed,
)?,
halvingepoch_to_timestamp: StorableVec::forced_import(
halvingepoch_to_timestamp: ComputedVec::forced_import(
&path.join("halvingepoch_to_timestamp"),
Version::ONE,
compressed,
)?,
monthindex_to_timestamp: StorableVec::forced_import(
monthindex_to_timestamp: ComputedVec::forced_import(
&path.join("monthindex_to_timestamp"),
Version::ONE,
compressed,
)?,
weekindex_to_timestamp: StorableVec::forced_import(
weekindex_to_timestamp: ComputedVec::forced_import(
&path.join("weekindex_to_timestamp"),
Version::ONE,
compressed,
)?,
yearindex_to_timestamp: StorableVec::forced_import(
yearindex_to_timestamp: ComputedVec::forced_import(
&path.join("yearindex_to_timestamp"),
Version::ONE,
compressed,
)?,
height_to_fixed_timestamp: StorableVec::forced_import(
height_to_fixed_timestamp: ComputedVec::forced_import(
&path.join("height_to_fixed_timestamp"),
Version::ONE,
compressed,
)?,
monthindex_to_quarterindex: StorableVec::forced_import(
monthindex_to_quarterindex: ComputedVec::forced_import(
&path.join("monthindex_to_quarterindex"),
Version::ONE,
compressed,
)?,
quarterindex_to_first_monthindex: StorableVec::forced_import(
quarterindex_to_first_monthindex: ComputedVec::forced_import(
&path.join("quarterindex_to_first_monthindex"),
Version::ONE,
compressed,
)?,
quarterindex_to_last_monthindex: StorableVec::forced_import(
quarterindex_to_last_monthindex: ComputedVec::forced_import(
&path.join("quarterindex_to_last_monthindex"),
Version::ONE,
compressed,
)?,
quarterindex_to_quarterindex: StorableVec::forced_import(
quarterindex_to_quarterindex: ComputedVec::forced_import(
&path.join("quarterindex_to_quarterindex"),
Version::ONE,
compressed,
)?,
quarterindex_to_timestamp: StorableVec::forced_import(
quarterindex_to_timestamp: ComputedVec::forced_import(
&path.join("quarterindex_to_timestamp"),
Version::ONE,
compressed,

View File

@@ -10,53 +10,45 @@ use brk_indexer::Indexer;
use brk_vec::{AnyStorableVec, Compressed, Version};
use super::{
Indexes, StorableVec, indexes,
stats::{
StorableVecGeneatorOptions, StorableVecsStatsFromDate, StorableVecsStatsFromHeightStrict,
ComputedVec, Indexes,
grouped::{
ComputedVecsFromDateindex, ComputedVecsFromHeightStrict, StorableVecGeneatorOptions,
},
indexes,
};
#[derive(Clone)]
pub struct Vecs {
pub dateindex_to_close: StorableVec<Dateindex, Close<Dollars>>,
pub dateindex_to_close_in_cents: StorableVec<Dateindex, Close<Cents>>,
pub dateindex_to_high: StorableVec<Dateindex, High<Dollars>>,
pub dateindex_to_high_in_cents: StorableVec<Dateindex, High<Cents>>,
pub dateindex_to_low: StorableVec<Dateindex, Low<Dollars>>,
pub dateindex_to_low_in_cents: StorableVec<Dateindex, Low<Cents>>,
pub dateindex_to_ohlc: StorableVec<Dateindex, OHLCDollars>,
pub dateindex_to_ohlc_in_cents: StorableVec<Dateindex, OHLCCents>,
pub dateindex_to_open: StorableVec<Dateindex, Open<Dollars>>,
pub dateindex_to_open_in_cents: StorableVec<Dateindex, Open<Cents>>,
pub dateindex_to_sats_per_dollar: StorableVec<Dateindex, Close<Sats>>,
pub height_to_close: StorableVec<Height, Close<Dollars>>,
pub height_to_close_in_cents: StorableVec<Height, Close<Cents>>,
pub height_to_high: StorableVec<Height, High<Dollars>>,
pub height_to_high_in_cents: StorableVec<Height, High<Cents>>,
pub height_to_low: StorableVec<Height, Low<Dollars>>,
pub height_to_low_in_cents: StorableVec<Height, Low<Cents>>,
pub height_to_ohlc: StorableVec<Height, OHLCDollars>,
pub height_to_ohlc_in_cents: StorableVec<Height, OHLCCents>,
pub height_to_open: StorableVec<Height, Open<Dollars>>,
pub height_to_open_in_cents: StorableVec<Height, Open<Cents>>,
pub height_to_sats_per_dollar: StorableVec<Height, Close<Sats>>,
pub timeindexes_to_close: StorableVecsStatsFromDate<Close<Dollars>>,
pub timeindexes_to_high: StorableVecsStatsFromDate<High<Dollars>>,
pub timeindexes_to_low: StorableVecsStatsFromDate<Low<Dollars>>,
pub timeindexes_to_open: StorableVecsStatsFromDate<Open<Dollars>>,
pub timeindexes_to_sats_per_dollar: StorableVecsStatsFromDate<Close<Sats>>,
pub chainindexes_to_close: StorableVecsStatsFromHeightStrict<Close<Dollars>>,
pub chainindexes_to_high: StorableVecsStatsFromHeightStrict<High<Dollars>>,
pub chainindexes_to_low: StorableVecsStatsFromHeightStrict<Low<Dollars>>,
pub chainindexes_to_open: StorableVecsStatsFromHeightStrict<Open<Dollars>>,
pub chainindexes_to_sats_per_dollar: StorableVecsStatsFromHeightStrict<Close<Sats>>,
pub weekindex_to_ohlc: StorableVec<Weekindex, OHLCDollars>,
pub difficultyepoch_to_ohlc: StorableVec<Difficultyepoch, OHLCDollars>,
pub monthindex_to_ohlc: StorableVec<Monthindex, OHLCDollars>,
pub quarterindex_to_ohlc: StorableVec<Quarterindex, OHLCDollars>,
pub yearindex_to_ohlc: StorableVec<Yearindex, OHLCDollars>,
// pub dateindex_to_close: ComputedVec<Dateindex, Close<Dollars>>,
pub dateindex_to_close_in_cents: ComputedVec<Dateindex, Close<Cents>>,
pub dateindex_to_high_in_cents: ComputedVec<Dateindex, High<Cents>>,
pub dateindex_to_low_in_cents: ComputedVec<Dateindex, Low<Cents>>,
pub dateindex_to_ohlc: ComputedVec<Dateindex, OHLCDollars>,
pub dateindex_to_ohlc_in_cents: ComputedVec<Dateindex, OHLCCents>,
pub dateindex_to_open_in_cents: ComputedVec<Dateindex, Open<Cents>>,
pub height_to_close_in_cents: ComputedVec<Height, Close<Cents>>,
pub height_to_high_in_cents: ComputedVec<Height, High<Cents>>,
pub height_to_low_in_cents: ComputedVec<Height, Low<Cents>>,
pub height_to_ohlc: ComputedVec<Height, OHLCDollars>,
pub height_to_ohlc_in_cents: ComputedVec<Height, OHLCCents>,
pub height_to_open_in_cents: ComputedVec<Height, Open<Cents>>,
pub timeindexes_to_close: ComputedVecsFromDateindex<Close<Dollars>>,
pub timeindexes_to_high: ComputedVecsFromDateindex<High<Dollars>>,
pub timeindexes_to_low: ComputedVecsFromDateindex<Low<Dollars>>,
pub timeindexes_to_open: ComputedVecsFromDateindex<Open<Dollars>>,
pub timeindexes_to_sats_per_dollar: ComputedVecsFromDateindex<Close<Sats>>,
pub chainindexes_to_close: ComputedVecsFromHeightStrict<Close<Dollars>>,
pub chainindexes_to_high: ComputedVecsFromHeightStrict<High<Dollars>>,
pub chainindexes_to_low: ComputedVecsFromHeightStrict<Low<Dollars>>,
pub chainindexes_to_open: ComputedVecsFromHeightStrict<Open<Dollars>>,
pub chainindexes_to_sats_per_dollar: ComputedVecsFromHeightStrict<Close<Sats>>,
pub weekindex_to_ohlc: ComputedVec<Weekindex, OHLCDollars>,
pub difficultyepoch_to_ohlc: ComputedVec<Difficultyepoch, OHLCDollars>,
pub monthindex_to_ohlc: ComputedVec<Monthindex, OHLCDollars>,
pub quarterindex_to_ohlc: ComputedVec<Quarterindex, OHLCDollars>,
pub yearindex_to_ohlc: ComputedVec<Yearindex, OHLCDollars>,
// pub halvingepoch_to_ohlc: StorableVec<Halvingepoch, OHLCDollars>,
pub decadeindex_to_ohlc: StorableVec<Decadeindex, OHLCDollars>,
pub decadeindex_to_ohlc: ComputedVec<Decadeindex, OHLCDollars>,
}
impl Vecs {
@@ -64,193 +56,163 @@ impl Vecs {
fs::create_dir_all(path)?;
Ok(Self {
dateindex_to_ohlc_in_cents: StorableVec::forced_import(
dateindex_to_ohlc_in_cents: ComputedVec::forced_import(
&path.join("dateindex_to_ohlc_in_cents"),
Version::ONE,
compressed,
)?,
dateindex_to_ohlc: StorableVec::forced_import(
dateindex_to_ohlc: ComputedVec::forced_import(
&path.join("dateindex_to_ohlc"),
Version::ONE,
compressed,
)?,
dateindex_to_close_in_cents: StorableVec::forced_import(
dateindex_to_close_in_cents: ComputedVec::forced_import(
&path.join("dateindex_to_close_in_cents"),
Version::ONE,
compressed,
)?,
dateindex_to_close: StorableVec::forced_import(
&path.join("dateindex_to_close"),
Version::ONE,
compressed,
)?,
dateindex_to_high_in_cents: StorableVec::forced_import(
dateindex_to_high_in_cents: ComputedVec::forced_import(
&path.join("dateindex_to_high_in_cents"),
Version::ONE,
compressed,
)?,
dateindex_to_high: StorableVec::forced_import(
&path.join("dateindex_to_high"),
Version::ONE,
compressed,
)?,
dateindex_to_low_in_cents: StorableVec::forced_import(
dateindex_to_low_in_cents: ComputedVec::forced_import(
&path.join("dateindex_to_low_in_cents"),
Version::ONE,
compressed,
)?,
dateindex_to_low: StorableVec::forced_import(
&path.join("dateindex_to_low"),
Version::ONE,
compressed,
)?,
dateindex_to_open_in_cents: StorableVec::forced_import(
dateindex_to_open_in_cents: ComputedVec::forced_import(
&path.join("dateindex_to_open_in_cents"),
Version::ONE,
compressed,
)?,
dateindex_to_open: StorableVec::forced_import(
&path.join("dateindex_to_open"),
Version::ONE,
compressed,
)?,
dateindex_to_sats_per_dollar: StorableVec::forced_import(
&path.join("dateindex_to_sats_per_dollar"),
Version::ONE,
compressed,
)?,
height_to_ohlc_in_cents: StorableVec::forced_import(
height_to_ohlc_in_cents: ComputedVec::forced_import(
&path.join("height_to_ohlc_in_cents"),
Version::ONE,
compressed,
)?,
height_to_ohlc: StorableVec::forced_import(
height_to_ohlc: ComputedVec::forced_import(
&path.join("height_to_ohlc"),
Version::ONE,
compressed,
)?,
height_to_close_in_cents: StorableVec::forced_import(
height_to_close_in_cents: ComputedVec::forced_import(
&path.join("height_to_close_in_cents"),
Version::ONE,
compressed,
)?,
height_to_close: StorableVec::forced_import(
&path.join("height_to_close"),
Version::ONE,
compressed,
)?,
height_to_high_in_cents: StorableVec::forced_import(
height_to_high_in_cents: ComputedVec::forced_import(
&path.join("height_to_high_in_cents"),
Version::ONE,
compressed,
)?,
height_to_high: StorableVec::forced_import(
&path.join("height_to_high"),
Version::ONE,
compressed,
)?,
height_to_low_in_cents: StorableVec::forced_import(
height_to_low_in_cents: ComputedVec::forced_import(
&path.join("height_to_low_in_cents"),
Version::ONE,
compressed,
)?,
height_to_low: StorableVec::forced_import(
&path.join("height_to_low"),
Version::ONE,
compressed,
)?,
height_to_open_in_cents: StorableVec::forced_import(
height_to_open_in_cents: ComputedVec::forced_import(
&path.join("height_to_open_in_cents"),
Version::ONE,
compressed,
)?,
height_to_open: StorableVec::forced_import(
&path.join("height_to_open"),
timeindexes_to_open: ComputedVecsFromDateindex::forced_import(
path,
"open",
Version::ONE,
compressed,
)?,
height_to_sats_per_dollar: StorableVec::forced_import(
&path.join("height_to_sats_per_dollar"),
Version::ONE,
compressed,
)?,
timeindexes_to_open: StorableVecsStatsFromDate::forced_import(
&path.join("open"),
compressed,
StorableVecGeneatorOptions::default().add_first(),
)?,
timeindexes_to_high: StorableVecsStatsFromDate::forced_import(
&path.join("high"),
timeindexes_to_high: ComputedVecsFromDateindex::forced_import(
path,
"high",
Version::ONE,
compressed,
StorableVecGeneatorOptions::default().add_max(),
)?,
timeindexes_to_low: StorableVecsStatsFromDate::forced_import(
&path.join("low"),
timeindexes_to_low: ComputedVecsFromDateindex::forced_import(
path,
"low",
Version::ONE,
compressed,
StorableVecGeneatorOptions::default().add_min(),
)?,
timeindexes_to_close: StorableVecsStatsFromDate::forced_import(
&path.join("close"),
timeindexes_to_close: ComputedVecsFromDateindex::forced_import(
path,
"close",
Version::ONE,
compressed,
StorableVecGeneatorOptions::default().add_last(),
)?,
timeindexes_to_sats_per_dollar: StorableVecsStatsFromDate::forced_import(
&path.join("sats_per_dollar"),
timeindexes_to_sats_per_dollar: ComputedVecsFromDateindex::forced_import(
path,
"sats_per_dollar",
Version::ONE,
compressed,
StorableVecGeneatorOptions::default().add_last(),
)?,
chainindexes_to_open: StorableVecsStatsFromHeightStrict::forced_import(
&path.join("open"),
chainindexes_to_open: ComputedVecsFromHeightStrict::forced_import(
path,
"open",
Version::ONE,
compressed,
StorableVecGeneatorOptions::default().add_first(),
)?,
chainindexes_to_high: StorableVecsStatsFromHeightStrict::forced_import(
&path.join("high"),
chainindexes_to_high: ComputedVecsFromHeightStrict::forced_import(
path,
"high",
Version::ONE,
compressed,
StorableVecGeneatorOptions::default().add_max(),
)?,
chainindexes_to_low: StorableVecsStatsFromHeightStrict::forced_import(
&path.join("low"),
chainindexes_to_low: ComputedVecsFromHeightStrict::forced_import(
path,
"low",
Version::ONE,
compressed,
StorableVecGeneatorOptions::default().add_min(),
)?,
chainindexes_to_close: StorableVecsStatsFromHeightStrict::forced_import(
&path.join("close"),
chainindexes_to_close: ComputedVecsFromHeightStrict::forced_import(
path,
"close",
Version::ONE,
compressed,
StorableVecGeneatorOptions::default().add_last(),
)?,
chainindexes_to_sats_per_dollar: StorableVecsStatsFromHeightStrict::forced_import(
&path.join("sats_per_dollar"),
chainindexes_to_sats_per_dollar: ComputedVecsFromHeightStrict::forced_import(
path,
"sats_per_dollar",
Version::ONE,
compressed,
StorableVecGeneatorOptions::default().add_last(),
)?,
weekindex_to_ohlc: StorableVec::forced_import(
weekindex_to_ohlc: ComputedVec::forced_import(
&path.join("weekindex_to_ohlc"),
Version::ONE,
compressed,
)?,
difficultyepoch_to_ohlc: StorableVec::forced_import(
difficultyepoch_to_ohlc: ComputedVec::forced_import(
&path.join("difficultyepoch_to_ohlc"),
Version::ONE,
compressed,
)?,
monthindex_to_ohlc: StorableVec::forced_import(
monthindex_to_ohlc: ComputedVec::forced_import(
&path.join("monthindex_to_ohlc"),
Version::ONE,
compressed,
)?,
quarterindex_to_ohlc: StorableVec::forced_import(
quarterindex_to_ohlc: ComputedVec::forced_import(
&path.join("quarterindex_to_ohlc"),
Version::ONE,
compressed,
)?,
yearindex_to_ohlc: StorableVec::forced_import(
yearindex_to_ohlc: ComputedVec::forced_import(
&path.join("yearindex_to_ohlc"),
Version::ONE,
compressed,
)?,
// halvingepoch_to_ohlc: StorableVec::forced_import(&path.join("halvingepoch_to_ohlc"), Version::ONE, compressed)?,
decadeindex_to_ohlc: StorableVec::forced_import(
decadeindex_to_ohlc: ComputedVec::forced_import(
&path.join("decadeindex_to_ohlc"),
Version::ONE,
compressed,
@@ -320,41 +282,6 @@ impl Vecs {
exit,
)?;
self.height_to_open.compute_transform(
starting_indexes.height,
self.height_to_ohlc.mut_vec(),
|(di, ohlc, ..)| (di, ohlc.open),
exit,
)?;
self.height_to_high.compute_transform(
starting_indexes.height,
self.height_to_ohlc.mut_vec(),
|(di, ohlc, ..)| (di, ohlc.high),
exit,
)?;
self.height_to_low.compute_transform(
starting_indexes.height,
self.height_to_ohlc.mut_vec(),
|(di, ohlc, ..)| (di, ohlc.low),
exit,
)?;
self.height_to_close.compute_transform(
starting_indexes.height,
self.height_to_ohlc.mut_vec(),
|(di, ohlc, ..)| (di, ohlc.close),
exit,
)?;
self.height_to_sats_per_dollar.compute_transform(
starting_indexes.height,
self.height_to_close.mut_vec(),
|(di, close, ..)| (di, Close::from(Sats::ONE_BTC / *close)),
exit,
)?;
self.dateindex_to_ohlc_in_cents.compute_transform(
starting_indexes.dateindex,
indexes.dateindex_to_date.mut_vec(),
@@ -400,92 +327,113 @@ impl Vecs {
exit,
)?;
self.dateindex_to_open.compute_transform(
starting_indexes.dateindex,
self.dateindex_to_ohlc.mut_vec(),
|(di, ohlc, ..)| (di, ohlc.open),
exit,
)?;
self.dateindex_to_high.compute_transform(
starting_indexes.dateindex,
self.dateindex_to_ohlc.mut_vec(),
|(di, ohlc, ..)| (di, ohlc.high),
exit,
)?;
self.dateindex_to_low.compute_transform(
starting_indexes.dateindex,
self.dateindex_to_ohlc.mut_vec(),
|(di, ohlc, ..)| (di, ohlc.low),
exit,
)?;
self.dateindex_to_close.compute_transform(
starting_indexes.dateindex,
self.dateindex_to_ohlc.mut_vec(),
|(di, ohlc, ..)| (di, ohlc.close),
exit,
)?;
self.dateindex_to_sats_per_dollar.compute_transform(
starting_indexes.dateindex,
self.dateindex_to_close.mut_vec(),
|(di, close, ..)| (di, Close::from(Sats::ONE_BTC / *close)),
exit,
)?;
self.timeindexes_to_close.compute(
&mut self.dateindex_to_close,
|v| {
v.compute_transform(
starting_indexes.dateindex,
self.dateindex_to_ohlc.mut_vec(),
|(di, ohlc, ..)| (di, ohlc.close),
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
self.timeindexes_to_high.compute(
&mut self.dateindex_to_high,
|v| {
v.compute_transform(
starting_indexes.dateindex,
self.dateindex_to_ohlc.mut_vec(),
|(di, ohlc, ..)| (di, ohlc.high),
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
self.timeindexes_to_low.compute(
&mut self.dateindex_to_low,
|v| {
v.compute_transform(
starting_indexes.dateindex,
self.dateindex_to_ohlc.mut_vec(),
|(di, ohlc, ..)| (di, ohlc.low),
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
self.timeindexes_to_open.compute(
&mut self.dateindex_to_open,
|v| {
v.compute_transform(
starting_indexes.dateindex,
self.dateindex_to_ohlc.mut_vec(),
|(di, ohlc, ..)| (di, ohlc.open),
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
self.chainindexes_to_close.compute(
&mut self.height_to_close,
|v| {
v.compute_transform(
starting_indexes.height,
self.height_to_ohlc.mut_vec(),
|(di, ohlc, ..)| (di, ohlc.close),
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
self.chainindexes_to_high.compute(
&mut self.height_to_high,
|v| {
v.compute_transform(
starting_indexes.height,
self.height_to_ohlc.mut_vec(),
|(di, ohlc, ..)| (di, ohlc.high),
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
self.chainindexes_to_low.compute(
&mut self.height_to_low,
|v| {
v.compute_transform(
starting_indexes.height,
self.height_to_ohlc.mut_vec(),
|(di, ohlc, ..)| (di, ohlc.low),
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
self.chainindexes_to_open.compute(
&mut self.height_to_open,
|v| {
v.compute_transform(
starting_indexes.height,
self.height_to_ohlc.mut_vec(),
|(di, ohlc, ..)| (di, ohlc.open),
exit,
)
},
indexes,
starting_indexes,
exit,
@@ -771,34 +719,52 @@ impl Vecs {
exit,
)?;
self.chainindexes_to_sats_per_dollar.compute(
|v| {
v.compute_transform(
starting_indexes.height,
self.chainindexes_to_close.height.mut_vec(),
|(i, close, ..)| (i, Close::from(Sats::ONE_BTC / *close)),
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
self.timeindexes_to_sats_per_dollar.compute(
|v| {
v.compute_transform(
starting_indexes.dateindex,
self.timeindexes_to_close.dateindex.mut_vec(),
|(i, close, ..)| (i, Close::from(Sats::ONE_BTC / *close)),
exit,
)
},
indexes,
starting_indexes,
exit,
)?;
Ok(())
}
pub fn as_any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
vec![
vec![
self.dateindex_to_close.any_vec(),
self.dateindex_to_close_in_cents.any_vec(),
self.dateindex_to_high.any_vec(),
self.dateindex_to_high_in_cents.any_vec(),
self.dateindex_to_low.any_vec(),
self.dateindex_to_low_in_cents.any_vec(),
self.dateindex_to_ohlc.any_vec(),
self.dateindex_to_ohlc_in_cents.any_vec(),
self.dateindex_to_open.any_vec(),
self.dateindex_to_open_in_cents.any_vec(),
self.dateindex_to_sats_per_dollar.any_vec(),
self.height_to_close.any_vec(),
self.height_to_close_in_cents.any_vec(),
self.height_to_high.any_vec(),
self.height_to_high_in_cents.any_vec(),
self.height_to_low.any_vec(),
self.height_to_low_in_cents.any_vec(),
self.height_to_ohlc.any_vec(),
self.height_to_ohlc_in_cents.any_vec(),
self.height_to_open.any_vec(),
self.height_to_open_in_cents.any_vec(),
self.height_to_sats_per_dollar.any_vec(),
self.weekindex_to_ohlc.any_vec(),
self.difficultyepoch_to_ohlc.any_vec(),
self.monthindex_to_ohlc.any_vec(),
@@ -807,14 +773,16 @@ impl Vecs {
// self.halvingepoch_to_ohlc.any_vec(),
self.decadeindex_to_ohlc.any_vec(),
],
self.timeindexes_to_close.as_any_vecs(),
self.timeindexes_to_high.as_any_vecs(),
self.timeindexes_to_low.as_any_vecs(),
self.timeindexes_to_open.as_any_vecs(),
self.chainindexes_to_close.as_any_vecs(),
self.chainindexes_to_high.as_any_vecs(),
self.chainindexes_to_low.as_any_vecs(),
self.chainindexes_to_open.as_any_vecs(),
self.chainindexes_to_sats_per_dollar.any_vecs(),
self.timeindexes_to_sats_per_dollar.any_vecs(),
self.timeindexes_to_close.any_vecs(),
self.timeindexes_to_high.any_vecs(),
self.timeindexes_to_low.any_vecs(),
self.timeindexes_to_open.any_vecs(),
self.chainindexes_to_close.any_vecs(),
self.chainindexes_to_high.any_vecs(),
self.chainindexes_to_low.any_vecs(),
self.chainindexes_to_open.any_vecs(),
]
.concat()
}

View File

@@ -7,9 +7,9 @@ use brk_vec::{AnyStorableVec, Compressed};
mod base;
mod blocks;
mod grouped;
mod indexes;
mod marketprice;
mod stats;
mod transactions;
use base::*;

View File

@@ -1,63 +0,0 @@
use std::path::Path;
use brk_core::{Difficultyepoch, Height};
use brk_exit::Exit;
use brk_vec::{AnyStorableVec, Compressed};
use crate::storage::vecs::{Indexes, base::StorableVec, indexes};
use super::{ComputedType, StorableVecBuilder, StorableVecGeneatorOptions};
#[derive(Clone)]
pub struct StorableVecsStatsFromHeightStrict<T>
where
T: ComputedType + PartialOrd,
{
pub difficultyepoch: StorableVecBuilder<Difficultyepoch, T>,
// TODO: pub halvingepoch: StorableVecGeneator<Halvingepoch, T>,
}
impl<T> StorableVecsStatsFromHeightStrict<T>
where
T: ComputedType + Ord + From<f64>,
f64: From<T>,
{
pub fn forced_import(
path: &Path,
compressed: Compressed,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
let options = options.remove_percentiles();
Ok(Self {
difficultyepoch: StorableVecBuilder::forced_import(path, compressed, options)?,
// halvingepoch: StorableVecGeneator::forced_import(path, compressed, options)?,
})
}
pub fn compute(
&mut self,
source: &mut StorableVec<Height, T>,
indexes: &mut indexes::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
) -> color_eyre::Result<()> {
self.difficultyepoch.compute(
starting_indexes.difficultyepoch,
source,
indexes.difficultyepoch_to_first_height.mut_vec(),
indexes.difficultyepoch_to_last_height.mut_vec(),
exit,
)?;
Ok(())
}
pub fn as_any_vecs(&self) -> Vec<&dyn AnyStorableVec> {
[
self.difficultyepoch.as_any_vecs(),
// self.halvingepoch.as_any_vecs(),
]
.concat()
}
}

View File

@@ -5,27 +5,27 @@ use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyStorableVec, Compressed, Version};
use super::{Indexes, StorableVec, indexes};
use super::{ComputedVec, Indexes, indexes};
#[derive(Clone)]
pub struct Vecs {
// pub height_to_fee: StorableVec<Txindex, Sats>,
// pub height_to_inputcount: StorableVec<Height, u32>,
// pub height_to_maxfeerate: StorableVec<Height, Feerate>,
// pub height_to_medianfeerate: StorableVec<Height, Feerate>,
// pub height_to_minfeerate: StorableVec<Height, Feerate>,
// pub height_to_outputcount: StorableVec<Height, u32>,
// pub height_to_subsidy: StorableVec<Height, u32>,
// pub height_to_totalfees: StorableVec<Height, Sats>,
// pub height_to_txcount: StorableVec<Height, u32>,
// pub txindex_to_fee: StorableVec<Txindex, Sats>,
pub txindex_to_is_coinbase: StorableVec<Txindex, bool>,
// pub txindex_to_feerate: StorableVec<Txindex, Feerate>,
pub txindex_to_inputs_count: StorableVec<Txindex, u32>,
// pub txindex_to_inputs_sum: StorableVec<Txindex, Sats>,
pub txindex_to_outputs_count: StorableVec<Txindex, u32>,
// pub txindex_to_outputs_sum: StorableVec<Txindex, Sats>,
// pub txinindex_to_value: StorableVec<Txinindex, Sats>,
// pub height_to_fee: ComputedVec<Txindex, Sats>,
// pub height_to_inputcount: ComputedVec<Height, u32>,
// pub height_to_maxfeerate: ComputedVec<Height, Feerate>,
// pub height_to_medianfeerate: ComputedVec<Height, Feerate>,
// pub height_to_minfeerate: ComputedVec<Height, Feerate>,
// pub height_to_outputcount: ComputedVec<Height, u32>,
// pub height_to_subsidy: ComputedVec<Height, u32>,
// pub height_to_totalfees: ComputedVec<Height, Sats>,
// pub height_to_txcount: ComputedVec<Height, u32>,
// pub txindex_to_fee: ComputedVec<Txindex, Sats>,
pub txindex_to_is_coinbase: ComputedVec<Txindex, bool>,
// pub txindex_to_feerate: ComputedVec<Txindex, Feerate>,
pub txindex_to_inputs_count: ComputedVec<Txindex, u32>,
// pub txindex_to_inputs_sum: ComputedVec<Txindex, Sats>,
pub txindex_to_outputs_count: ComputedVec<Txindex, u32>,
// pub txindex_to_outputs_sum: ComputedVec<Txindex, Sats>,
// pub txinindex_to_value: ComputedVec<Txinindex, Sats>,
}
impl Vecs {
@@ -52,13 +52,13 @@ impl Vecs {
// &path.join("txindex_to_fee"),
// Version::ONE,
// )?,
txindex_to_is_coinbase: StorableVec::forced_import(
txindex_to_is_coinbase: ComputedVec::forced_import(
&path.join("txindex_to_is_coinbase"),
Version::ONE,
compressed,
)?,
// txindex_to_feerate: StorableVec::forced_import(&path.join("txindex_to_feerate"), Version::ONE)?,
txindex_to_inputs_count: StorableVec::forced_import(
txindex_to_inputs_count: ComputedVec::forced_import(
&path.join("txindex_to_inputs_count"),
Version::ONE,
compressed,
@@ -67,7 +67,7 @@ impl Vecs {
// &path.join("txindex_to_inputs_sum"),
// Version::ONE,
// )?,
txindex_to_outputs_count: StorableVec::forced_import(
txindex_to_outputs_count: ComputedVec::forced_import(
&path.join("txindex_to_outputs_count"),
Version::ONE,
compressed,

View File

@@ -6,19 +6,19 @@ use std::{
};
use brk_vec::{
AnyStorableVec, Compressed, Error, MAX_CACHE_SIZE, MAX_PAGE_SIZE, Result, StoredIndex,
StoredType, Value, Version,
AnyStorableVec, Compressed, Error, MAX_CACHE_SIZE, MAX_PAGE_SIZE, Result, StorableVec,
StoredIndex, StoredType, Value, Version,
};
use super::Height;
#[derive(Debug)]
pub struct StorableVec<I, T> {
pub struct IndexedVec<I, T> {
height: Option<Height>,
vec: brk_vec::StorableVec<I, T>,
vec: StorableVec<I, T>,
}
impl<I, T> StorableVec<I, T>
impl<I, T> IndexedVec<I, T>
where
I: StoredIndex,
T: StoredType,
@@ -162,7 +162,7 @@ where
}
}
impl<I, T> Clone for StorableVec<I, T>
impl<I, T> Clone for IndexedVec<I, T>
where
I: StoredIndex,
T: StoredType,
@@ -180,7 +180,7 @@ pub trait AnyIndexedVec: Send + Sync {
fn flush(&mut self, height: Height) -> io::Result<()>;
}
impl<I, T> AnyIndexedVec for StorableVec<I, T>
impl<I, T> AnyIndexedVec for IndexedVec<I, T>
where
I: StoredIndex,
T: StoredType,

View File

@@ -18,50 +18,50 @@ pub use base::*;
#[derive(Clone)]
pub struct Vecs {
pub addressindex_to_addresstype: StorableVec<Addressindex, Addresstype>,
pub addressindex_to_addresstypeindex: StorableVec<Addressindex, Addresstypeindex>,
pub addressindex_to_height: StorableVec<Addressindex, Height>,
pub height_to_blockhash: StorableVec<Height, BlockHash>,
pub height_to_difficulty: StorableVec<Height, f64>,
pub height_to_first_addressindex: StorableVec<Height, Addressindex>,
pub height_to_first_emptyindex: StorableVec<Height, Emptyindex>,
pub height_to_first_multisigindex: StorableVec<Height, Multisigindex>,
pub height_to_first_opreturnindex: StorableVec<Height, Opreturnindex>,
pub height_to_first_pushonlyindex: StorableVec<Height, Pushonlyindex>,
pub height_to_first_txindex: StorableVec<Height, Txindex>,
pub height_to_first_txinindex: StorableVec<Height, Txinindex>,
pub height_to_first_txoutindex: StorableVec<Height, Txoutindex>,
pub height_to_first_unknownindex: StorableVec<Height, Unknownindex>,
pub height_to_first_p2pk33index: StorableVec<Height, P2PK33index>,
pub height_to_first_p2pk65index: StorableVec<Height, P2PK65index>,
pub height_to_first_p2pkhindex: StorableVec<Height, P2PKHindex>,
pub height_to_first_p2shindex: StorableVec<Height, P2SHindex>,
pub height_to_first_p2trindex: StorableVec<Height, P2TRindex>,
pub height_to_first_p2wpkhindex: StorableVec<Height, P2WPKHindex>,
pub height_to_first_p2wshindex: StorableVec<Height, P2WSHindex>,
pub height_to_size: StorableVec<Height, usize>,
pub height_to_timestamp: StorableVec<Height, Timestamp>,
pub height_to_weight: StorableVec<Height, Weight>,
pub p2pk33index_to_p2pk33addressbytes: StorableVec<P2PK33index, P2PK33AddressBytes>,
pub p2pk65index_to_p2pk65addressbytes: StorableVec<P2PK65index, P2PK65AddressBytes>,
pub p2pkhindex_to_p2pkhaddressbytes: StorableVec<P2PKHindex, P2PKHAddressBytes>,
pub p2shindex_to_p2shaddressbytes: StorableVec<P2SHindex, P2SHAddressBytes>,
pub p2trindex_to_p2traddressbytes: StorableVec<P2TRindex, P2TRAddressBytes>,
pub p2wpkhindex_to_p2wpkhaddressbytes: StorableVec<P2WPKHindex, P2WPKHAddressBytes>,
pub p2wshindex_to_p2wshaddressbytes: StorableVec<P2WSHindex, P2WSHAddressBytes>,
pub txindex_to_first_txinindex: StorableVec<Txindex, Txinindex>,
pub txindex_to_first_txoutindex: StorableVec<Txindex, Txoutindex>,
pub txindex_to_height: StorableVec<Txindex, Height>,
pub txindex_to_locktime: StorableVec<Txindex, LockTime>,
pub txindex_to_txid: StorableVec<Txindex, Txid>,
pub txindex_to_base_size: StorableVec<Txindex, usize>,
pub txindex_to_total_size: StorableVec<Txindex, usize>,
pub txindex_to_is_explicitly_rbf: StorableVec<Txindex, bool>,
pub txindex_to_txversion: StorableVec<Txindex, TxVersion>,
pub addressindex_to_addresstype: IndexedVec<Addressindex, Addresstype>,
pub addressindex_to_addresstypeindex: IndexedVec<Addressindex, Addresstypeindex>,
pub addressindex_to_height: IndexedVec<Addressindex, Height>,
pub height_to_blockhash: IndexedVec<Height, BlockHash>,
pub height_to_difficulty: IndexedVec<Height, f64>,
pub height_to_first_addressindex: IndexedVec<Height, Addressindex>,
pub height_to_first_emptyindex: IndexedVec<Height, Emptyindex>,
pub height_to_first_multisigindex: IndexedVec<Height, Multisigindex>,
pub height_to_first_opreturnindex: IndexedVec<Height, Opreturnindex>,
pub height_to_first_pushonlyindex: IndexedVec<Height, Pushonlyindex>,
pub height_to_first_txindex: IndexedVec<Height, Txindex>,
pub height_to_first_txinindex: IndexedVec<Height, Txinindex>,
pub height_to_first_txoutindex: IndexedVec<Height, Txoutindex>,
pub height_to_first_unknownindex: IndexedVec<Height, Unknownindex>,
pub height_to_first_p2pk33index: IndexedVec<Height, P2PK33index>,
pub height_to_first_p2pk65index: IndexedVec<Height, P2PK65index>,
pub height_to_first_p2pkhindex: IndexedVec<Height, P2PKHindex>,
pub height_to_first_p2shindex: IndexedVec<Height, P2SHindex>,
pub height_to_first_p2trindex: IndexedVec<Height, P2TRindex>,
pub height_to_first_p2wpkhindex: IndexedVec<Height, P2WPKHindex>,
pub height_to_first_p2wshindex: IndexedVec<Height, P2WSHindex>,
pub height_to_size: IndexedVec<Height, usize>,
pub height_to_timestamp: IndexedVec<Height, Timestamp>,
pub height_to_weight: IndexedVec<Height, Weight>,
pub p2pk33index_to_p2pk33addressbytes: IndexedVec<P2PK33index, P2PK33AddressBytes>,
pub p2pk65index_to_p2pk65addressbytes: IndexedVec<P2PK65index, P2PK65AddressBytes>,
pub p2pkhindex_to_p2pkhaddressbytes: IndexedVec<P2PKHindex, P2PKHAddressBytes>,
pub p2shindex_to_p2shaddressbytes: IndexedVec<P2SHindex, P2SHAddressBytes>,
pub p2trindex_to_p2traddressbytes: IndexedVec<P2TRindex, P2TRAddressBytes>,
pub p2wpkhindex_to_p2wpkhaddressbytes: IndexedVec<P2WPKHindex, P2WPKHAddressBytes>,
pub p2wshindex_to_p2wshaddressbytes: IndexedVec<P2WSHindex, P2WSHAddressBytes>,
pub txindex_to_first_txinindex: IndexedVec<Txindex, Txinindex>,
pub txindex_to_first_txoutindex: IndexedVec<Txindex, Txoutindex>,
pub txindex_to_height: IndexedVec<Txindex, Height>,
pub txindex_to_locktime: IndexedVec<Txindex, LockTime>,
pub txindex_to_txid: IndexedVec<Txindex, Txid>,
pub txindex_to_base_size: IndexedVec<Txindex, usize>,
pub txindex_to_total_size: IndexedVec<Txindex, usize>,
pub txindex_to_is_explicitly_rbf: IndexedVec<Txindex, bool>,
pub txindex_to_txversion: IndexedVec<Txindex, TxVersion>,
/// If txoutindex == Txoutindex MAX then is it's coinbase
pub txinindex_to_txoutindex: StorableVec<Txinindex, Txoutindex>,
pub txoutindex_to_addressindex: StorableVec<Txoutindex, Addressindex>,
pub txoutindex_to_value: StorableVec<Txoutindex, Sats>,
pub txinindex_to_txoutindex: IndexedVec<Txinindex, Txoutindex>,
pub txoutindex_to_addressindex: IndexedVec<Txoutindex, Addressindex>,
pub txoutindex_to_value: IndexedVec<Txoutindex, Sats>,
}
impl Vecs {
@@ -69,217 +69,217 @@ impl Vecs {
fs::create_dir_all(path)?;
Ok(Self {
addressindex_to_addresstype: StorableVec::forced_import(
addressindex_to_addresstype: IndexedVec::forced_import(
&path.join("addressindex_to_addresstype"),
Version::ONE,
compressed,
)?,
addressindex_to_addresstypeindex: StorableVec::forced_import(
addressindex_to_addresstypeindex: IndexedVec::forced_import(
&path.join("addressindex_to_addresstypeindex"),
Version::ONE,
compressed,
)?,
addressindex_to_height: StorableVec::forced_import(
addressindex_to_height: IndexedVec::forced_import(
&path.join("addressindex_to_height"),
Version::ONE,
compressed,
)?,
height_to_blockhash: StorableVec::forced_import(
height_to_blockhash: IndexedVec::forced_import(
&path.join("height_to_blockhash"),
Version::ONE,
Compressed::NO,
)?,
height_to_difficulty: StorableVec::forced_import(
height_to_difficulty: IndexedVec::forced_import(
&path.join("height_to_difficulty"),
Version::ONE,
compressed,
)?,
height_to_first_addressindex: StorableVec::forced_import(
height_to_first_addressindex: IndexedVec::forced_import(
&path.join("height_to_first_addressindex"),
Version::ONE,
compressed,
)?,
height_to_first_emptyindex: StorableVec::forced_import(
height_to_first_emptyindex: IndexedVec::forced_import(
&path.join("height_to_first_emptyindex"),
Version::ONE,
compressed,
)?,
height_to_first_multisigindex: StorableVec::forced_import(
height_to_first_multisigindex: IndexedVec::forced_import(
&path.join("height_to_first_multisigindex"),
Version::ONE,
compressed,
)?,
height_to_first_opreturnindex: StorableVec::forced_import(
height_to_first_opreturnindex: IndexedVec::forced_import(
&path.join("height_to_first_opreturnindex"),
Version::ONE,
compressed,
)?,
height_to_first_pushonlyindex: StorableVec::forced_import(
height_to_first_pushonlyindex: IndexedVec::forced_import(
&path.join("height_to_first_pushonlyindex"),
Version::ONE,
compressed,
)?,
height_to_first_txindex: StorableVec::forced_import(
height_to_first_txindex: IndexedVec::forced_import(
&path.join("height_to_first_txindex"),
Version::ONE,
compressed,
)?,
height_to_first_txinindex: StorableVec::forced_import(
height_to_first_txinindex: IndexedVec::forced_import(
&path.join("height_to_first_txinindex"),
Version::ONE,
compressed,
)?,
height_to_first_txoutindex: StorableVec::forced_import(
height_to_first_txoutindex: IndexedVec::forced_import(
&path.join("height_to_first_txoutindex"),
Version::ONE,
compressed,
)?,
height_to_first_unknownindex: StorableVec::forced_import(
height_to_first_unknownindex: IndexedVec::forced_import(
&path.join("height_to_first_unkownindex"),
Version::ONE,
compressed,
)?,
height_to_first_p2pk33index: StorableVec::forced_import(
height_to_first_p2pk33index: IndexedVec::forced_import(
&path.join("height_to_first_p2pk33index"),
Version::ONE,
compressed,
)?,
height_to_first_p2pk65index: StorableVec::forced_import(
height_to_first_p2pk65index: IndexedVec::forced_import(
&path.join("height_to_first_p2pk65index"),
Version::ONE,
compressed,
)?,
height_to_first_p2pkhindex: StorableVec::forced_import(
height_to_first_p2pkhindex: IndexedVec::forced_import(
&path.join("height_to_first_p2pkhindex"),
Version::ONE,
compressed,
)?,
height_to_first_p2shindex: StorableVec::forced_import(
height_to_first_p2shindex: IndexedVec::forced_import(
&path.join("height_to_first_p2shindex"),
Version::ONE,
compressed,
)?,
height_to_first_p2trindex: StorableVec::forced_import(
height_to_first_p2trindex: IndexedVec::forced_import(
&path.join("height_to_first_p2trindex"),
Version::ONE,
compressed,
)?,
height_to_first_p2wpkhindex: StorableVec::forced_import(
height_to_first_p2wpkhindex: IndexedVec::forced_import(
&path.join("height_to_first_p2wpkhindex"),
Version::ONE,
compressed,
)?,
height_to_first_p2wshindex: StorableVec::forced_import(
height_to_first_p2wshindex: IndexedVec::forced_import(
&path.join("height_to_first_p2wshindex"),
Version::ONE,
compressed,
)?,
height_to_size: StorableVec::forced_import(
height_to_size: IndexedVec::forced_import(
&path.join("height_to_size"),
Version::ONE,
compressed,
)?,
height_to_timestamp: StorableVec::forced_import(
height_to_timestamp: IndexedVec::forced_import(
&path.join("height_to_timestamp"),
Version::ONE,
compressed,
)?,
height_to_weight: StorableVec::forced_import(
height_to_weight: IndexedVec::forced_import(
&path.join("height_to_weight"),
Version::ONE,
compressed,
)?,
p2pk33index_to_p2pk33addressbytes: StorableVec::forced_import(
p2pk33index_to_p2pk33addressbytes: IndexedVec::forced_import(
&path.join("p2pk33index_to_p2pk33addressbytes"),
Version::ONE,
Compressed::NO,
)?,
p2pk65index_to_p2pk65addressbytes: StorableVec::forced_import(
p2pk65index_to_p2pk65addressbytes: IndexedVec::forced_import(
&path.join("p2pk65index_to_p2pk65addressbytes"),
Version::ONE,
Compressed::NO,
)?,
p2pkhindex_to_p2pkhaddressbytes: StorableVec::forced_import(
p2pkhindex_to_p2pkhaddressbytes: IndexedVec::forced_import(
&path.join("p2pkhindex_to_p2pkhaddressbytes"),
Version::ONE,
Compressed::NO,
)?,
p2shindex_to_p2shaddressbytes: StorableVec::forced_import(
p2shindex_to_p2shaddressbytes: IndexedVec::forced_import(
&path.join("p2shindex_to_p2shaddressbytes"),
Version::ONE,
Compressed::NO,
)?,
p2trindex_to_p2traddressbytes: StorableVec::forced_import(
p2trindex_to_p2traddressbytes: IndexedVec::forced_import(
&path.join("p2trindex_to_p2traddressbytes"),
Version::ONE,
Compressed::NO,
)?,
p2wpkhindex_to_p2wpkhaddressbytes: StorableVec::forced_import(
p2wpkhindex_to_p2wpkhaddressbytes: IndexedVec::forced_import(
&path.join("p2wpkhindex_to_p2wpkhaddressbytes"),
Version::ONE,
Compressed::NO,
)?,
p2wshindex_to_p2wshaddressbytes: StorableVec::forced_import(
p2wshindex_to_p2wshaddressbytes: IndexedVec::forced_import(
&path.join("p2wshindex_to_p2wshaddressbytes"),
Version::ONE,
Compressed::NO,
)?,
txindex_to_first_txinindex: StorableVec::forced_import(
txindex_to_first_txinindex: IndexedVec::forced_import(
&path.join("txindex_to_first_txinindex"),
Version::ONE,
compressed,
)?,
txindex_to_first_txoutindex: StorableVec::forced_import(
txindex_to_first_txoutindex: IndexedVec::forced_import(
&path.join("txindex_to_first_txoutindex"),
Version::ONE,
Compressed::NO,
)?,
txindex_to_height: StorableVec::forced_import(
txindex_to_height: IndexedVec::forced_import(
&path.join("txindex_to_height"),
Version::ONE,
compressed,
)?,
txindex_to_locktime: StorableVec::forced_import(
txindex_to_locktime: IndexedVec::forced_import(
&path.join("txindex_to_locktime"),
Version::ONE,
compressed,
)?,
txindex_to_txid: StorableVec::forced_import(
txindex_to_txid: IndexedVec::forced_import(
&path.join("txindex_to_txid"),
Version::ONE,
Compressed::NO,
)?,
txindex_to_base_size: StorableVec::forced_import(
txindex_to_base_size: IndexedVec::forced_import(
&path.join("txindex_to_base_size"),
Version::ONE,
compressed,
)?,
txindex_to_total_size: StorableVec::forced_import(
txindex_to_total_size: IndexedVec::forced_import(
&path.join("txindex_to_total_size"),
Version::ONE,
compressed,
)?,
txindex_to_is_explicitly_rbf: StorableVec::forced_import(
txindex_to_is_explicitly_rbf: IndexedVec::forced_import(
&path.join("txindex_to_is_explicitly_rbf"),
Version::ONE,
compressed,
)?,
txindex_to_txversion: StorableVec::forced_import(
txindex_to_txversion: IndexedVec::forced_import(
&path.join("txindex_to_txversion"),
Version::ONE,
compressed,
)?,
txinindex_to_txoutindex: StorableVec::forced_import(
txinindex_to_txoutindex: IndexedVec::forced_import(
&path.join("txinindex_to_txoutindex"),
Version::ONE,
compressed,
)?,
txoutindex_to_addressindex: StorableVec::forced_import(
txoutindex_to_addressindex: IndexedVec::forced_import(
&path.join("txoutindex_to_addressindex"),
Version::ONE,
compressed,
)?,
txoutindex_to_value: StorableVec::forced_import(
txoutindex_to_value: IndexedVec::forced_import(
&path.join("txoutindex_to_value"),
Version::ONE,
compressed,

View File

@@ -25,6 +25,5 @@ oxc = { version = "0.62.0", features = ["codegen", "minifier"] }
serde = { workspace = true }
tokio = { version = "1.44.1", features = ["full"] }
tower-http = { version = "0.6.2", features = ["compression-full", "trace"] }
zip = "2.6.0"
zip = "2.6.1"
tracing = "0.1.41"
tracing-subscriber = "0.3.19"