global: wip

This commit is contained in:
nym21
2025-06-02 18:22:42 +02:00
parent 98a312701f
commit 93ee5e480b
54 changed files with 3914 additions and 1076 deletions

View File

@@ -8,12 +8,12 @@ use crate::run::RunConfig;
pub fn query(params: QueryParams) -> color_eyre::Result<()> {
let config = RunConfig::import(None)?;
let compressed = config.compressed();
let format = config.format();
let mut indexer = Indexer::new(&config.outputsdir(), compressed, config.check_collisions())?;
let mut indexer = Indexer::new(&config.outputsdir(), format, config.check_collisions())?;
indexer.import_vecs()?;
let mut computer = Computer::new(&config.outputsdir(), config.fetcher(), compressed);
let mut computer = Computer::new(&config.outputsdir(), config.fetcher(), format);
computer.import_vecs(&indexer, config.computation())?;
let query = Query::build(&indexer, &computer);

View File

@@ -12,7 +12,7 @@ use brk_exit::Exit;
use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
use brk_server::{Server, Website};
use brk_vec::Computation;
use brk_vec::{Computation, Format};
use clap_derive::{Parser, ValueEnum};
use color_eyre::eyre::eyre;
use log::info;
@@ -27,9 +27,9 @@ pub fn run(config: RunConfig) -> color_eyre::Result<()> {
let parser = brk_parser::Parser::new(config.blocksdir(), rpc);
let compressed = config.compressed();
let format = config.format();
let mut indexer = Indexer::new(&config.outputsdir(), compressed, config.check_collisions())?;
let mut indexer = Indexer::new(&config.outputsdir(), format, config.check_collisions())?;
indexer.import_stores()?;
indexer.import_vecs()?;
@@ -50,7 +50,7 @@ pub fn run(config: RunConfig) -> color_eyre::Result<()> {
};
let f = move || -> color_eyre::Result<()> {
let mut computer = Computer::new(&config.outputsdir(), config.fetcher(), compressed);
let mut computer = Computer::new(&config.outputsdir(), config.fetcher(), format);
computer.import_stores(&indexer)?;
computer.import_vecs(&indexer, config.computation())?;
@@ -133,15 +133,15 @@ pub struct RunConfig {
mode: Option<Mode>,
/// Computation mode for compatible datasets, `lazy` computes data whenever requested without saving it, `eager` computes the data once and saves it to disk, default: Lazy, saved
#[arg(short = 'C', long)]
#[arg(short, long)]
computation: Option<Computation>,
/// Activate compression of datasets, set to true to save disk space or false if prioritize speed, default: true, saved
#[arg(short, long, value_name = "BOOL")]
compressed: Option<bool>,
#[arg(short, long, value_name = "FORMAT")]
format: Option<Format>,
/// Activate fetching prices from exchanges APIs and the computation of all related datasets, default: true, saved
#[arg(short, long, value_name = "BOOL")]
#[arg(short = 'F', long, value_name = "BOOL")]
fetch: Option<bool>,
/// Website served by the server (if active), default: kibo.money, saved
@@ -204,12 +204,16 @@ impl RunConfig {
config_saved.mode = Some(mode);
}
if let Some(computation) = config_args.computation.take() {
config_saved.computation = Some(computation);
}
if let Some(fetch) = config_args.fetch.take() {
config_saved.fetch = Some(fetch);
}
if let Some(compressed) = config_args.compressed.take() {
config_saved.compressed = Some(compressed);
if let Some(format) = config_args.format.take() {
config_saved.format = Some(format);
}
if let Some(website) = config_args.website.take() {
@@ -430,8 +434,8 @@ impl RunConfig {
self.computation.unwrap_or_default()
}
pub fn compressed(&self) -> bool {
self.compressed.is_none_or(|b| b)
pub fn format(&self) -> Format {
self.format.unwrap_or_default()
}
pub fn check_collisions(&self) -> bool {

View File

@@ -6,7 +6,7 @@ use brk_exit::Exit;
use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
use brk_parser::Parser;
use brk_vec::Computation;
use brk_vec::{Computation, Format};
pub fn main() -> color_eyre::Result<()> {
color_eyre::install()?;
@@ -31,15 +31,15 @@ pub fn main() -> color_eyre::Result<()> {
let outputs_dir = _outputs_dir.as_path();
// let outputs_dir = Path::new("../../_outputs");
let compressed = false;
let format = Format::Raw;
let mut indexer = Indexer::new(outputs_dir, compressed, true)?;
let mut indexer = Indexer::new(outputs_dir, format, true)?;
indexer.import_stores()?;
indexer.import_vecs()?;
let fetcher = Fetcher::import(None)?;
let mut computer = Computer::new(outputs_dir, Some(fetcher), compressed);
let mut computer = Computer::new(outputs_dir, Some(fetcher), format);
computer.import_stores(&indexer)?;
computer.import_vecs(&indexer, Computation::Lazy)?;

View File

@@ -9,7 +9,7 @@ use brk_core::Version;
use brk_exit::Exit;
use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, Compressed, Computation};
use brk_vec::{AnyCollectableVec, Computation, Format};
mod stores;
mod utils;
@@ -25,19 +25,19 @@ pub struct Computer {
fetcher: Option<Fetcher>,
vecs: Option<Vecs>,
stores: Option<Stores>,
compressed: Compressed,
format: Format,
}
const VERSION: Version = Version::ONE;
impl Computer {
pub fn new(outputs_dir: &Path, fetcher: Option<Fetcher>, compressed: bool) -> Self {
pub fn new(outputs_dir: &Path, fetcher: Option<Fetcher>, format: Format) -> Self {
Self {
path: outputs_dir.to_owned(),
fetcher,
vecs: None,
stores: None,
compressed: Compressed::from(compressed),
format,
}
}
@@ -53,7 +53,7 @@ impl Computer {
indexer,
self.fetcher.is_some(),
computation,
self.compressed,
self.format,
indexer.keyspace(),
)?);
Ok(())
@@ -80,15 +80,10 @@ impl Computer {
exit: &Exit,
) -> color_eyre::Result<()> {
info!("Computing...");
self.vecs.as_mut().unwrap().compute(
indexer,
starting_indexes,
self.fetcher.as_mut(),
exit,
)?;
Ok(())
self.vecs
.as_mut()
.unwrap()
.compute(indexer, starting_indexes, self.fetcher.as_mut(), exit)
}
pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> {

View File

@@ -6,7 +6,7 @@ use brk_core::{
};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, AnyIterableVec, Compressed, Computation, EagerVec};
use brk_vec::{AnyCollectableVec, AnyIterableVec, Computation, EagerVec, Format};
use super::{
Indexes,
@@ -35,7 +35,7 @@ impl Vecs {
path: &Path,
version: Version,
_computation: Computation,
compressed: Compressed,
format: Format,
) -> color_eyre::Result<Self> {
fs::create_dir_all(path)?;
@@ -44,14 +44,14 @@ impl Vecs {
path,
"interval",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
timeindexes_to_timestamp: ComputedVecsFromDateIndex::forced_import(
path,
"timestamp",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_first(),
)?,
indexes_to_block_interval: ComputedVecsFromHeight::forced_import(
@@ -59,7 +59,7 @@ impl Vecs {
"block_interval",
false,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_percentiles()
.add_minmax()
@@ -70,7 +70,7 @@ impl Vecs {
"block_count",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
@@ -80,7 +80,7 @@ impl Vecs {
"block_weight",
false,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
@@ -90,7 +90,7 @@ impl Vecs {
"block_size",
false,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
@@ -99,14 +99,14 @@ impl Vecs {
path,
"vbytes",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
indexes_to_block_vbytes: ComputedVecsFromHeight::forced_import(
path,
"block_vbytes",
false,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
@@ -115,13 +115,13 @@ impl Vecs {
path,
"timestamp",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
halvingepoch_to_timestamp: EagerVec::forced_import(
path,
"timestamp",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
})
}

View File

@@ -3,7 +3,7 @@ use std::{fs, path::Path};
use brk_core::{StoredU8, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, AnyVec, Compressed, Computation};
use brk_vec::{AnyCollectableVec, AnyVec, Computation, Format};
use super::{
Indexes,
@@ -26,7 +26,7 @@ impl Vecs {
path: &Path,
version: Version,
_computation: Computation,
compressed: Compressed,
format: Format,
) -> color_eyre::Result<Self> {
fs::create_dir_all(path)?;
@@ -36,7 +36,7 @@ impl Vecs {
"0",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_last(),
)?,
_1: ComputedVecsFromHeight::forced_import(
@@ -44,7 +44,7 @@ impl Vecs {
"1",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_last(),
)?,
_50: ComputedVecsFromHeight::forced_import(
@@ -52,7 +52,7 @@ impl Vecs {
"50",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_last(),
)?,
_100: ComputedVecsFromHeight::forced_import(
@@ -60,7 +60,7 @@ impl Vecs {
"100",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_last(),
)?,
})

View File

@@ -7,7 +7,7 @@ use brk_core::{
use brk_exit::Exit;
use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, AnyIterableVec, Compressed, Computation, EagerVec};
use brk_vec::{AnyCollectableVec, AnyIterableVec, Computation, EagerVec, Format};
use super::{
Indexes,
@@ -73,7 +73,7 @@ impl Vecs {
path: &Path,
version: Version,
_computation: Computation,
compressed: Compressed,
format: Format,
) -> color_eyre::Result<Self> {
fs::create_dir_all(path)?;
@@ -86,92 +86,92 @@ impl Vecs {
&fetched_path,
"ohlc_in_cents",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
dateindex_to_ohlc: EagerVec::forced_import(
path,
"ohlc",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
dateindex_to_ohlc_in_sats: EagerVec::forced_import(
path,
"ohlc_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
format,
)?,
dateindex_to_close_in_cents: EagerVec::forced_import(
path,
"close_in_cents",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
dateindex_to_high_in_cents: EagerVec::forced_import(
path,
"high_in_cents",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
dateindex_to_low_in_cents: EagerVec::forced_import(
path,
"low_in_cents",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
dateindex_to_open_in_cents: EagerVec::forced_import(
path,
"open_in_cents",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_ohlc_in_cents: EagerVec::forced_import(
&fetched_path,
"ohlc_in_cents",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_ohlc: EagerVec::forced_import(
path,
"ohlc",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_ohlc_in_sats: EagerVec::forced_import(
path,
"ohlc_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
format,
)?,
height_to_close_in_cents: EagerVec::forced_import(
path,
"close_in_cents",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_high_in_cents: EagerVec::forced_import(
path,
"high_in_cents",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_low_in_cents: EagerVec::forced_import(
path,
"low_in_cents",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_open_in_cents: EagerVec::forced_import(
path,
"open_in_cents",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
timeindexes_to_open: ComputedVecsFromDateIndex::forced_import(
path,
"open",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_first(),
)?,
timeindexes_to_high: ComputedVecsFromDateIndex::forced_import(
@@ -179,7 +179,7 @@ impl Vecs {
"high",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_max(),
)?,
timeindexes_to_low: ComputedVecsFromDateIndex::forced_import(
@@ -187,7 +187,7 @@ impl Vecs {
"low",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_min(),
)?,
timeindexes_to_close: ComputedVecsFromDateIndex::forced_import(
@@ -195,7 +195,7 @@ impl Vecs {
"close",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_last(),
)?,
timeindexes_to_open_in_sats: ComputedVecsFromDateIndex::forced_import(
@@ -203,7 +203,7 @@ impl Vecs {
"open_in_sats",
true,
version + VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_first(),
)?,
timeindexes_to_high_in_sats: ComputedVecsFromDateIndex::forced_import(
@@ -211,7 +211,7 @@ impl Vecs {
"high_in_sats",
true,
version + VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_max(),
)?,
timeindexes_to_low_in_sats: ComputedVecsFromDateIndex::forced_import(
@@ -219,7 +219,7 @@ impl Vecs {
"low_in_sats",
true,
version + VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_min(),
)?,
timeindexes_to_close_in_sats: ComputedVecsFromDateIndex::forced_import(
@@ -227,138 +227,138 @@ impl Vecs {
"close_in_sats",
true,
version + VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_last(),
)?,
chainindexes_to_open: ComputedVecsFromHeightStrict::forced_import(
path,
"open",
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_first(),
)?,
chainindexes_to_high: ComputedVecsFromHeightStrict::forced_import(
path,
"high",
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_max(),
)?,
chainindexes_to_low: ComputedVecsFromHeightStrict::forced_import(
path,
"low",
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_min(),
)?,
chainindexes_to_close: ComputedVecsFromHeightStrict::forced_import(
path,
"close",
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_last(),
)?,
chainindexes_to_open_in_sats: ComputedVecsFromHeightStrict::forced_import(
path,
"open_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_first(),
)?,
chainindexes_to_high_in_sats: ComputedVecsFromHeightStrict::forced_import(
path,
"high_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_max(),
)?,
chainindexes_to_low_in_sats: ComputedVecsFromHeightStrict::forced_import(
path,
"low_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_min(),
)?,
chainindexes_to_close_in_sats: ComputedVecsFromHeightStrict::forced_import(
path,
"close_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_last(),
)?,
weekindex_to_ohlc: EagerVec::forced_import(
path,
"ohlc",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
weekindex_to_ohlc_in_sats: EagerVec::forced_import(
path,
"ohlc_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
format,
)?,
difficultyepoch_to_ohlc: EagerVec::forced_import(
path,
"ohlc",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
difficultyepoch_to_ohlc_in_sats: EagerVec::forced_import(
path,
"ohlc_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
format,
)?,
monthindex_to_ohlc: EagerVec::forced_import(
path,
"ohlc",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
monthindex_to_ohlc_in_sats: EagerVec::forced_import(
path,
"ohlc_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
format,
)?,
quarterindex_to_ohlc: EagerVec::forced_import(
path,
"ohlc",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
quarterindex_to_ohlc_in_sats: EagerVec::forced_import(
path,
"ohlc_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
format,
)?,
yearindex_to_ohlc: EagerVec::forced_import(
path,
"ohlc",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
yearindex_to_ohlc_in_sats: EagerVec::forced_import(
path,
"ohlc_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
format,
)?,
// halvingepoch_to_ohlc: StorableVec::forced_import(path,
// "halvingepoch_to_ohlc"), version + VERSION + Version::ZERO, compressed)?,
// "halvingepoch_to_ohlc"), version + VERSION + Version::ZERO, format)?,
decadeindex_to_ohlc: EagerVec::forced_import(
path,
"ohlc",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
decadeindex_to_ohlc_in_sats: EagerVec::forced_import(
path,
"ohlc_in_sats",
version + VERSION + VERSION_IN_SATS + Version::ZERO,
compressed,
format,
)?,
})
}

View File

@@ -2,7 +2,7 @@ use std::path::Path;
use brk_core::{CheckedSub, Result, StoredUsize, Version};
use brk_exit::Exit;
use brk_vec::{AnyCollectableVec, AnyIterableVec, Compressed, EagerVec, StoredIndex, StoredType};
use brk_vec::{AnyCollectableVec, AnyIterableVec, EagerVec, Format, StoredIndex, StoredType};
use color_eyre::eyre::ContextCompat;
use crate::utils::get_percentile;
@@ -40,7 +40,7 @@ where
path: &Path,
name: &str,
version: Version,
compressed: Compressed,
format: Format,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
let only_one_active = options.is_only_one_active();
@@ -72,15 +72,14 @@ where
path,
&maybe_prefix("first"),
version + VERSION + Version::ZERO,
compressed,
format,
)
.unwrap(),
)
}),
last: options.last.then(|| {
Box::new(
EagerVec::forced_import(path, name, version + Version::ZERO, compressed)
.unwrap(),
EagerVec::forced_import(path, name, version + Version::ZERO, format).unwrap(),
)
}),
min: options.min.then(|| {
@@ -89,7 +88,7 @@ where
path,
&maybe_suffix("min"),
version + VERSION + Version::ZERO,
compressed,
format,
)
.unwrap(),
)
@@ -100,7 +99,7 @@ where
path,
&maybe_suffix("max"),
version + VERSION + Version::ZERO,
compressed,
format,
)
.unwrap(),
)
@@ -111,7 +110,7 @@ where
path,
&maybe_suffix("median"),
version + VERSION + Version::ZERO,
compressed,
format,
)
.unwrap(),
)
@@ -122,7 +121,7 @@ where
path,
&maybe_suffix("average"),
version + VERSION + Version::ZERO,
compressed,
format,
)
.unwrap(),
)
@@ -133,7 +132,7 @@ where
path,
&maybe_suffix("sum"),
version + VERSION + Version::ZERO,
compressed,
format,
)
.unwrap(),
)
@@ -144,7 +143,7 @@ where
path,
&prefix("cumulative"),
version + VERSION + Version::ZERO,
compressed,
format,
)
.unwrap(),
)
@@ -155,7 +154,7 @@ where
path,
&maybe_suffix("90p"),
version + VERSION + Version::ZERO,
compressed,
format,
)
.unwrap(),
)
@@ -166,7 +165,7 @@ where
path,
&maybe_suffix("75p"),
version + VERSION + Version::ZERO,
compressed,
format,
)
.unwrap(),
)
@@ -177,7 +176,7 @@ where
path,
&maybe_suffix("25p"),
version + VERSION + Version::ZERO,
compressed,
format,
)
.unwrap(),
)
@@ -188,7 +187,7 @@ where
path,
&maybe_suffix("10p"),
version + VERSION + Version::ZERO,
compressed,
format,
)
.unwrap(),
)

View File

@@ -5,7 +5,7 @@ use brk_core::{
};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, AnyIterableVec, Compressed, EagerVec};
use brk_vec::{AnyCollectableVec, AnyIterableVec, EagerVec, Format};
use crate::vecs::{Indexes, indexes};
@@ -36,19 +36,18 @@ where
name: &str,
compute_source: bool,
version: Version,
compressed: Compressed,
format: Format,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
let dateindex = compute_source.then(|| {
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, compressed)
.unwrap()
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format).unwrap()
});
let dateindex_extra = ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options.copy_self_extra(),
)?;
@@ -61,35 +60,35 @@ where
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
monthindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
quarterindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
yearindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
decadeindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
})

View File

@@ -6,7 +6,7 @@ use brk_core::{
};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, AnyIterableVec, Compressed, EagerVec};
use brk_vec::{AnyCollectableVec, AnyIterableVec, EagerVec, Format};
use crate::vecs::{Indexes, indexes};
@@ -41,19 +41,18 @@ where
name: &str,
compute_source: bool,
version: Version,
compressed: Compressed,
format: Format,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
let height = compute_source.then(|| {
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, compressed)
.unwrap()
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format).unwrap()
});
let height_extra = ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options.copy_self_extra(),
)?;
@@ -61,7 +60,7 @@ where
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?;
@@ -75,43 +74,43 @@ where
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
difficultyepoch: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
monthindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
quarterindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
yearindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
// halvingepoch: StorableVecGeneator::forced_import(path, name, version + VERSION + Version::ZERO, compressed, options)?,
// halvingepoch: StorableVecGeneator::forced_import(path, name, version + VERSION + Version::ZERO, format, options)?,
decadeindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
})

View File

@@ -3,7 +3,7 @@ use std::path::Path;
use brk_core::{DifficultyEpoch, Height, Result, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, Compressed, EagerVec};
use brk_vec::{AnyCollectableVec, EagerVec, Format};
use crate::vecs::{Indexes, indexes};
@@ -31,17 +31,17 @@ where
path: &Path,
name: &str,
version: Version,
compressed: Compressed,
format: Format,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
let height =
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, compressed)?;
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format)?;
let height_extra = ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options.copy_self_extra(),
)?;
@@ -54,10 +54,10 @@ where
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
// halvingepoch: StorableVecGeneator::forced_import(path, name, version + VERSION + Version::ZERO, compressed, options)?,
// halvingepoch: StorableVecGeneator::forced_import(path, name, version + VERSION + Version::ZERO, format, options)?,
})
}

View File

@@ -7,7 +7,7 @@ use brk_core::{
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{
AnyCollectableVec, AnyVec, CollectableVec, Compressed, EagerVec, StoredIndex, VecIterator,
AnyCollectableVec, AnyVec, CollectableVec, EagerVec, Format, StoredIndex, VecIterator,
};
use crate::vecs::{Indexes, fetched, indexes};
@@ -43,12 +43,12 @@ where
name: &str,
compute_source: bool,
version: Version,
compressed: Compressed,
format: Format,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
let txindex = compute_source.then(|| {
Box::new(
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, compressed)
EagerVec::forced_import(path, name, version + VERSION + Version::ZERO, format)
.unwrap(),
)
});
@@ -57,7 +57,7 @@ where
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?;
@@ -70,50 +70,50 @@ where
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
weekindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
difficultyepoch: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
monthindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
quarterindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
yearindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
// halvingepoch: StorableVecGeneator::forced_import(path, name, version + VERSION + Version::ZERO, compressed, options)?,
// halvingepoch: StorableVecGeneator::forced_import(path, name, version + VERSION + Version::ZERO, format, options)?,
decadeindex: ComputedVecBuilder::forced_import(
path,
name,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
})

View File

@@ -4,7 +4,7 @@ use brk_core::{Date, DateIndex, Dollars, Result, StoredF32, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{
AnyCollectableVec, AnyIterableVec, AnyVec, CollectableVec, Compressed, EagerVec, StoredIndex,
AnyCollectableVec, AnyIterableVec, AnyVec, CollectableVec, EagerVec, Format, StoredIndex,
VecIterator,
};
@@ -61,7 +61,7 @@ impl ComputedRatioVecsFromDateIndex {
name: &str,
compute_source: bool,
version: Version,
compressed: Compressed,
format: Format,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
Ok(Self {
@@ -71,7 +71,7 @@ impl ComputedRatioVecsFromDateIndex {
name,
true,
version + VERSION,
compressed,
format,
options,
)
.unwrap()
@@ -81,7 +81,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_sma: ComputedVecsFromDateIndex::forced_import(
@@ -89,7 +89,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_sma"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_1w_sma: ComputedVecsFromDateIndex::forced_import(
@@ -97,7 +97,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_1w_sma"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_1m_sma: ComputedVecsFromDateIndex::forced_import(
@@ -105,7 +105,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_1m_sma"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_1y_sma: ComputedVecsFromDateIndex::forced_import(
@@ -113,7 +113,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_1y_sma"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_1y_sma_momentum_oscillator: ComputedVecsFromDateIndex::forced_import(
@@ -121,7 +121,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_1y_sma_momentum_oscillator"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_standard_deviation: ComputedVecsFromDateIndex::forced_import(
@@ -129,7 +129,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_standard_deviation"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p99_9: ComputedVecsFromDateIndex::forced_import(
@@ -137,7 +137,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p99_9"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p99_5: ComputedVecsFromDateIndex::forced_import(
@@ -145,7 +145,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p99_5"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p99: ComputedVecsFromDateIndex::forced_import(
@@ -153,7 +153,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p99"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p1: ComputedVecsFromDateIndex::forced_import(
@@ -161,7 +161,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p1"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p0_5: ComputedVecsFromDateIndex::forced_import(
@@ -169,7 +169,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p0_5"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p0_1: ComputedVecsFromDateIndex::forced_import(
@@ -177,7 +177,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p0_1"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p1sd: ComputedVecsFromDateIndex::forced_import(
@@ -185,7 +185,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p1sd"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p2sd: ComputedVecsFromDateIndex::forced_import(
@@ -193,7 +193,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p2sd"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p3sd: ComputedVecsFromDateIndex::forced_import(
@@ -201,7 +201,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p3sd"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_m1sd: ComputedVecsFromDateIndex::forced_import(
@@ -209,7 +209,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_m1sd"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_m2sd: ComputedVecsFromDateIndex::forced_import(
@@ -217,7 +217,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_m2sd"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_m3sd: ComputedVecsFromDateIndex::forced_import(
@@ -225,7 +225,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_m3sd"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p99_9_as_price: ComputedVecsFromDateIndex::forced_import(
@@ -233,7 +233,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p99_9_as_price"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p99_5_as_price: ComputedVecsFromDateIndex::forced_import(
@@ -241,7 +241,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p99_5_as_price"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p99_as_price: ComputedVecsFromDateIndex::forced_import(
@@ -249,7 +249,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p99_as_price"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p1_as_price: ComputedVecsFromDateIndex::forced_import(
@@ -257,7 +257,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p1_as_price"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p0_5_as_price: ComputedVecsFromDateIndex::forced_import(
@@ -265,7 +265,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p0_5_as_price"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p0_1_as_price: ComputedVecsFromDateIndex::forced_import(
@@ -273,7 +273,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p0_1_as_price"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p1sd_as_price: ComputedVecsFromDateIndex::forced_import(
@@ -281,7 +281,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p1sd_as_price"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p2sd_as_price: ComputedVecsFromDateIndex::forced_import(
@@ -289,7 +289,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p2sd_as_price"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_p3sd_as_price: ComputedVecsFromDateIndex::forced_import(
@@ -297,7 +297,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_p3sd_as_price"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_m1sd_as_price: ComputedVecsFromDateIndex::forced_import(
@@ -305,7 +305,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_m1sd_as_price"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_m2sd_as_price: ComputedVecsFromDateIndex::forced_import(
@@ -313,7 +313,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_m2sd_as_price"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_m3sd_as_price: ComputedVecsFromDateIndex::forced_import(
@@ -321,7 +321,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_m3sd_as_price"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
ratio_zscore: ComputedVecsFromDateIndex::forced_import(
@@ -329,7 +329,7 @@ impl ComputedRatioVecsFromDateIndex {
&format!("{name}_ratio_zscore"),
true,
version + VERSION + Version::ZERO,
compressed,
format,
options,
)?,
})

View File

@@ -3,7 +3,7 @@ use std::path::Path;
use brk_core::{Bitcoin, Dollars, Height, Result, Sats, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, CollectableVec, Compressed, EagerVec, StoredVec};
use brk_vec::{AnyCollectableVec, CollectableVec, EagerVec, Format, StoredVec};
use crate::vecs::{Indexes, fetched, indexes};
@@ -24,7 +24,7 @@ impl ComputedValueVecsFromHeight {
name: &str,
compute_source: bool,
version: Version,
compressed: Compressed,
format: Format,
options: StorableVecGeneatorOptions,
compute_dollars: bool,
) -> color_eyre::Result<Self> {
@@ -34,7 +34,7 @@ impl ComputedValueVecsFromHeight {
name,
compute_source,
version + VERSION,
compressed,
format,
options,
)?,
bitcoin: ComputedVecsFromHeight::forced_import(
@@ -42,7 +42,7 @@ impl ComputedValueVecsFromHeight {
&format!("{name}_in_btc"),
true,
version + VERSION,
compressed,
format,
options,
)?,
dollars: compute_dollars.then(|| {
@@ -51,7 +51,7 @@ impl ComputedValueVecsFromHeight {
&format!("{name}_in_usd"),
true,
version + VERSION,
compressed,
format,
options,
)
.unwrap()

View File

@@ -4,8 +4,8 @@ use brk_core::{Bitcoin, Close, Dollars, Height, Sats, TxIndex, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{
AnyCollectableVec, BoxedAnyIterableVec, CloneableAnyIterableVec, CollectableVec, Compressed,
Computation, ComputedVecFrom3, LazyVecFrom1, StoredIndex, StoredVec,
AnyCollectableVec, BoxedAnyIterableVec, CloneableAnyIterableVec, CollectableVec, Computation,
ComputedVecFrom3, Format, LazyVecFrom1, StoredIndex, StoredVec,
};
use crate::vecs::{Indexes, fetched, indexes};
@@ -44,7 +44,7 @@ impl ComputedValueVecsFromTxindex {
source: Option<BoxedAnyIterableVec<TxIndex, Sats>>,
version: Version,
computation: Computation,
compressed: Compressed,
format: Format,
fetched: Option<&fetched::Vecs>,
options: StorableVecGeneatorOptions,
) -> color_eyre::Result<Self> {
@@ -59,7 +59,7 @@ impl ComputedValueVecsFromTxindex {
name,
compute_source,
version + VERSION,
compressed,
format,
options,
)?;
@@ -80,7 +80,7 @@ impl ComputedValueVecsFromTxindex {
&name_in_btc,
false,
version + VERSION,
compressed,
format,
options,
)?;
@@ -90,7 +90,7 @@ impl ComputedValueVecsFromTxindex {
path,
&name_in_usd,
version + VERSION,
compressed,
format,
bitcoin_txindex.boxed_clone(),
indexes.txindex_to_height.boxed_clone(),
fetched.chainindexes_to_close.height.boxed_clone(),
@@ -126,7 +126,7 @@ impl ComputedValueVecsFromTxindex {
&name_in_usd,
false,
version + VERSION,
compressed,
format,
options,
)
.unwrap()

View File

@@ -10,10 +10,12 @@ use brk_core::{
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{
AnyCollectableVec, CloneableAnyIterableVec, Compressed, Computation, ComputedVec,
ComputedVecFrom1, ComputedVecFrom2, EagerVec, StoredIndex, VecIterator,
AnyCollectableVec, CloneableAnyIterableVec, Computation, ComputedVec, ComputedVecFrom1,
ComputedVecFrom2, EagerVec, Format, StoredIndex, VecIterator,
};
use crate::vecs::indexes;
const VERSION: Version = Version::ZERO;
#[derive(Clone)]
@@ -95,7 +97,7 @@ impl Vecs {
version: Version,
indexer: &Indexer,
computation: Computation,
compressed: Compressed,
format: Format,
) -> color_eyre::Result<Self> {
fs::create_dir_all(path)?;
@@ -104,7 +106,7 @@ impl Vecs {
path,
"outputindex",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().outputindex_to_value.boxed_clone(),
|index, _| Some(index),
)?;
@@ -114,7 +116,7 @@ impl Vecs {
path,
"inputindex",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().inputindex_to_outputindex.boxed_clone(),
|index, _| Some(index),
)?;
@@ -124,7 +126,7 @@ impl Vecs {
path,
"txindex",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().txindex_to_txid.boxed_clone(),
|index, _| Some(index),
)?;
@@ -134,7 +136,7 @@ impl Vecs {
path,
"input_count",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().txindex_to_first_inputindex.boxed_clone(),
indexer.vecs().inputindex_to_outputindex.boxed_clone(),
|index: TxIndex, txindex_to_first_inputindex_iter, inputindex_to_outputindex_iter| {
@@ -157,7 +159,7 @@ impl Vecs {
path,
"output_count",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().txindex_to_first_outputindex.boxed_clone(),
indexer.vecs().outputindex_to_value.boxed_clone(),
|index: TxIndex, txindex_to_first_outputindex_iter, outputindex_to_value_iter| {
@@ -180,7 +182,7 @@ impl Vecs {
path,
"p2pk33index",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().p2pk33index_to_p2pk33bytes.boxed_clone(),
|index, _| Some(index),
)?;
@@ -189,7 +191,7 @@ impl Vecs {
path,
"p2pk65index",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().p2pk65index_to_p2pk65bytes.boxed_clone(),
|index, _| Some(index),
)?;
@@ -198,7 +200,7 @@ impl Vecs {
path,
"p2pkhindex",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().p2pkhindex_to_p2pkhbytes.boxed_clone(),
|index, _| Some(index),
)?;
@@ -207,7 +209,7 @@ impl Vecs {
path,
"p2shindex",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().p2shindex_to_p2shbytes.boxed_clone(),
|index, _| Some(index),
)?;
@@ -216,7 +218,7 @@ impl Vecs {
path,
"p2trindex",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().p2trindex_to_p2trbytes.boxed_clone(),
|index, _| Some(index),
)?;
@@ -225,7 +227,7 @@ impl Vecs {
path,
"p2wpkhindex",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().p2wpkhindex_to_p2wpkhbytes.boxed_clone(),
|index, _| Some(index),
)?;
@@ -234,7 +236,7 @@ impl Vecs {
path,
"p2wshindex",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().p2wshindex_to_p2wshbytes.boxed_clone(),
|index, _| Some(index),
)?;
@@ -243,7 +245,7 @@ impl Vecs {
path,
"p2aindex",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().p2aindex_to_p2abytes.boxed_clone(),
|index, _| Some(index),
)?;
@@ -252,7 +254,7 @@ impl Vecs {
path,
"p2msindex",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().p2msindex_to_txindex.boxed_clone(),
|index, _| Some(index),
)?;
@@ -261,7 +263,7 @@ impl Vecs {
path,
"emptyoutputindex",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().emptyoutputindex_to_txindex.boxed_clone(),
|index, _| Some(index),
)?;
@@ -270,7 +272,7 @@ impl Vecs {
path,
"unknownoutputindex",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().unknownoutputindex_to_txindex.boxed_clone(),
|index, _| Some(index),
)?;
@@ -279,7 +281,7 @@ impl Vecs {
path,
"opreturnindex",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().opreturnindex_to_txindex.boxed_clone(),
|index, _| Some(index),
)?;
@@ -288,7 +290,7 @@ impl Vecs {
path,
"first_height",
version + VERSION + Version::ZERO,
compressed,
format,
)?;
let dateindex_to_dateindex = ComputedVec::forced_import_or_init_from_1(
@@ -296,7 +298,7 @@ impl Vecs {
path,
"dateindex",
version + VERSION + Version::ZERO,
compressed,
format,
dateindex_to_first_height.boxed_clone(),
|index, _| Some(index),
)?;
@@ -306,20 +308,20 @@ impl Vecs {
path,
"date",
version + VERSION + Version::ZERO,
compressed,
format,
dateindex_to_dateindex.boxed_clone(),
|index, _| Some(Date::from(index)),
)?;
let height_to_date =
EagerVec::forced_import(path, "date", version + VERSION + Version::ZERO, compressed)?;
EagerVec::forced_import(path, "date", version + VERSION + Version::ZERO, format)?;
let height_to_height = ComputedVec::forced_import_or_init_from_1(
computation,
path,
"height",
version + VERSION + Version::ZERO,
compressed,
format,
height_to_date.boxed_clone(),
|index, _| Some(index),
)?;
@@ -329,7 +331,7 @@ impl Vecs {
path,
"difficultyepoch",
version + VERSION + Version::ZERO,
compressed,
format,
height_to_height.boxed_clone(),
|index, _| Some(DifficultyEpoch::from(index)),
)?;
@@ -338,7 +340,7 @@ impl Vecs {
path,
"first_height",
version + VERSION + Version::ZERO,
compressed,
format,
)?;
let difficultyepoch_to_difficultyepoch = ComputedVec::forced_import_or_init_from_1(
@@ -346,7 +348,7 @@ impl Vecs {
path,
"difficultyepoch",
version + VERSION + Version::ZERO,
compressed,
format,
difficultyepoch_to_first_height.boxed_clone(),
|index, _| Some(index),
)?;
@@ -356,7 +358,7 @@ impl Vecs {
path,
"halvingepoch",
version + VERSION + Version::ZERO,
compressed,
format,
height_to_height.boxed_clone(),
|index, _| Some(HalvingEpoch::from(index)),
)?;
@@ -365,7 +367,7 @@ impl Vecs {
path,
"first_height",
version + VERSION + Version::ZERO,
compressed,
format,
)?;
let halvingepoch_to_halvingepoch = ComputedVec::forced_import_or_init_from_1(
@@ -373,23 +375,19 @@ impl Vecs {
path,
"halvingepoch",
version + VERSION + Version::ZERO,
compressed,
format,
halvingepoch_to_first_height.boxed_clone(),
|index, _| Some(index),
)?;
let dateindex_to_weekindex = EagerVec::forced_import(
path,
"weekindex",
version + VERSION + Version::ZERO,
compressed,
)?;
let dateindex_to_weekindex =
EagerVec::forced_import(path, "weekindex", version + VERSION + Version::ZERO, format)?;
let weekindex_to_first_dateindex = EagerVec::forced_import(
path,
"first_dateindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?;
let weekindex_to_weekindex = ComputedVec::forced_import_or_init_from_1(
@@ -397,7 +395,7 @@ impl Vecs {
path,
"weekindex",
version + VERSION + Version::ZERO,
compressed,
format,
weekindex_to_first_dateindex.boxed_clone(),
|index, _| Some(index),
)?;
@@ -406,14 +404,14 @@ impl Vecs {
path,
"monthindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?;
let monthindex_to_first_dateindex = EagerVec::forced_import(
path,
"first_dateindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?;
let monthindex_to_monthindex = ComputedVec::forced_import_or_init_from_1(
@@ -421,7 +419,7 @@ impl Vecs {
path,
"monthindex",
version + VERSION + Version::ZERO,
compressed,
format,
monthindex_to_first_dateindex.boxed_clone(),
|index, _| Some(index),
)?;
@@ -431,7 +429,7 @@ impl Vecs {
path,
"quarterindex",
version + VERSION + Version::ZERO,
compressed,
format,
monthindex_to_monthindex.boxed_clone(),
|index, _| Some(QuarterIndex::from(index)),
)?;
@@ -440,7 +438,7 @@ impl Vecs {
path,
"first_monthindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?;
let quarterindex_to_quarterindex = ComputedVec::forced_import_or_init_from_1(
@@ -448,7 +446,7 @@ impl Vecs {
path,
"quarterindex",
version + VERSION + Version::ZERO,
compressed,
format,
quarterindex_to_first_monthindex.boxed_clone(),
|index, _| Some(index),
)?;
@@ -458,7 +456,7 @@ impl Vecs {
path,
"yearindex",
version + VERSION + Version::ZERO,
compressed,
format,
monthindex_to_monthindex.boxed_clone(),
|index, _| Some(YearIndex::from(index)),
)?;
@@ -467,7 +465,7 @@ impl Vecs {
path,
"first_monthindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?;
let yearindex_to_yearindex = ComputedVec::forced_import_or_init_from_1(
@@ -475,7 +473,7 @@ impl Vecs {
path,
"yearindex",
version + VERSION + Version::ZERO,
compressed,
format,
yearindex_to_first_monthindex.boxed_clone(),
|index, _| Some(index),
)?;
@@ -485,7 +483,7 @@ impl Vecs {
path,
"decadeindex",
version + VERSION + Version::ZERO,
compressed,
format,
yearindex_to_yearindex.boxed_clone(),
|index, _| Some(DecadeIndex::from(index)),
)?;
@@ -494,7 +492,7 @@ impl Vecs {
path,
"first_yearindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?;
let decadeindex_to_decadeindex = ComputedVec::forced_import_or_init_from_1(
@@ -502,7 +500,7 @@ impl Vecs {
path,
"decadeindex",
version + VERSION + Version::ZERO,
compressed,
format,
decadeindex_to_first_yearindex.boxed_clone(),
|index, _| Some(index),
)?;
@@ -555,79 +553,79 @@ impl Vecs {
path,
"date_fixed",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_dateindex: EagerVec::forced_import(
path,
"dateindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
txindex_to_height: EagerVec::forced_import(
path,
"height",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_timestamp_fixed: EagerVec::forced_import(
path,
"timestamp_fixed",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_txindex_count: EagerVec::forced_import(
path,
"txindex_count",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
dateindex_to_height_count: EagerVec::forced_import(
path,
"height_count",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
weekindex_to_dateindex_count: EagerVec::forced_import(
path,
"dateindex_count",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
difficultyepoch_to_height_count: EagerVec::forced_import(
path,
"height_count",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
monthindex_to_dateindex_count: EagerVec::forced_import(
path,
"dateindex_count",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
quarterindex_to_monthindex_count: EagerVec::forced_import(
path,
"monthindex_count",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
yearindex_to_monthindex_count: EagerVec::forced_import(
path,
"monthindex_count",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
decadeindex_to_yearindex_count: EagerVec::forced_import(
path,
"yearindex_count",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
outputindex_to_txindex: EagerVec::forced_import(
path,
"txindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
})
}
@@ -1111,6 +1109,26 @@ pub struct Indexes {
pub halvingepoch: HalvingEpoch,
}
impl Indexes {
pub fn update_from_height(&mut self, height: Height, indexes: &indexes::Vecs) {
self.indexes.height = height;
self.dateindex = DateIndex::try_from(
indexes
.height_to_date_fixed
.into_iter()
.unwrap_get_inner(height),
)
.unwrap();
self.weekindex = WeekIndex::from(self.dateindex);
self.monthindex = MonthIndex::from(self.dateindex);
self.quarterindex = QuarterIndex::from(self.monthindex);
self.yearindex = YearIndex::from(self.monthindex);
self.decadeindex = DecadeIndex::from(self.dateindex);
self.difficultyepoch = DifficultyEpoch::from(self.height);
self.halvingepoch = HalvingEpoch::from(self.height);
}
}
impl Deref for Indexes {
type Target = brk_indexer::Indexes;
fn deref(&self) -> &Self::Target {

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@ use std::{fs, path::Path};
use brk_core::{DifficultyEpoch, HalvingEpoch, StoredF64, Version};
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, Compressed, Computation, VecIterator};
use brk_vec::{AnyCollectableVec, Computation, Format, VecIterator};
use super::{
Indexes,
@@ -25,7 +25,7 @@ impl Vecs {
path: &Path,
version: Version,
_computation: Computation,
compressed: Compressed,
format: Format,
) -> color_eyre::Result<Self> {
fs::create_dir_all(path)?;
@@ -35,7 +35,7 @@ impl Vecs {
"difficulty",
false,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_last(),
)?,
indexes_to_difficultyepoch: ComputedVecsFromDateIndex::forced_import(
@@ -43,7 +43,7 @@ impl Vecs {
"difficultyepoch",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_last(),
)?,
indexes_to_halvingepoch: ComputedVecsFromDateIndex::forced_import(
@@ -51,7 +51,7 @@ impl Vecs {
"halvingepoch",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_last(),
)?,
})

View File

@@ -4,7 +4,7 @@ use brk_core::Version;
use brk_exit::Exit;
use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
use brk_vec::{AnyCollectableVec, Compressed, Computation};
use brk_vec::{AnyCollectableVec, Computation, Format};
use fjall::TransactionalKeyspace;
pub mod blocks;
@@ -40,7 +40,7 @@ impl Vecs {
indexer: &Indexer,
fetch: bool,
computation: Computation,
compressed: Compressed,
format: Format,
keyspace: &TransactionalKeyspace,
) -> color_eyre::Result<Self> {
fs::create_dir_all(path)?;
@@ -50,7 +50,7 @@ impl Vecs {
version + VERSION + Version::ZERO,
indexer,
computation,
compressed,
format,
)?;
let fetched = fetch.then(|| {
@@ -58,7 +58,7 @@ impl Vecs {
path,
version + VERSION + Version::ZERO,
computation,
compressed,
format,
)
.unwrap()
});
@@ -68,31 +68,31 @@ impl Vecs {
path,
version + VERSION + Version::ZERO,
computation,
compressed,
format,
)?,
mining: mining::Vecs::forced_import(
path,
version + VERSION + Version::ZERO,
computation,
compressed,
format,
)?,
constants: constants::Vecs::forced_import(
path,
version + VERSION + Version::ZERO,
computation,
compressed,
format,
)?,
market: market::Vecs::forced_import(
path,
version + VERSION + Version::ZERO,
computation,
compressed,
format,
)?,
stateful: stateful::Vecs::forced_import(
path,
version + VERSION + Version::ZERO,
computation,
compressed,
format,
fetched.as_ref(),
keyspace,
)?,
@@ -102,7 +102,7 @@ impl Vecs {
indexer,
&indexes,
computation,
compressed,
format,
fetched.as_ref(),
)?,
indexes,
@@ -162,7 +162,8 @@ impl Vecs {
&self.indexes,
&self.transactions,
self.fetched.as_ref(),
&starting_indexes,
&self.market,
starting_indexes,
exit,
)?;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +1,20 @@
use std::{collections::BTreeMap, ops::ControlFlow};
use brk_core::{CheckedSub, Dollars, HalvingEpoch, Height, Timestamp};
use brk_core::{CheckedSub, Dollars, HalvingEpoch, Height, Result, Timestamp};
use brk_exit::Exit;
use brk_state::{BlockState, OutputFilter, Outputs, Transacted};
use brk_vec::StoredIndex;
use rayon::prelude::*;
use crate::vecs::Indexes;
use super::cohort;
pub trait OutputCohorts {
fn tick_tock_next_block(&mut self, chain_state: &[BlockState], timestamp: Timestamp);
fn send(&mut self, height_to_sent: BTreeMap<Height, Transacted>, chain_state: &[BlockState]);
fn receive(&mut self, received: Transacted, height: Height, price: Option<Dollars>);
fn compute_overlaping_vecs(&mut self, starting_indexes: &Indexes, exit: &Exit) -> Result<()>;
}
impl OutputCohorts for Outputs<(OutputFilter, cohort::Vecs)> {
@@ -21,27 +25,12 @@ impl OutputCohorts for Outputs<(OutputFilter, cohort::Vecs)> {
let prev_timestamp = chain_state.last().unwrap().timestamp;
self.by_term
self.by_date_range
.as_mut_vec()
.into_par_iter()
.chain(self.by_up_to.as_mut_vec())
.chain(self.by_from.as_mut_vec())
.chain(self.by_range.as_mut_vec())
.for_each(|(filter, v)| {
let state = &mut v.state;
let mut check_days_old = |days_old: usize| -> bool {
match filter {
OutputFilter::From(from) => *from <= days_old,
OutputFilter::To(to) => *to > days_old,
OutputFilter::Range(range) => range.contains(&days_old),
OutputFilter::All
| OutputFilter::Epoch(_)
| OutputFilter::Size
| OutputFilter::Type(_) => unreachable!(),
}
};
let _ = chain_state
.iter()
.try_for_each(|block_state| -> ControlFlow<()> {
@@ -54,8 +43,8 @@ impl OutputCohorts for Outputs<(OutputFilter, cohort::Vecs)> {
return ControlFlow::Continue(());
}
let is = check_days_old(days_old);
let was = check_days_old(prev_days_old);
let is = filter.contains(days_old);
let was = filter.contains(prev_days_old);
if is && !was {
state.increment(&block_state.supply, block_state.price);
@@ -70,12 +59,9 @@ impl OutputCohorts for Outputs<(OutputFilter, cohort::Vecs)> {
fn send(&mut self, height_to_sent: BTreeMap<Height, Transacted>, chain_state: &[BlockState]) {
let mut time_based_vecs = self
.by_term
.by_date_range
.as_mut_vec()
.into_iter()
.chain(self.by_up_to.as_mut_vec())
.chain(self.by_from.as_mut_vec())
.chain(self.by_range.as_mut_vec())
.chain(self.by_epoch.as_mut_vec())
.collect::<Vec<_>>();
@@ -95,13 +81,6 @@ impl OutputCohorts for Outputs<(OutputFilter, cohort::Vecs)> {
.as_second()
>= 60 * 60;
self.all.1.state.send(
&sent.spendable_supply,
current_price,
prev_price,
older_than_hour,
);
time_based_vecs
.iter_mut()
.filter(|(filter, _)| match filter {
@@ -131,14 +110,16 @@ impl OutputCohorts for Outputs<(OutputFilter, cohort::Vecs)> {
},
);
sent.by_size.into_iter().for_each(|(group, supply_state)| {
self.by_size.get_mut(group).1.state.send(
&supply_state,
current_price,
prev_price,
older_than_hour,
);
});
sent.by_size_group
.into_iter()
.for_each(|(group, supply_state)| {
self.by_size_range.get_mut(group).1.state.send(
&supply_state,
current_price,
prev_price,
older_than_hour,
);
});
});
}
@@ -146,13 +127,10 @@ impl OutputCohorts for Outputs<(OutputFilter, cohort::Vecs)> {
let supply_state = received.spendable_supply;
[
&mut self.all.1,
&mut self.by_term.short.1,
&mut self.by_date_range.start_to_1d.1,
&mut self.by_epoch.mut_vec_from_height(height).1,
// Skip from and range as can't receive in the past
]
.into_iter()
.chain(self.by_up_to.as_mut_vec().map(|(_, v)| v))
.for_each(|v| {
v.state.receive(&supply_state, price);
});
@@ -169,14 +147,105 @@ impl OutputCohorts for Outputs<(OutputFilter, cohort::Vecs)> {
});
received
.by_size
.by_size_group
.into_iter()
.for_each(|(group, supply_state)| {
self.by_size
self.by_size_range
.get_mut(group)
.1
.state
.receive(&supply_state, price);
});
}
fn compute_overlaping_vecs(&mut self, starting_indexes: &Indexes, exit: &Exit) -> Result<()> {
self.all
.1
.compute_from_stateful(starting_indexes, &self.by_epoch.vecs(), exit)?;
self.by_from_date
.as_mut_vec()
.into_iter()
.try_for_each(|(filter, vecs)| {
vecs.compute_from_stateful(
starting_indexes,
self.by_date_range
.as_vec()
.into_iter()
.filter(|(other, _)| filter.includes(other))
.map(|(_, v)| v)
.collect::<Vec<_>>()
.as_slice(),
exit,
)
})?;
self.by_up_to_date
.as_mut_vec()
.into_iter()
.try_for_each(|(filter, vecs)| {
vecs.compute_from_stateful(
starting_indexes,
self.by_date_range
.as_vec()
.into_iter()
.filter(|(other, _)| filter.includes(other))
.map(|(_, v)| v)
.collect::<Vec<_>>()
.as_slice(),
exit,
)
})?;
self.by_term
.as_mut_vec()
.into_iter()
.try_for_each(|(filter, vecs)| {
vecs.compute_from_stateful(
starting_indexes,
self.by_date_range
.as_vec()
.into_iter()
.filter(|(other, _)| filter.includes(other))
.map(|(_, v)| v)
.collect::<Vec<_>>()
.as_slice(),
exit,
)
})?;
self.by_up_to_size
.as_mut_vec()
.into_iter()
.try_for_each(|(filter, vecs)| {
vecs.compute_from_stateful(
starting_indexes,
self.by_date_range
.as_vec()
.into_iter()
.filter(|(other, _)| filter.includes(other))
.map(|(_, v)| v)
.collect::<Vec<_>>()
.as_slice(),
exit,
)
})?;
self.by_from_size
.as_mut_vec()
.into_iter()
.try_for_each(|(filter, vecs)| {
vecs.compute_from_stateful(
starting_indexes,
self.by_size_range
.as_vec()
.into_iter()
.filter(|(other, _)| filter.includes(other))
.map(|(_, v)| v)
.collect::<Vec<_>>()
.as_slice(),
exit,
)
})
}
}

View File

@@ -7,8 +7,8 @@ use brk_core::{
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_vec::{
AnyCollectableVec, AnyIterableVec, CloneableAnyIterableVec, Compressed, Computation,
ComputedVec, ComputedVecFrom1, ComputedVecFrom2, ComputedVecFrom3, StoredIndex, VecIterator,
AnyCollectableVec, AnyIterableVec, CloneableAnyIterableVec, Computation, ComputedVec,
ComputedVecFrom1, ComputedVecFrom2, ComputedVecFrom3, Format, StoredIndex, VecIterator,
};
use super::{
@@ -93,7 +93,7 @@ impl Vecs {
indexer: &Indexer,
indexes: &indexes::Vecs,
computation: Computation,
compressed: Compressed,
format: Format,
fetched: Option<&fetched::Vecs>,
) -> color_eyre::Result<Self> {
let compute_dollars = fetched.is_some();
@@ -105,7 +105,7 @@ impl Vecs {
path,
"value",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().inputindex_to_outputindex.boxed_clone(),
indexer.vecs().outputindex_to_value.boxed_clone(),
|index: InputIndex, inputindex_to_outputindex_iter, outputindex_to_value_iter| {
@@ -132,7 +132,7 @@ impl Vecs {
path,
"weight",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().txindex_to_base_size.boxed_clone(),
indexer.vecs().txindex_to_total_size.boxed_clone(),
|index: TxIndex, txindex_to_base_size_iter, txindex_to_total_size_iter| {
@@ -160,7 +160,7 @@ impl Vecs {
path,
"vsize",
version + VERSION + Version::ZERO,
compressed,
format,
txindex_to_weight.boxed_clone(),
|index: TxIndex, iter| {
let index = index.unwrap_to_usize();
@@ -177,7 +177,7 @@ impl Vecs {
path,
"is_coinbase",
version + VERSION + Version::ZERO,
compressed,
format,
indexes.txindex_to_height.boxed_clone(),
indexer.vecs().height_to_first_txindex.boxed_clone(),
|index: TxIndex, txindex_to_height_iter, height_to_first_txindex_iter| {
@@ -201,7 +201,7 @@ impl Vecs {
path,
"input_value",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().txindex_to_first_inputindex.boxed_clone(),
indexes.txindex_to_input_count.boxed_clone(),
inputindex_to_value.boxed_clone(),
@@ -238,7 +238,7 @@ impl Vecs {
// "input_value",
// true,
// version + VERSION + Version::ZERO,
// compressed,
// format,
// StorableVecGeneatorOptions::default()
// .add_average()
// .add_sum()
@@ -250,7 +250,7 @@ impl Vecs {
path,
"output_value",
version + VERSION + Version::ZERO,
compressed,
format,
indexer.vecs().txindex_to_first_outputindex.boxed_clone(),
indexes.txindex_to_output_count.boxed_clone(),
indexer.vecs().outputindex_to_value.boxed_clone(),
@@ -287,7 +287,7 @@ impl Vecs {
// "output_value",
// true,
// version + VERSION + Version::ZERO,
// compressed,
// format,
// StorableVecGeneatorOptions::default()
// .add_average()
// .add_sum()
@@ -299,7 +299,7 @@ impl Vecs {
path,
"fee",
version + VERSION + Version::ZERO,
compressed,
format,
txindex_to_input_value.boxed_clone(),
txindex_to_output_value.boxed_clone(),
|txindex: TxIndex, input_iter, output_iter| {
@@ -322,7 +322,7 @@ impl Vecs {
path,
"feerate",
version + VERSION + Version::ZERO,
compressed,
format,
txindex_to_fee.boxed_clone(),
txindex_to_vsize.boxed_clone(),
|txindex: TxIndex, fee_iter, vsize_iter| {
@@ -343,7 +343,7 @@ impl Vecs {
"tx_count",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_average()
.add_minmax()
@@ -356,7 +356,7 @@ impl Vecs {
"input_count",
false,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_average()
.add_minmax()
@@ -369,7 +369,7 @@ impl Vecs {
"output_count",
false,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_average()
.add_minmax()
@@ -382,7 +382,7 @@ impl Vecs {
"tx_v1",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
@@ -392,7 +392,7 @@ impl Vecs {
"tx_v2",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
@@ -402,7 +402,7 @@ impl Vecs {
"tx_v3",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
@@ -414,7 +414,7 @@ impl Vecs {
Some(txindex_to_fee.boxed_clone()),
version + VERSION + Version::ZERO,
computation,
compressed,
format,
fetched,
StorableVecGeneatorOptions::default()
.add_sum()
@@ -428,7 +428,7 @@ impl Vecs {
"feerate",
false,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_percentiles()
.add_minmax()
@@ -439,7 +439,7 @@ impl Vecs {
"tx_vsize",
false,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_percentiles()
.add_minmax()
@@ -450,7 +450,7 @@ impl Vecs {
"tx_weight",
false,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_percentiles()
.add_minmax()
@@ -461,7 +461,7 @@ impl Vecs {
"subsidy",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_percentiles()
.add_sum()
@@ -475,7 +475,7 @@ impl Vecs {
"coinbase",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative()
@@ -489,7 +489,7 @@ impl Vecs {
"unclaimed_rewards",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_sum()
.add_cumulative(),
@@ -500,7 +500,7 @@ impl Vecs {
"p2a_count",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_average()
.add_minmax()
@@ -513,7 +513,7 @@ impl Vecs {
"p2ms_count",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_average()
.add_minmax()
@@ -526,7 +526,7 @@ impl Vecs {
"p2pk33_count",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_average()
.add_minmax()
@@ -539,7 +539,7 @@ impl Vecs {
"p2pk65_count",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_average()
.add_minmax()
@@ -552,7 +552,7 @@ impl Vecs {
"p2pkh_count",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_average()
.add_minmax()
@@ -565,7 +565,7 @@ impl Vecs {
"p2sh_count",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_average()
.add_minmax()
@@ -578,7 +578,7 @@ impl Vecs {
"p2tr_count",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_average()
.add_minmax()
@@ -591,7 +591,7 @@ impl Vecs {
"p2wpkh_count",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_average()
.add_minmax()
@@ -604,7 +604,7 @@ impl Vecs {
"p2wsh_count",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_average()
.add_minmax()
@@ -617,7 +617,7 @@ impl Vecs {
"opreturn_count",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_average()
.add_minmax()
@@ -630,7 +630,7 @@ impl Vecs {
"unknownoutput_count",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_average()
.add_minmax()
@@ -643,7 +643,7 @@ impl Vecs {
"emptyoutput_count",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default()
.add_average()
.add_minmax()
@@ -656,7 +656,7 @@ impl Vecs {
"exact_utxo_count",
true,
version + VERSION + Version::ZERO,
compressed,
format,
StorableVecGeneatorOptions::default().add_last(),
)?,
txindex_to_is_coinbase,

View File

@@ -104,7 +104,7 @@ impl From<Cents> for u128 {
impl Mul<Cents> for Cents {
type Output = Cents;
fn mul(self, rhs: Cents) -> Self::Output {
Self(self.0 * rhs.0)
Self(self.0.checked_mul(rhs.0).unwrap())
}
}

View File

@@ -11,7 +11,7 @@ use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
use crate::{CheckedSub, copy_first_8bytes};
use super::{Bitcoin, Cents, Close, Sats, StoredF32, StoredF64};
use super::{Bitcoin, Cents, Close, High, Sats, StoredF32, StoredF64};
#[derive(
Debug, Default, Clone, Copy, Deref, FromBytes, Immutable, IntoBytes, KnownLayout, Serialize,
@@ -63,6 +63,12 @@ impl From<Close<Dollars>> for Dollars {
}
}
impl From<High<Dollars>> for Dollars {
fn from(value: High<Dollars>) -> Self {
Self(value.0)
}
}
impl From<usize> for Dollars {
fn from(value: usize) -> Self {
Self(value as f64)
@@ -131,6 +137,27 @@ impl Div<Bitcoin> for Dollars {
}
}
impl Mul<Dollars> for Dollars {
type Output = Self;
fn mul(self, rhs: Dollars) -> Self::Output {
Self::from(Cents::from(self) * Cents::from(rhs))
}
}
impl Mul<Close<Dollars>> for Dollars {
type Output = Self;
fn mul(self, rhs: Close<Dollars>) -> Self::Output {
Self::from(Cents::from(self) * Cents::from(*rhs))
}
}
impl Mul<Dollars> for Close<Dollars> {
type Output = Dollars;
fn mul(self, rhs: Dollars) -> Self::Output {
Dollars::from(Cents::from(*self) * Cents::from(rhs))
}
}
impl Mul<Bitcoin> for Dollars {
type Output = Self;
fn mul(self, rhs: Bitcoin) -> Self::Output {
@@ -138,6 +165,13 @@ impl Mul<Bitcoin> for Dollars {
}
}
impl Mul<Bitcoin> for Close<Dollars> {
type Output = Dollars;
fn mul(self, rhs: Bitcoin) -> Self::Output {
*self * Sats::from(rhs)
}
}
impl Mul<Sats> for Dollars {
type Output = Self;
fn mul(self, rhs: Sats) -> Self::Output {
@@ -186,6 +220,12 @@ impl From<u128> for Dollars {
}
}
impl From<StoredF64> for Dollars {
fn from(value: StoredF64) -> Self {
Self(*value)
}
}
impl From<Close<Dollars>> for u128 {
fn from(value: Close<Dollars>) -> Self {
u128::from(*value)

View File

@@ -207,3 +207,10 @@ impl From<Sats> for ByteView {
Self::from(&value)
}
}
impl Mul<Sats> for usize {
type Output = Sats;
fn mul(self, rhs: Sats) -> Self::Output {
Self::Output::from(rhs.0 * self as u64)
}
}

View File

@@ -1,6 +1,7 @@
use std::{
fs,
io::{self, Read},
iter::Sum,
ops::Add,
path::Path,
};
@@ -70,3 +71,9 @@ impl Add<Version> for Version {
Self(self.0 + rhs.0)
}
}
impl Sum for Version {
fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
iter.fold(Self::ZERO, Add::add)
}
}

View File

@@ -4,6 +4,7 @@ use brk_core::default_bitcoin_path;
use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_parser::Parser;
use brk_vec::Format;
fn main() -> color_eyre::Result<()> {
color_eyre::install()?;
@@ -24,7 +25,7 @@ fn main() -> color_eyre::Result<()> {
let outputs = Path::new("../../_outputs");
let mut indexer = Indexer::new(outputs, false, false)?;
let mut indexer = Indexer::new(outputs, Format::Raw, false)?;
indexer.import_stores()?;
indexer.import_vecs()?;

View File

@@ -19,7 +19,7 @@ use brk_core::{
use bitcoin::{Transaction, TxIn, TxOut};
use brk_exit::Exit;
use brk_parser::Parser;
use brk_vec::{AnyVec, Compressed, VecIterator};
use brk_vec::{AnyVec, Format, VecIterator};
use color_eyre::eyre::{ContextCompat, eyre};
use fjall::TransactionalKeyspace;
use log::{error, info};
@@ -42,13 +42,13 @@ pub struct Indexer {
vecs: Option<Vecs>,
stores: Option<Stores>,
check_collisions: bool,
compressed: Compressed,
format: Format,
}
impl Indexer {
pub fn new(
outputs_dir: &Path,
compressed: bool,
format: Format,
check_collisions: bool,
) -> color_eyre::Result<Self> {
setrlimit()?;
@@ -56,7 +56,7 @@ impl Indexer {
path: outputs_dir.to_owned(),
vecs: None,
stores: None,
compressed: Compressed::from(compressed),
format,
check_collisions,
})
}
@@ -65,7 +65,7 @@ impl Indexer {
self.vecs = Some(Vecs::forced_import(
&self.path.join("vecs/indexed"),
VERSION + Version::ZERO,
self.compressed,
self.format,
)?);
Ok(())
}
@@ -120,6 +120,7 @@ impl Indexer {
if starting_indexes.height > Height::try_from(rpc)?
|| end.is_some_and(|end| starting_indexes.height > end)
{
info!("Up to date, nothing to index.");
return Ok(starting_indexes);
}

View File

@@ -8,7 +8,7 @@ use brk_core::{
StoredU32, StoredUsize, Timestamp, TxIndex, TxVersion, Txid, UnknownOutputIndex, Version,
Weight,
};
use brk_vec::{AnyCollectableVec, AnyIndexedVec, Compressed, IndexedVec};
use brk_vec::{AnyCollectableVec, AnyIndexedVec, Format, IndexedVec};
use rayon::prelude::*;
use crate::Indexes;
@@ -69,7 +69,7 @@ impl Vecs {
pub fn forced_import(
path: &Path,
version: Version,
compressed: Compressed,
format: Format,
) -> color_eyre::Result<Self> {
fs::create_dir_all(path)?;
@@ -78,265 +78,265 @@ impl Vecs {
path,
"txindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_blockhash: IndexedVec::forced_import(
path,
"blockhash",
version + VERSION + Version::ZERO,
Compressed::NO,
Format::Raw,
)?,
height_to_difficulty: IndexedVec::forced_import(
path,
"difficulty",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_first_emptyoutputindex: IndexedVec::forced_import(
path,
"first_emptyoutputindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_first_inputindex: IndexedVec::forced_import(
path,
"first_inputindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_first_opreturnindex: IndexedVec::forced_import(
path,
"first_opreturnindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_first_outputindex: IndexedVec::forced_import(
path,
"first_outputindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_first_p2aindex: IndexedVec::forced_import(
path,
"first_p2aindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_first_p2msindex: IndexedVec::forced_import(
path,
"first_p2msindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_first_p2pk33index: IndexedVec::forced_import(
path,
"first_p2pk33index",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_first_p2pk65index: IndexedVec::forced_import(
path,
"first_p2pk65index",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_first_p2pkhindex: IndexedVec::forced_import(
path,
"first_p2pkhindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_first_p2shindex: IndexedVec::forced_import(
path,
"first_p2shindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_first_p2trindex: IndexedVec::forced_import(
path,
"first_p2trindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_first_p2wpkhindex: IndexedVec::forced_import(
path,
"first_p2wpkhindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_first_p2wshindex: IndexedVec::forced_import(
path,
"first_p2wshindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_first_txindex: IndexedVec::forced_import(
path,
"first_txindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_first_unknownoutputindex: IndexedVec::forced_import(
path,
"first_unknownoutputindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_timestamp: IndexedVec::forced_import(
path,
"timestamp",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_total_size: IndexedVec::forced_import(
path,
"total_size",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
height_to_weight: IndexedVec::forced_import(
path,
"weight",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
inputindex_to_outputindex: IndexedVec::forced_import(
path,
"outputindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
opreturnindex_to_txindex: IndexedVec::forced_import(
path,
"txindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
outputindex_to_outputtype: IndexedVec::forced_import(
path,
"outputtype",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
outputindex_to_outputtypeindex: IndexedVec::forced_import(
path,
"outputtypeindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
outputindex_to_value: IndexedVec::forced_import(
path,
"value",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
p2aindex_to_p2abytes: IndexedVec::forced_import(
path,
"p2abytes",
version + VERSION + Version::ZERO,
Compressed::NO,
Format::Raw,
)?,
p2msindex_to_txindex: IndexedVec::forced_import(
path,
"txindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
p2pk33index_to_p2pk33bytes: IndexedVec::forced_import(
path,
"p2pk33bytes",
version + VERSION + Version::ZERO,
Compressed::NO,
Format::Raw,
)?,
p2pk65index_to_p2pk65bytes: IndexedVec::forced_import(
path,
"p2pk65bytes",
version + VERSION + Version::ZERO,
Compressed::NO,
Format::Raw,
)?,
p2pkhindex_to_p2pkhbytes: IndexedVec::forced_import(
path,
"p2pkhbytes",
version + VERSION + Version::ZERO,
Compressed::NO,
Format::Raw,
)?,
p2shindex_to_p2shbytes: IndexedVec::forced_import(
path,
"p2shbytes",
version + VERSION + Version::ZERO,
Compressed::NO,
Format::Raw,
)?,
p2trindex_to_p2trbytes: IndexedVec::forced_import(
path,
"p2trbytes",
version + VERSION + Version::ZERO,
Compressed::NO,
Format::Raw,
)?,
p2wpkhindex_to_p2wpkhbytes: IndexedVec::forced_import(
path,
"p2wpkhbytes",
version + VERSION + Version::ZERO,
Compressed::NO,
Format::Raw,
)?,
p2wshindex_to_p2wshbytes: IndexedVec::forced_import(
path,
"p2wshbytes",
version + VERSION + Version::ZERO,
Compressed::NO,
Format::Raw,
)?,
txindex_to_base_size: IndexedVec::forced_import(
path,
"base_size",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
txindex_to_first_inputindex: IndexedVec::forced_import(
path,
"first_inputindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
txindex_to_first_outputindex: IndexedVec::forced_import(
path,
"first_outputindex",
version + VERSION + Version::ZERO,
Compressed::NO,
Format::Raw,
)?,
txindex_to_is_explicitly_rbf: IndexedVec::forced_import(
path,
"is_explicitly_rbf",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
txindex_to_rawlocktime: IndexedVec::forced_import(
path,
"rawlocktime",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
txindex_to_total_size: IndexedVec::forced_import(
path,
"total_size",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
txindex_to_txid: IndexedVec::forced_import(
path,
"txid",
version + VERSION + Version::ZERO,
Compressed::NO,
Format::Raw,
)?,
txindex_to_txversion: IndexedVec::forced_import(
path,
"txversion",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
unknownoutputindex_to_txindex: IndexedVec::forced_import(
path,
"txindex",
version + VERSION + Version::ZERO,
compressed,
format,
)?,
})
}

View File

@@ -3,19 +3,19 @@ use std::path::Path;
use brk_computer::Computer;
use brk_indexer::Indexer;
use brk_query::{Index, Query};
use brk_vec::Computation;
use brk_vec::{Computation, Format};
pub fn main() -> color_eyre::Result<()> {
color_eyre::install()?;
let outputs_dir = Path::new("../../_outputs");
let compressed = true;
let format = Format::Compressed;
let mut indexer = Indexer::new(outputs_dir, compressed, true)?;
let mut indexer = Indexer::new(outputs_dir, format, true)?;
indexer.import_vecs()?;
let mut computer = Computer::new(outputs_dir, None, compressed);
let mut computer = Computer::new(outputs_dir, None, format);
computer.import_vecs(&indexer, Computation::Lazy)?;
let query = Query::build(&indexer, &computer);

View File

@@ -20,10 +20,17 @@ impl<'a> VecTrees<'a> {
&& !(split.len() == 3
&& split.get(1).is_some_and(|s| {
s == &"up"
|| s == &"start"
|| s.ends_with("relative")
|| s.starts_with("from")
|| s == &"cumulative_up"
|| s.starts_with("cumulative_from")
}))
&& !(split.len() == 4
&& split
.get(1)
.is_some_and(|s| s == &"up" || s == &"start" || s.starts_with("from"))
&& split.get(2).is_some_and(|s| s.ends_with("relative")))
{
dbg!(&name, &split);
panic!();

View File

@@ -8,7 +8,7 @@ use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
use brk_parser::Parser;
use brk_server::{Server, Website};
use brk_vec::Computation;
use brk_vec::{Computation, Format};
pub fn main() -> color_eyre::Result<()> {
color_eyre::install()?;
@@ -29,15 +29,15 @@ pub fn main() -> color_eyre::Result<()> {
let outputs_dir = Path::new("../../_outputs");
let compressed = true;
let format = Format::Compressed;
let mut indexer = Indexer::new(outputs_dir, compressed, true)?;
let mut indexer = Indexer::new(outputs_dir, format, true)?;
indexer.import_stores()?;
indexer.import_vecs()?;
let fetcher = Some(Fetcher::import(None)?);
let mut computer = Computer::new(outputs_dir, fetcher, compressed);
let mut computer = Computer::new(outputs_dir, fetcher, format);
computer.import_stores(&indexer)?;
computer.import_vecs(&indexer, Computation::Lazy)?;

View File

@@ -1,7 +1,8 @@
use super::OutputFilter;
#[derive(Default, Clone)]
pub struct OutputsByRange<T> {
pub struct OutputsByDateRange<T> {
pub start_to_1d: T,
pub _1d_to_1w: T,
pub _1w_to_1m: T,
pub _1m_to_3m: T,
@@ -14,11 +15,13 @@ pub struct OutputsByRange<T> {
pub _5y_to_7y: T,
pub _7y_to_10y: T,
pub _10y_to_15y: T,
pub _15y_to_end: T,
}
impl<T> From<OutputsByRange<T>> for OutputsByRange<(OutputFilter, T)> {
fn from(value: OutputsByRange<T>) -> Self {
impl<T> From<OutputsByDateRange<T>> for OutputsByDateRange<(OutputFilter, T)> {
fn from(value: OutputsByDateRange<T>) -> Self {
Self {
start_to_1d: (OutputFilter::To(1), value.start_to_1d),
_1d_to_1w: (OutputFilter::Range(1..7), value._1d_to_1w),
_1w_to_1m: (OutputFilter::Range(7..30), value._1w_to_1m),
_1m_to_3m: (OutputFilter::Range(30..3 * 30), value._1m_to_3m),
@@ -31,13 +34,34 @@ impl<T> From<OutputsByRange<T>> for OutputsByRange<(OutputFilter, T)> {
_5y_to_7y: (OutputFilter::Range(5 * 365..7 * 365), value._5y_to_7y),
_7y_to_10y: (OutputFilter::Range(7 * 365..10 * 365), value._7y_to_10y),
_10y_to_15y: (OutputFilter::Range(10 * 365..15 * 365), value._10y_to_15y),
_15y_to_end: (OutputFilter::From(15 * 365), value._15y_to_end),
}
}
}
impl<T> OutputsByRange<T> {
pub fn as_mut_vec(&mut self) -> [&mut T; 12] {
impl<T> OutputsByDateRange<T> {
pub fn as_vec(&mut self) -> [&T; 14] {
[
&self.start_to_1d,
&self._1d_to_1w,
&self._1w_to_1m,
&self._1m_to_3m,
&self._3m_to_6m,
&self._6m_to_1y,
&self._1y_to_2y,
&self._2y_to_3y,
&self._3y_to_4y,
&self._4y_to_5y,
&self._5y_to_7y,
&self._7y_to_10y,
&self._10y_to_15y,
&self._15y_to_end,
]
}
pub fn as_mut_vec(&mut self) -> [&mut T; 14] {
[
&mut self.start_to_1d,
&mut self._1d_to_1w,
&mut self._1w_to_1m,
&mut self._1m_to_3m,
@@ -50,13 +74,15 @@ impl<T> OutputsByRange<T> {
&mut self._5y_to_7y,
&mut self._7y_to_10y,
&mut self._10y_to_15y,
&mut self._15y_to_end,
]
}
}
impl<T> OutputsByRange<(OutputFilter, T)> {
pub fn vecs(&self) -> [&T; 12] {
impl<T> OutputsByDateRange<(OutputFilter, T)> {
pub fn vecs(&self) -> [&T; 14] {
[
&self.start_to_1d.1,
&self._1d_to_1w.1,
&self._1w_to_1m.1,
&self._1m_to_3m.1,
@@ -69,6 +95,7 @@ impl<T> OutputsByRange<(OutputFilter, T)> {
&self._5y_to_7y.1,
&self._7y_to_10y.1,
&self._10y_to_15y.1,
&self._15y_to_end.1,
]
}
}

View File

@@ -1,7 +1,7 @@
use super::OutputFilter;
#[derive(Default, Clone)]
pub struct OutputsByFrom<T> {
pub struct OutputsByFromDate<T> {
pub _1d: T,
pub _1w: T,
pub _1m: T,
@@ -22,7 +22,7 @@ pub struct OutputsByFrom<T> {
pub _15y: T,
}
impl<T> OutputsByFrom<T> {
impl<T> OutputsByFromDate<T> {
pub fn as_mut_vec(&mut self) -> [&mut T; 18] {
[
&mut self._1d,
@@ -47,7 +47,7 @@ impl<T> OutputsByFrom<T> {
}
}
impl<T> OutputsByFrom<(OutputFilter, T)> {
impl<T> OutputsByFromDate<(OutputFilter, T)> {
pub fn vecs(&self) -> [&T; 18] {
[
&self._1d.1,
@@ -72,8 +72,8 @@ impl<T> OutputsByFrom<(OutputFilter, T)> {
}
}
impl<T> From<OutputsByFrom<T>> for OutputsByFrom<(OutputFilter, T)> {
fn from(value: OutputsByFrom<T>) -> Self {
impl<T> From<OutputsByFromDate<T>> for OutputsByFromDate<(OutputFilter, T)> {
fn from(value: OutputsByFromDate<T>) -> Self {
Self {
_1d: (OutputFilter::From(1), value._1d),
_1w: (OutputFilter::From(7), value._1w),

View File

@@ -0,0 +1,50 @@
use brk_core::Sats;
use super::OutputFilter;
#[derive(Default, Clone)]
pub struct OutputsByFromSize<T> {
pub _1_000sats: T,
pub _1btc: T,
pub _10btc: T,
pub _100btc: T,
}
impl<T> OutputsByFromSize<T> {
pub fn as_mut_vec(&mut self) -> [&mut T; 4] {
[
&mut self._1_000sats,
&mut self._1btc,
&mut self._10btc,
&mut self._100btc,
]
}
}
impl<T> OutputsByFromSize<(OutputFilter, T)> {
pub fn vecs(&self) -> [&T; 4] {
[
&self._1_000sats.1,
&self._1btc.1,
&self._10btc.1,
&self._100btc.1,
]
}
}
impl<T> From<OutputsByFromSize<T>> for OutputsByFromSize<(OutputFilter, T)> {
fn from(value: OutputsByFromSize<T>) -> Self {
Self {
_1_000sats: (OutputFilter::From(1_000), value._1_000sats),
_1btc: (OutputFilter::From(usize::from(Sats::ONE_BTC)), value._1btc),
_10btc: (
OutputFilter::From(usize::from(10 * Sats::ONE_BTC)),
value._10btc,
),
_100btc: (
OutputFilter::From(usize::from(100 * Sats::ONE_BTC)),
value._100btc,
),
}
}
}

View File

@@ -1,8 +1,8 @@
use super::OutputFilter;
#[derive(Default, Clone)]
pub struct OutputsBySize<T> {
pub _0sat: T,
pub struct OutputsBySizeRange<T> {
pub _0sats: T,
pub from_1sat_to_10sats: T,
pub from_10sats_to_100sats: T,
pub from_100sats_to_1_000sats: T,
@@ -19,94 +19,70 @@ pub struct OutputsBySize<T> {
pub from_100_000btc: T,
}
impl<T> From<OutputsBySize<T>> for OutputsBySize<(OutputFilter, T)> {
fn from(value: OutputsBySize<T>) -> Self {
impl<T> From<OutputsBySizeRange<T>> for OutputsBySizeRange<(OutputFilter, T)> {
fn from(value: OutputsBySizeRange<T>) -> Self {
#[allow(clippy::inconsistent_digit_grouping)]
Self {
_0sat: (
// OutputFilter::Zero,
OutputFilter::Size,
value._0sat,
),
from_1sat_to_10sats: (
// OutputFilter::Size(Sats::new(1)..Sats::new(10)),
OutputFilter::Size,
value.from_1sat_to_10sats,
),
from_10sats_to_100sats: (
// OutputFilter::Size(Sats::new(10)..Sats::new(100)),
OutputFilter::Size,
value.from_10sats_to_100sats,
),
_0sats: (OutputFilter::To(1), value._0sats),
from_1sat_to_10sats: (OutputFilter::Range(1..10), value.from_1sat_to_10sats),
from_10sats_to_100sats: (OutputFilter::Range(10..100), value.from_10sats_to_100sats),
from_100sats_to_1_000sats: (
// OutputFilter::Size(Sats::new(100)..Sats::new(1_000)),
OutputFilter::Size,
OutputFilter::Range(100..1_000),
value.from_100sats_to_1_000sats,
),
from_1_000sats_to_10_000sats: (
// OutputFilter::Size(Sats::new(1_000)..Sats::new(10_000)),
OutputFilter::Size,
OutputFilter::Range(1_000..10_000),
value.from_1_000sats_to_10_000sats,
),
from_10_000sats_to_100_000sats: (
// OutputFilter::Size(Sats::new(10_000)..Sats::new(100_000)),
OutputFilter::Size,
OutputFilter::Range(10_000..100_000),
value.from_10_000sats_to_100_000sats,
),
from_100_000sats_to_1_000_000sats: (
// OutputFilter::Size(Sats::new(100_000)..Sats::new(1_000_000)),
OutputFilter::Size,
OutputFilter::Range(100_000..1_000_000),
value.from_100_000sats_to_1_000_000sats,
),
from_1_000_000sats_to_10_000_000sats: (
// OutputFilter::Size(Sats::new(1_000_000)..Sats::new(10_000_000)),
OutputFilter::Size,
OutputFilter::Range(1_000_000..10_000_000),
value.from_1_000_000sats_to_10_000_000sats,
),
from_10_000_000sats_to_1btc: (
// OutputFilter::Size(Sats::new(10_000_000)..Sats::new(1_00_000_000)),
OutputFilter::Size,
OutputFilter::Range(10_000_000..1_00_000_000),
value.from_10_000_000sats_to_1btc,
),
from_1btc_to_10btc: (
// OutputFilter::Size(Sats::new(1_00_000_000)..Sats::new(10_00_000_000)),
OutputFilter::Size,
OutputFilter::Range(1_00_000_000..10_00_000_000),
value.from_1btc_to_10btc,
),
from_10btc_to_100btc: (
// OutputFilter::Size(Sats::new(10_00_000_000)..Sats::new(100_00_000_000)),
OutputFilter::Size,
OutputFilter::Range(10_00_000_000..100_00_000_000),
value.from_10btc_to_100btc,
),
from_100btc_to_1_000btc: (
// OutputFilter::Size(Sats::new(100_00_000_000)..Sats::new(1_000_00_000_000)),
OutputFilter::Size,
OutputFilter::Range(100_00_000_000..1_000_00_000_000),
value.from_100btc_to_1_000btc,
),
from_1_000btc_to_10_000btc: (
// OutputFilter::Size(Sats::new(1_000_00_000_000)..Sats::new(10_000_00_000_000)),
OutputFilter::Size,
OutputFilter::Range(1_000_00_000_000..10_000_00_000_000),
value.from_1_000btc_to_10_000btc,
),
from_10_000btc_to_100_000btc: (
// OutputFilter::Size(Sats::new(10_000_00_000_000)..Sats::new(100_000_00_000_000)),
OutputFilter::Size,
OutputFilter::Range(10_000_00_000_000..100_000_00_000_000),
value.from_10_000btc_to_100_000btc,
),
from_100_000btc: (
// OutputFilter::Size(Sats::new(100_000_00_000_000)..Sats::MAX),
OutputFilter::Size,
OutputFilter::From(100_000_00_000_000),
value.from_100_000btc,
),
}
}
}
impl<T> OutputsBySize<T> {
impl<T> OutputsBySizeRange<T> {
#[allow(clippy::inconsistent_digit_grouping)]
pub fn get_mut(&mut self, group: usize) -> &mut T {
if group == 0 {
&mut self._0sat
&mut self._0sats
} else if group == 1 {
&mut self.from_1sat_to_10sats
} else if group == 10 {
@@ -138,9 +114,29 @@ impl<T> OutputsBySize<T> {
}
}
pub fn as_vec(&self) -> [&T; 15] {
[
&self._0sats,
&self.from_1sat_to_10sats,
&self.from_10sats_to_100sats,
&self.from_100sats_to_1_000sats,
&self.from_1_000sats_to_10_000sats,
&self.from_10_000sats_to_100_000sats,
&self.from_100_000sats_to_1_000_000sats,
&self.from_1_000_000sats_to_10_000_000sats,
&self.from_10_000_000sats_to_1btc,
&self.from_1btc_to_10btc,
&self.from_10btc_to_100btc,
&self.from_100btc_to_1_000btc,
&self.from_1_000btc_to_10_000btc,
&self.from_10_000btc_to_100_000btc,
&self.from_100_000btc,
]
}
pub fn as_mut_vec(&mut self) -> [&mut T; 15] {
[
&mut self._0sat,
&mut self._0sats,
&mut self.from_1sat_to_10sats,
&mut self.from_10sats_to_100sats,
&mut self.from_100sats_to_1_000sats,
@@ -159,10 +155,10 @@ impl<T> OutputsBySize<T> {
}
}
impl<T> OutputsBySize<(OutputFilter, T)> {
impl<T> OutputsBySizeRange<(OutputFilter, T)> {
pub fn vecs(&self) -> [&T; 15] {
[
&self._0sat.1,
&self._0sats.1,
&self.from_1sat_to_10sats.1,
&self.from_10sats_to_100sats.1,
&self.from_100sats_to_1_000sats.1,

View File

@@ -21,8 +21,8 @@ impl<T> OutputsByTerm<(OutputFilter, T)> {
impl<T> From<OutputsByTerm<T>> for OutputsByTerm<(OutputFilter, T)> {
fn from(value: OutputsByTerm<T>) -> Self {
Self {
long: (OutputFilter::From(155), value.long),
short: (OutputFilter::To(155), value.short),
long: (OutputFilter::From(150), value.long),
short: (OutputFilter::To(150), value.short),
}
}
}

View File

@@ -1,7 +1,7 @@
use super::OutputFilter;
#[derive(Default, Clone)]
pub struct OutputsByUpTo<T> {
pub struct OutputsByUpToDate<T> {
pub _1d: T,
pub _1w: T,
pub _1m: T,
@@ -22,7 +22,7 @@ pub struct OutputsByUpTo<T> {
pub _15y: T,
}
impl<T> OutputsByUpTo<T> {
impl<T> OutputsByUpToDate<T> {
pub fn as_mut_vec(&mut self) -> [&mut T; 18] {
[
&mut self._1d,
@@ -47,7 +47,7 @@ impl<T> OutputsByUpTo<T> {
}
}
impl<T> OutputsByUpTo<(OutputFilter, T)> {
impl<T> OutputsByUpToDate<(OutputFilter, T)> {
pub fn vecs(&self) -> [&T; 18] {
[
&self._1d.1,
@@ -72,8 +72,8 @@ impl<T> OutputsByUpTo<(OutputFilter, T)> {
}
}
impl<T> From<OutputsByUpTo<T>> for OutputsByUpTo<(OutputFilter, T)> {
fn from(value: OutputsByUpTo<T>) -> Self {
impl<T> From<OutputsByUpToDate<T>> for OutputsByUpToDate<(OutputFilter, T)> {
fn from(value: OutputsByUpToDate<T>) -> Self {
Self {
_1d: (OutputFilter::To(1), value._1d),
_1w: (OutputFilter::To(7), value._1w),

View File

@@ -0,0 +1,54 @@
use brk_core::Sats;
use super::OutputFilter;
#[derive(Default, Clone)]
pub struct OutputsByUpToSize<T> {
pub _1_000sats: T,
pub _10_000sats: T,
pub _1btc: T,
pub _10btc: T,
pub _100btc: T,
}
impl<T> OutputsByUpToSize<T> {
pub fn as_mut_vec(&mut self) -> [&mut T; 5] {
[
&mut self._1_000sats,
&mut self._10_000sats,
&mut self._1btc,
&mut self._10btc,
&mut self._100btc,
]
}
}
impl<T> OutputsByUpToSize<(OutputFilter, T)> {
pub fn vecs(&self) -> [&T; 5] {
[
&self._1_000sats.1,
&self._10_000sats.1,
&self._1btc.1,
&self._10btc.1,
&self._100btc.1,
]
}
}
impl<T> From<OutputsByUpToSize<T>> for OutputsByUpToSize<(OutputFilter, T)> {
fn from(value: OutputsByUpToSize<T>) -> Self {
Self {
_1_000sats: (OutputFilter::To(1_000), value._1_000sats),
_10_000sats: (OutputFilter::To(10_000), value._10_000sats),
_1btc: (OutputFilter::To(usize::from(Sats::ONE_BTC)), value._1btc),
_10btc: (
OutputFilter::To(usize::from(10 * Sats::ONE_BTC)),
value._10btc,
),
_100btc: (
OutputFilter::To(usize::from(100 * Sats::ONE_BTC)),
value._100btc,
),
}
}
}

View File

@@ -8,7 +8,44 @@ pub enum OutputFilter {
To(usize),
Range(Range<usize>),
From(usize),
Size,
Epoch(HalvingEpoch),
Type(OutputType),
}
impl OutputFilter {
pub fn contains(&self, value: usize) -> bool {
match self {
OutputFilter::All => true,
OutputFilter::To(to) => *to > value,
OutputFilter::From(from) => *from <= value,
OutputFilter::Range(r) => r.contains(&value),
OutputFilter::Epoch(_) => false,
OutputFilter::Type(_) => false,
}
}
pub fn includes(&self, other: &OutputFilter) -> bool {
match self {
OutputFilter::All => true,
OutputFilter::To(to) => match other {
OutputFilter::All => false,
OutputFilter::To(to2) => to >= to2,
OutputFilter::Range(range) => range.end <= *to,
OutputFilter::From(_) => true,
OutputFilter::Epoch(_) => false,
OutputFilter::Type(_) => false,
},
OutputFilter::From(from) => match other {
OutputFilter::All => false,
OutputFilter::To(_) => false,
OutputFilter::Range(range) => range.start >= *from,
OutputFilter::From(from2) => from <= from2,
OutputFilter::Epoch(_) => false,
OutputFilter::Type(_) => false,
},
OutputFilter::Range(_) => false,
OutputFilter::Epoch(_) => false,
OutputFilter::Type(_) => false,
}
}
}

View File

@@ -1,53 +1,83 @@
mod by_date_range;
mod by_epoch;
mod by_from;
mod by_range;
mod by_size;
mod by_from_date;
mod by_from_size;
mod by_size_range;
mod by_spendable_type;
mod by_term;
mod by_type;
mod by_unspendable_type;
mod by_up_to;
mod by_up_to_date;
mod by_up_to_size;
// mod by_value;
mod filter;
pub use by_date_range::*;
pub use by_epoch::*;
pub use by_from::*;
pub use by_range::*;
pub use by_size::*;
pub use by_from_date::*;
pub use by_from_size::*;
pub use by_size_range::*;
pub use by_spendable_type::*;
pub use by_term::*;
pub use by_type::*;
pub use by_unspendable_type::*;
pub use by_up_to::*;
pub use by_up_to_date::*;
pub use by_up_to_size::*;
// pub use by_value::*;
pub use filter::*;
#[derive(Default, Clone)]
pub struct Outputs<T> {
pub all: T,
pub by_term: OutputsByTerm<T>,
pub by_up_to: OutputsByUpTo<T>,
pub by_from: OutputsByFrom<T>,
pub by_range: OutputsByRange<T>,
pub by_date_range: OutputsByDateRange<T>,
pub by_epoch: OutputsByEpoch<T>,
pub by_from_date: OutputsByFromDate<T>,
pub by_from_size: OutputsByFromSize<T>,
pub by_size_range: OutputsBySizeRange<T>,
pub by_term: OutputsByTerm<T>,
pub by_type: OutputsBySpendableType<T>,
pub by_size: OutputsBySize<T>,
// // Needs whole UTXO set, TODO later
// // pub by_value: OutputsByValue<T>,
pub by_up_to_date: OutputsByUpToDate<T>,
pub by_up_to_size: OutputsByUpToSize<T>,
// Needs whole UTXO set, TODO later
// pub by_value: OutputsByValue<T>,
}
impl<T> Outputs<T> {
pub fn as_mut_vec(&mut self) -> Vec<&mut T> {
pub fn as_mut_vecs(&mut self) -> Vec<&mut T> {
[&mut self.all]
.into_iter()
.chain(self.by_term.as_mut_vec())
.chain(self.by_up_to.as_mut_vec())
.chain(self.by_from.as_mut_vec())
.chain(self.by_range.as_mut_vec())
.chain(self.by_up_to_date.as_mut_vec())
.chain(self.by_from_date.as_mut_vec())
.chain(self.by_from_size.as_mut_vec())
.chain(self.by_date_range.as_mut_vec())
.chain(self.by_epoch.as_mut_vec())
.chain(self.by_size.as_mut_vec())
.chain(self.by_size_range.as_mut_vec())
.chain(self.by_up_to_size.as_mut_vec())
.chain(self.by_type.as_mut_vec())
// // .chain(self.by_value.as_mut_vec())
// .chain(self.by_value.as_mut_vec())
.collect::<Vec<_>>()
}
pub fn as_mut_separate_vecs(&mut self) -> Vec<&mut T> {
self.by_date_range
.as_mut_vec()
.into_iter()
.chain(self.by_epoch.as_mut_vec())
.chain(self.by_size_range.as_mut_vec())
.chain(self.by_type.as_mut_vec())
// .chain(self.by_value.as_mut_vec())
.collect::<Vec<_>>()
}
pub fn as_mut_overlaping_vecs(&mut self) -> Vec<&mut T> {
[&mut self.all]
.into_iter()
.chain(self.by_term.as_mut_vec())
.chain(self.by_up_to_date.as_mut_vec())
.chain(self.by_from_date.as_mut_vec())
.chain(self.by_up_to_size.as_mut_vec())
.chain(self.by_from_size.as_mut_vec())
.collect::<Vec<_>>()
}
}
@@ -57,13 +87,15 @@ impl<T> Outputs<(OutputFilter, T)> {
[&self.all.1]
.into_iter()
.chain(self.by_term.vecs())
.chain(self.by_up_to.vecs())
.chain(self.by_from.vecs())
.chain(self.by_range.vecs())
.chain(self.by_up_to_date.vecs())
.chain(self.by_from_date.vecs())
.chain(self.by_date_range.vecs())
.chain(self.by_epoch.vecs())
.chain(self.by_size.vecs())
// // .chain(self.by_value.vecs())
.chain(self.by_size_range.vecs())
.chain(self.by_type.vecs())
.chain(self.by_up_to_size.vecs())
.chain(self.by_from_size.vecs())
// .chain(self.by_value.vecs())
.collect::<Vec<_>>()
}
}
@@ -73,13 +105,15 @@ impl<T> From<Outputs<T>> for Outputs<(OutputFilter, T)> {
Self {
all: (OutputFilter::All, value.all),
by_term: OutputsByTerm::from(value.by_term),
by_up_to: OutputsByUpTo::from(value.by_up_to),
by_from: OutputsByFrom::from(value.by_from),
by_range: OutputsByRange::from(value.by_range),
by_up_to_date: OutputsByUpToDate::from(value.by_up_to_date),
by_from_date: OutputsByFromDate::from(value.by_from_date),
by_date_range: OutputsByDateRange::from(value.by_date_range),
by_epoch: OutputsByEpoch::from(value.by_epoch),
by_size: OutputsBySize::from(value.by_size),
// // Needs whole UTXO set, TODO later
// // by_value: OutputsByValue<T>,
by_size_range: OutputsBySizeRange::from(value.by_size_range),
by_up_to_size: OutputsByUpToSize::from(value.by_up_to_size),
by_from_size: OutputsByFromSize::from(value.by_from_size),
// Needs whole UTXO set, TODO later
// by_value: OutputsByValue<T>,
by_type: OutputsBySpendableType::from(value.by_type),
}
}

View File

@@ -12,7 +12,7 @@ use super::{OutputsByType, SupplyState};
pub struct Transacted {
pub spendable_supply: SupplyState,
pub by_type: OutputsByType<SupplyState>,
pub by_size: BTreeMap<usize, SupplyState>,
pub by_size_group: BTreeMap<usize, SupplyState>,
}
impl Transacted {
@@ -32,35 +32,35 @@ impl Transacted {
// Need to be in sync with by_size !! but plenty fast (I think)
if _value == 0 {
*self.by_size.entry(0).or_default() += &supply;
*self.by_size_group.entry(0).or_default() += &supply;
} else if _value < 10 {
*self.by_size.entry(1).or_default() += &supply;
*self.by_size_group.entry(1).or_default() += &supply;
} else if _value < 100 {
*self.by_size.entry(10).or_default() += &supply;
*self.by_size_group.entry(10).or_default() += &supply;
} else if _value < 1_000 {
*self.by_size.entry(100).or_default() += &supply;
*self.by_size_group.entry(100).or_default() += &supply;
} else if _value < 10_000 {
*self.by_size.entry(1_000).or_default() += &supply;
*self.by_size_group.entry(1_000).or_default() += &supply;
} else if _value < 100_000 {
*self.by_size.entry(10_000).or_default() += &supply;
*self.by_size_group.entry(10_000).or_default() += &supply;
} else if _value < 1_000_000 {
*self.by_size.entry(100_000).or_default() += &supply;
*self.by_size_group.entry(100_000).or_default() += &supply;
} else if _value < 10_000_000 {
*self.by_size.entry(1_000_000).or_default() += &supply;
*self.by_size_group.entry(1_000_000).or_default() += &supply;
} else if _value < 1_00_000_000 {
*self.by_size.entry(10_000_000).or_default() += &supply;
*self.by_size_group.entry(10_000_000).or_default() += &supply;
} else if _value < 10_00_000_000 {
*self.by_size.entry(1_00_000_000).or_default() += &supply;
*self.by_size_group.entry(1_00_000_000).or_default() += &supply;
} else if _value < 100_00_000_000 {
*self.by_size.entry(10_00_000_000).or_default() += &supply;
*self.by_size_group.entry(10_00_000_000).or_default() += &supply;
} else if _value < 1_000_00_000_000 {
*self.by_size.entry(100_00_000_000).or_default() += &supply;
*self.by_size_group.entry(100_00_000_000).or_default() += &supply;
} else if _value < 10_000_00_000_000 {
*self.by_size.entry(1_000_00_000_000).or_default() += &supply;
*self.by_size_group.entry(1_000_00_000_000).or_default() += &supply;
} else if _value < 100_000_00_000_000 {
*self.by_size.entry(10_000_00_000_000).or_default() += &supply;
*self.by_size_group.entry(10_000_00_000_000).or_default() += &supply;
} else {
*self.by_size.entry(100_000_00_000_000).or_default() += &supply;
*self.by_size_group.entry(100_000_00_000_000).or_default() += &supply;
}
}
@@ -86,14 +86,15 @@ impl Add for Transacted {
Self {
spendable_supply: self.spendable_supply + rhs.spendable_supply,
by_type: self.by_type + rhs.by_type,
by_size: Self::merge_by_size(self.by_size, rhs.by_size),
by_size_group: Self::merge_by_size(self.by_size_group, rhs.by_size_group),
}
}
}
impl AddAssign for Transacted {
fn add_assign(&mut self, rhs: Self) {
self.by_size = Self::merge_by_size(mem::take(&mut self.by_size), rhs.by_size);
self.by_size_group =
Self::merge_by_size(mem::take(&mut self.by_size_group), rhs.by_size_group);
self.spendable_supply += &rhs.spendable_supply;
self.by_type += rhs.by_type;
}

View File

@@ -93,14 +93,22 @@ where
}
}
pub fn first_key_value(&self) -> Result<Option<(K, V)>> {
pub fn puts_first_key_value(&self) -> Option<(&K, &V)> {
self.puts.first_key_value()
}
pub fn puts_last_key_value(&self) -> Option<(&K, &V)> {
self.puts.last_key_value()
}
pub fn rtx_first_key_value(&self) -> Result<Option<(K, V)>> {
Ok(self
.rtx
.first_key_value(&self.partition.load())?
.map(|(k, v)| (K::from(ByteView::from(k)), V::from(ByteView::from(v)))))
}
pub fn last_key_value(&self) -> Result<Option<(K, V)>> {
pub fn rtx_last_key_value(&self) -> Result<Option<(K, V)>> {
Ok(self
.rtx
.last_key_value(&self.partition.load())?

View File

@@ -1,17 +1,17 @@
use std::{fs, path::Path};
use brk_core::Version;
use brk_vec::{AnyVec, CollectableVec, Compressed, GenericStoredVec, StoredVec, VecIterator};
use brk_vec::{AnyVec, CollectableVec, Format, GenericStoredVec, StoredVec, VecIterator};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let _ = fs::remove_dir_all("./vec");
let version = Version::ZERO;
let compressed = Compressed::YES;
let format = Format::Compressed;
{
let mut vec: StoredVec<usize, u32> =
StoredVec::forced_import(Path::new("."), "vec", version, compressed)?;
StoredVec::forced_import(Path::new("."), "vec", version, format)?;
(0..21_u32).for_each(|v| {
vec.push(v);
@@ -27,7 +27,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
{
let mut vec: StoredVec<usize, u32> =
StoredVec::forced_import(Path::new("."), "vec", version, compressed)?;
StoredVec::forced_import(Path::new("."), "vec", version, format)?;
let mut iter = vec.into_iter();
dbg!(iter.get(0));
@@ -53,7 +53,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
{
let mut vec: StoredVec<usize, u32> =
StoredVec::forced_import(Path::new("."), "vec", version, compressed)?;
StoredVec::forced_import(Path::new("."), "vec", version, format)?;
let mut iter = vec.into_iter();
dbg!(iter.get(0));

View File

@@ -1,20 +1,33 @@
use std::{fs, io, ops::Deref, path::Path};
use std::{fs, io, path::Path};
use brk_core::{Error, Result};
use clap_derive::ValueEnum;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct Compressed(bool);
impl Compressed {
pub const YES: Self = Self(true);
pub const NO: Self = Self(false);
#[derive(
Default, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, ValueEnum,
)]
pub enum Format {
#[default]
Compressed,
Raw,
}
impl Format {
pub fn write(&self, path: &Path) -> Result<(), io::Error> {
fs::write(path, self.as_bytes())
}
pub fn is_compressed(&self) -> bool {
*self == Self::Compressed
}
fn as_bytes(&self) -> Vec<u8> {
if self.0 { vec![1] } else { vec![0] }
if self.is_compressed() {
vec![1]
} else {
vec![0]
}
}
fn from_bytes(bytes: &[u8]) -> Self {
@@ -22,16 +35,16 @@ impl Compressed {
panic!();
}
if bytes[0] == 1 {
Self(true)
Self::Compressed
} else if bytes[0] == 0 {
Self(false)
Self::Raw
} else {
panic!()
}
}
pub fn validate(&self, path: &Path) -> Result<()> {
if let Ok(prev_compressed) = Compressed::try_from(path) {
if let Ok(prev_compressed) = Format::try_from(path) {
if prev_compressed != *self {
return Err(Error::DifferentCompressionMode);
}
@@ -41,22 +54,9 @@ impl Compressed {
}
}
impl TryFrom<&Path> for Compressed {
impl TryFrom<&Path> for Format {
type Error = Error;
fn try_from(value: &Path) -> Result<Self, Self::Error> {
Ok(Self::from_bytes(&fs::read(value)?))
}
}
impl From<bool> for Compressed {
fn from(value: bool) -> Self {
Self(value)
}
}
impl Deref for Compressed {
type Target = bool;
fn deref(&self) -> &Self::Target {
&self.0
}
}

View File

@@ -1,11 +1,11 @@
mod compressed;
mod compressed_page_meta;
mod compressed_pages_meta;
mod format;
mod length;
mod unsafe_slice;
pub use compressed::*;
pub use compressed_page_meta::*;
pub use compressed_pages_meta::*;
pub use format::*;
pub use length::*;
pub use unsafe_slice::*;

View File

@@ -8,7 +8,7 @@ use brk_core::{Result, StoredPhantom, Value, Version};
use crate::{
AnyCollectableVec, AnyIterableVec, AnyVec, BaseVecIterator, BoxedAnyIterableVec,
BoxedVecIterator, CollectableVec, Compressed, StoredIndex, StoredType,
BoxedVecIterator, CollectableVec, Format, StoredIndex, StoredType,
};
use super::{
@@ -86,13 +86,13 @@ where
path: &Path,
value_name: &str,
version: Version,
compressed: Compressed,
format: Format,
source: BoxedAnyIterableVec<S1I, S1T>,
compute: ComputeFrom1<I, T, S1I, S1T>,
) -> Result<Self> {
Ok(match mode {
Computation::Eager => Self::Eager {
vec: EagerVec::forced_import(path, value_name, version, compressed)?,
vec: EagerVec::forced_import(path, value_name, version, format)?,
deps: Dependencies::From1(source, compute),
},
Computation::Lazy => {
@@ -108,14 +108,14 @@ where
path: &Path,
value_name: &str,
version: Version,
compressed: Compressed,
format: Format,
source1: BoxedAnyIterableVec<S1I, S1T>,
source2: BoxedAnyIterableVec<S2I, S2T>,
compute: ComputeFrom2<I, T, S1I, S1T, S2I, S2T>,
) -> Result<Self> {
Ok(match mode {
Computation::Eager => Self::Eager {
vec: EagerVec::forced_import(path, value_name, version, compressed)?,
vec: EagerVec::forced_import(path, value_name, version, format)?,
deps: Dependencies::From2((source1, source2), compute),
},
Computation::Lazy => {
@@ -133,7 +133,7 @@ where
path: &Path,
value_name: &str,
version: Version,
compressed: Compressed,
format: Format,
source1: BoxedAnyIterableVec<S1I, S1T>,
source2: BoxedAnyIterableVec<S2I, S2T>,
source3: BoxedAnyIterableVec<S3I, S3T>,
@@ -141,7 +141,7 @@ where
) -> Result<Self> {
Ok(match mode {
Computation::Eager => Self::Eager {
vec: EagerVec::forced_import(path, value_name, version, compressed)?,
vec: EagerVec::forced_import(path, value_name, version, format)?,
deps: Dependencies::From3((source1, source2, source3), compute),
},
Computation::Lazy => {

View File

@@ -10,15 +10,15 @@ use std::{
use arc_swap::ArcSwap;
use brk_core::{
Bitcoin, CheckedSub, Close, Date, DateIndex, Dollars, Error, Height, Result, Sats, StoredUsize,
TxIndex, Value, Version,
Bitcoin, CheckedSub, Close, Date, DateIndex, Dollars, Error, Height, Result, Sats, StoredF32,
StoredUsize, TxIndex, Value, Version,
};
use brk_exit::Exit;
use log::info;
use memmap2::Mmap;
use crate::{
AnyCollectableVec, AnyIterableVec, AnyVec, BoxedVecIterator, CollectableVec, Compressed,
AnyCollectableVec, AnyIterableVec, AnyVec, BoxedVecIterator, CollectableVec, Format,
GenericStoredVec, StoredIndex, StoredType, StoredVec, StoredVecIterator, VecIterator,
};
@@ -44,9 +44,9 @@ where
path: &Path,
value_name: &str,
version: Version,
compressed: Compressed,
format: Format,
) -> Result<Self> {
let inner = StoredVec::forced_import(path, value_name, version, compressed)?;
let inner = StoredVec::forced_import(path, value_name, version, format)?;
Ok(Self {
computed_version: None,
@@ -219,10 +219,10 @@ where
)?;
let index = max_from.min(I::from(self.len()));
let mut added_iter = adder.iter();
let mut adder_iter = adder.iter();
added.iter_at(index).try_for_each(|(i, v)| {
let v = v.into_inner() + added_iter.unwrap_get_inner(i);
let v = v.into_inner() + adder_iter.unwrap_get_inner(i);
self.forced_push_at(i, v, exit)
})?;
@@ -245,12 +245,12 @@ where
)?;
let index = max_from.min(I::from(self.len()));
let mut subtracted_iter = subtracter.iter();
let mut subtracter_iter = subtracter.iter();
subtracted.iter_at(index).try_for_each(|(i, v)| {
let v = v
.into_inner()
.checked_sub(subtracted_iter.unwrap_get_inner(i))
.checked_sub(subtracter_iter.unwrap_get_inner(i))
.unwrap();
self.forced_push_at(i, v, exit)
@@ -259,6 +259,71 @@ where
self.safe_flush(exit)
}
pub fn compute_max<T2>(
&mut self,
max_from: I,
source: &impl AnyIterableVec<I, T2>,
exit: &Exit,
) -> Result<()>
where
T: From<T2> + Ord,
T2: StoredType,
{
self.validate_computed_version_or_reset_file(
Version::ZERO + self.inner.version() + source.version(),
)?;
let index = max_from.min(I::from(self.len()));
let mut prev = None;
source.iter_at(index).try_for_each(|(i, v)| {
if prev.is_none() {
let i = i.unwrap_to_usize();
prev.replace(if i > 0 {
self.into_iter().unwrap_get_inner_(i - 1)
} else {
T::from(source.iter().unwrap_get_inner_(0))
});
}
let max = prev.clone().unwrap().max(T::from(v.into_inner()));
prev.replace(max.clone());
self.forced_push_at(i, max, exit)
})?;
self.safe_flush(exit)
}
pub fn compute_multiply<T2, T3, T4>(
&mut self,
max_from: I,
multiplied: &impl AnyIterableVec<I, T2>,
multiplier: &impl AnyIterableVec<I, T3>,
exit: &Exit,
) -> Result<()>
where
T2: StoredType + Mul<T3, Output = T4>,
T3: StoredType,
T4: StoredType,
T: From<T4>,
{
self.validate_computed_version_or_reset_file(
Version::ZERO + self.inner.version() + multiplied.version() + multiplier.version(),
)?;
let index = max_from.min(I::from(self.len()));
let mut multiplier_iter = multiplier.iter();
multiplied.iter_at(index).try_for_each(|(i, v)| {
let v = v.into_inner() * multiplier_iter.unwrap_get_inner(i);
self.forced_push_at(i, v.into(), exit)
})?;
self.safe_flush(exit)
}
pub fn compute_divide<T2, T3, T4>(
&mut self,
max_from: I,
@@ -343,6 +408,36 @@ where
self.safe_flush(exit)
}
pub fn compute_drawdown(
&mut self,
max_from: I,
close: &impl AnyIterableVec<I, Close<Dollars>>,
ath: &impl AnyIterableVec<I, Dollars>,
exit: &Exit,
) -> Result<()>
where
T: From<StoredF32>,
{
self.validate_computed_version_or_reset_file(
Version::ZERO + self.inner.version() + ath.version() + close.version(),
)?;
let index = max_from.min(I::from(self.len()));
let mut close_iter = close.iter();
ath.iter_at(index).try_for_each(|(i, ath)| {
let ath = ath.into_inner();
if ath == Dollars::ZERO {
self.forced_push_at(i, T::from(StoredF32::default()), exit)
} else {
let close = *close_iter.unwrap_get_inner(i);
let drawdown = StoredF32::from((*ath - *close) / *ath * -100.0);
self.forced_push_at(i, T::from(drawdown), exit)
}
})?;
self.safe_flush(exit)
}
pub fn compute_inverse_more_to_less(
&mut self,
max_from: T,
@@ -579,6 +674,115 @@ where
self.safe_flush(exit)
}
pub fn compute_sum_of_others(
&mut self,
max_from: I,
others: &[&impl AnyIterableVec<I, T>],
exit: &Exit,
) -> Result<()>
where
T: From<usize> + Add<T, Output = T>,
{
self.validate_computed_version_or_reset_file(
Version::ZERO + self.inner.version() + others.iter().map(|v| v.version()).sum(),
)?;
if others.is_empty() {
unreachable!("others should've length of 1 at least");
}
let mut others_iter = others[1..].iter().map(|v| v.iter()).collect::<Vec<_>>();
let index = max_from.min(I::from(self.len()));
others
.first()
.unwrap()
.iter_at(index)
.try_for_each(|(i, v)| {
let mut sum = v.into_inner();
others_iter.iter_mut().for_each(|iter| {
sum = sum.clone() + iter.unwrap_get_inner(i);
});
self.forced_push_at(i, sum, exit)
})?;
self.safe_flush(exit)
}
pub fn compute_min_of_others(
&mut self,
max_from: I,
others: &[&impl AnyIterableVec<I, T>],
exit: &Exit,
) -> Result<()>
where
T: From<usize> + Add<T, Output = T> + Ord,
{
self.validate_computed_version_or_reset_file(
Version::ZERO + self.inner.version() + others.iter().map(|v| v.version()).sum(),
)?;
if others.is_empty() {
unreachable!("others should've length of 1 at least");
}
let mut others_iter = others[1..].iter().map(|v| v.iter()).collect::<Vec<_>>();
let index = max_from.min(I::from(self.len()));
others
.first()
.unwrap()
.iter_at(index)
.try_for_each(|(i, v)| {
let min = v.into_inner();
let min = others_iter
.iter_mut()
.map(|iter| iter.unwrap_get_inner(i))
.min()
.map_or(min.clone(), |min2| min.min(min2));
self.forced_push_at(i, min, exit)
})?;
self.safe_flush(exit)
}
pub fn compute_max_of_others(
&mut self,
max_from: I,
others: &[&impl AnyIterableVec<I, T>],
exit: &Exit,
) -> Result<()>
where
T: From<usize> + Add<T, Output = T> + Ord,
{
self.validate_computed_version_or_reset_file(
Version::ZERO + self.inner.version() + others.iter().map(|v| v.version()).sum(),
)?;
if others.is_empty() {
unreachable!("others should've length of 1 at least");
}
let mut others_iter = others[1..].iter().map(|v| v.iter()).collect::<Vec<_>>();
let index = max_from.min(I::from(self.len()));
others
.first()
.unwrap()
.iter_at(index)
.try_for_each(|(i, v)| {
let max = v.into_inner();
let max = others_iter
.iter_mut()
.map(|iter| iter.unwrap_get_inner(i))
.max()
.map_or(max.clone(), |max2| max.max(max2));
self.forced_push_at(i, max, exit)
})?;
self.safe_flush(exit)
}
pub fn compute_sma<T2>(
&mut self,
max_from: I,

View File

@@ -9,7 +9,7 @@ use arc_swap::ArcSwap;
use brk_core::{Error, Height, Result, Value, Version};
use crate::{
AnyCollectableVec, AnyIterableVec, AnyVec, BoxedVecIterator, CollectableVec, Compressed,
AnyCollectableVec, AnyIterableVec, AnyVec, BoxedVecIterator, CollectableVec, Format,
GenericStoredVec, Mmap, StoredIndex, StoredType, StoredVec,
};
@@ -30,9 +30,9 @@ where
path: &Path,
value_name: &str,
version: Version,
compressed: Compressed,
format: Format,
) -> Result<Self> {
let inner = StoredVec::forced_import(path, value_name, version, compressed)?;
let inner = StoredVec::forced_import(path, value_name, version, format)?;
Ok(Self {
height: Height::try_from(Self::path_height_(inner.path()).as_path()).ok(),

View File

@@ -6,7 +6,7 @@ use memmap2::Mmap;
use crate::{
AnyCollectableVec, AnyIterableVec, AnyVec, BaseVecIterator, BoxedVecIterator, CollectableVec,
Compressed, GenericStoredVec, StoredIndex, StoredType,
Format, GenericStoredVec, StoredIndex, StoredType,
};
use super::{CompressedVec, CompressedVecIterator, RawVec, RawVecIterator};
@@ -26,7 +26,7 @@ where
path: &Path,
value_name: &str,
version: Version,
compressed: Compressed,
format: Format,
) -> Result<Self> {
let path = I::path(path, value_name);
@@ -35,7 +35,7 @@ where
panic!("Version must be at least 1, can't verify endianess otherwise");
}
if *compressed {
if format.is_compressed() {
Ok(Self::Compressed(CompressedVec::forced_import(
&path, version,
)?))

View File

@@ -734,6 +734,7 @@ function createUtils() {
id === "marketcap" ||
id.includes("in-usd") ||
id.startsWith("price") ||
id.endsWith("price-paid") ||
id.endsWith("price") ||
id.endsWith("value-created") ||
id.endsWith("value-destroyed") ||

View File

@@ -565,11 +565,71 @@ function createPartialOptions(colors) {
},
]);
const size = /** @type {const } */ ([
const fromSize = /** @type {const} */ ([
{
key: "0sat",
name: "0sat",
title: "0 sat",
key: "from-1-000sats",
name: "1_000sats",
title: "From 1,000 sats",
color: colors.cyan,
},
{
key: "from-1btc",
name: "1btc",
title: "From 1 BTC",
color: colors.violet,
},
{
key: "from-10btc",
name: "10btc",
title: "From 10 BTC",
color: colors.purple,
},
{
key: "from-100btc",
name: "100btc",
title: "From 100 BTC",
color: colors.pink,
},
]);
const upToSize = /** @type {const} */ ([
{
key: "up-to-1-000sats",
name: "1_000sats",
title: "Up to 1,000 sats",
color: colors.yellow,
},
{
key: "up-to-10-000sats",
name: "10_000sats",
title: "Up to 10,000 sats",
color: colors.green,
},
{
key: "up-to-1btc",
name: "1btc",
title: "Up to 1 btc",
color: colors.cyan,
},
{
key: "up-to-10btc",
name: "10btc",
title: "Up to 10 btc",
color: colors.blue,
},
{
key: "up-to-100btc",
name: "100btc",
title: "Up to 100 btc",
color: colors.violet,
},
]);
const sizeRanges = /** @type {const} */ ([
{
key: "0sats",
name: "0sats",
title: "0 sats",
color: colors.red,
},
{
@@ -1398,6 +1458,81 @@ function createPartialOptions(colors) {
},
],
},
...("list" in args
? [
{
name: "Price paid",
tree: [
{
name: "Average",
title: `${args.title} Average Price Paid`,
bottom: list.flatMap(({ color, name, key: _key }) => {
const key = fixKey(_key);
return /** @type {const} */ ([
createBaseSeries({
key: `${key}realized-price`,
name,
color: color,
}),
]);
}),
},
{
name: "Min",
title: `${args.title} Min Price Paid`,
bottom: list.flatMap(({ color, name, key: _key }) => {
const key = fixKey(_key);
return /** @type {const} */ ([
createBaseSeries({
key: `${key}min-price-paid`,
name,
color: color,
}),
]);
}),
},
{
name: "Max",
title: `${args.title} Max Price Paid`,
bottom: list.flatMap(({ color, name, key: _key }) => {
const key = fixKey(_key);
return /** @type {const} */ ([
createBaseSeries({
key: `${key}max-price-paid`,
name,
color: color,
}),
]);
}),
},
],
},
]
: [
{
name: "Price paid",
title: `${args.title} Prices Paid`,
top: [
createBaseSeries({
key: `${fixKey(args.key)}realized-price`,
name: "Average",
color: args.color,
}),
createBaseSeries({
key: `${fixKey(args.key)}min-price-paid`,
name: "Min",
color: colors.green,
// defaultActive: false,
}),
createBaseSeries({
key: `${fixKey(args.key)}max-price-paid`,
name: "Max",
color: colors.red,
// defaultActive: false,
}),
],
},
]),
],
});
}
@@ -1446,12 +1581,12 @@ function createPartialOptions(colors) {
name: "Days since",
}),
createBaseSeries({
key: "max-days-between-ath",
key: "max-days-between-aths",
name: "Max",
color: colors.red,
}),
createBaseSeries({
key: "max-years-between-ath",
key: "max-years-between-aths",
name: "Max",
color: colors.red,
}),
@@ -2224,7 +2359,7 @@ function createPartialOptions(colors) {
],
},
{
name: "Up to",
name: "Up to date",
tree: [
createUTXOGroupFolder({
name: "Compare",
@@ -2235,7 +2370,7 @@ function createPartialOptions(colors) {
],
},
{
name: "From",
name: "From Date",
tree: [
createUTXOGroupFolder({
name: "Compare",
@@ -2246,7 +2381,7 @@ function createPartialOptions(colors) {
],
},
{
name: "Range",
name: "Date Range",
tree: [
createUTXOGroupFolder({
name: "Compare",
@@ -2268,14 +2403,36 @@ function createPartialOptions(colors) {
],
},
{
name: "size",
name: "Up to size",
tree: [
createUTXOGroupFolder({
name: "Compare",
title: "Compare By Size",
list: size,
title: "Compare By Up To Size",
list: upToSize,
}),
...size.map(createUTXOGroupFolder),
...upToSize.map(createUTXOGroupFolder),
],
},
{
name: "From size",
tree: [
createUTXOGroupFolder({
name: "Compare",
title: "Compare By From Size",
list: fromSize,
}),
...fromSize.map(createUTXOGroupFolder),
],
},
{
name: "Size range",
tree: [
createUTXOGroupFolder({
name: "Compare",
title: "Compare By Size Range",
list: sizeRanges,
}),
...sizeRanges.map(createUTXOGroupFolder),
],
},
{

File diff suppressed because it is too large Load Diff