mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-06-11 15:33:33 -07:00
global: vec iter part 2
This commit is contained in:
@@ -36,7 +36,6 @@ pub fn main() -> color_eyre::Result<()> {
|
||||
// for_each(|t| {
|
||||
// dbg!(t);
|
||||
// });
|
||||
// .skip(0)
|
||||
// .try_for_each(|(height, timestamp)| -> Result<()> {
|
||||
// let interval = height.decremented().map_or(Timestamp::ZERO, |prev_h| {
|
||||
// dbg!((height, prev_h));
|
||||
|
||||
@@ -8,7 +8,6 @@ use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
use brk_parser::bitcoin;
|
||||
use brk_vec::{Compressed, Version};
|
||||
use color_eyre::eyre::ContextCompat;
|
||||
|
||||
use super::{
|
||||
EagerVec, Indexes,
|
||||
@@ -149,20 +148,13 @@ impl Vecs {
|
||||
|
||||
let indexer_vecs = indexer.vecs();
|
||||
|
||||
let mut height_to_timestamp_iter = indexer_vecs.height_to_timestamp.iter();
|
||||
self.height_to_interval.compute_transform(
|
||||
starting_indexes.height,
|
||||
indexer_vecs.height_to_timestamp.vec(),
|
||||
|(height, timestamp, _, height_to_timestamp_iter)| {
|
||||
|(height, timestamp)| {
|
||||
let interval = height.decremented().map_or(Timestamp::ZERO, |prev_h| {
|
||||
let prev_timestamp = height_to_timestamp_iter
|
||||
.get(prev_h)
|
||||
.context("To work")
|
||||
.inspect_err(|_| {
|
||||
dbg!(prev_h);
|
||||
})
|
||||
.unwrap()
|
||||
.1
|
||||
.into_inner();
|
||||
let prev_timestamp = height_to_timestamp_iter.unwrap_get_inner(prev_h);
|
||||
timestamp
|
||||
.checked_sub(prev_timestamp)
|
||||
.unwrap_or(Timestamp::ZERO)
|
||||
|
||||
@@ -144,22 +144,13 @@ where
|
||||
|
||||
let total_vec = self.total.as_mut().unwrap();
|
||||
|
||||
source
|
||||
.into_iter()
|
||||
.skip(index.unwrap_to_usize())
|
||||
.try_for_each(|(i, v)| -> Result<()> {
|
||||
let v = v.into_inner();
|
||||
let prev = i
|
||||
.unwrap_to_usize()
|
||||
.checked_sub(1)
|
||||
.map_or(T::from(0_usize), |prev_i| {
|
||||
total_vec
|
||||
.unwrap_cached_get(I::from(prev_i))
|
||||
.unwrap_or(T::from(0_usize))
|
||||
});
|
||||
let value = v.clone() + prev;
|
||||
total_vec.forced_push_at(i, value, exit)
|
||||
})?;
|
||||
let mut total = index.decremented().map_or(T::from(0_usize), |index| {
|
||||
total_vec.iter().unwrap_get_inner(index)
|
||||
});
|
||||
source.iter_at(index).try_for_each(|(i, v)| -> Result<()> {
|
||||
total = total.clone() + v.into_inner();
|
||||
total_vec.forced_push_at(i, total.clone(), exit)
|
||||
})?;
|
||||
|
||||
self.safe_flush(exit)?;
|
||||
|
||||
@@ -182,9 +173,16 @@ where
|
||||
let mut last_indexes_iter = last_indexes.iter();
|
||||
let mut source_iter = source.iter();
|
||||
|
||||
let total_vec = self.total.as_mut();
|
||||
|
||||
let mut total = total_vec.map(|total_vec| {
|
||||
index.decremented().map_or(T::from(0_usize), |index| {
|
||||
total_vec.iter().unwrap_get_inner(index)
|
||||
})
|
||||
});
|
||||
|
||||
first_indexes
|
||||
.into_iter()
|
||||
.skip(index.unwrap_to_usize())
|
||||
.iter_at(index)
|
||||
.try_for_each(|(i, first_index)| -> Result<()> {
|
||||
let first_index = first_index.into_inner();
|
||||
|
||||
@@ -290,13 +288,9 @@ where
|
||||
}
|
||||
|
||||
if let Some(total_vec) = self.total.as_mut() {
|
||||
let prev = i
|
||||
.unwrap_to_usize()
|
||||
.checked_sub(1)
|
||||
.map_or(T::from(0_usize), |prev_i| {
|
||||
total_vec.double_unwrap_cached_get(I::from(prev_i))
|
||||
});
|
||||
total_vec.forced_push_at(i, prev + sum, exit)?;
|
||||
let t = total.as_ref().unwrap().clone() + sum;
|
||||
total.replace(t.clone());
|
||||
total_vec.forced_push_at(i, t, exit)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -342,9 +336,14 @@ where
|
||||
let mut source_average_iter = source.average.as_ref().map(|f| f.iter());
|
||||
let mut source_sum_iter = source.sum.as_ref().map(|f| f.iter());
|
||||
|
||||
let mut total = self.total.as_mut().map(|total_vec| {
|
||||
index.decremented().map_or(T::from(0_usize), |index| {
|
||||
total_vec.iter().unwrap_get_inner(index)
|
||||
})
|
||||
});
|
||||
|
||||
first_indexes
|
||||
.into_iter()
|
||||
.skip(index.unwrap_to_usize())
|
||||
.iter_at(index)
|
||||
.try_for_each(|(i, first_index, ..)| -> Result<()> {
|
||||
let first_index = first_index.into_inner();
|
||||
|
||||
@@ -374,10 +373,9 @@ where
|
||||
if needs_values {
|
||||
if needs_sorted {
|
||||
if let Some(max) = self.max.as_mut() {
|
||||
let source_max_iter = source_max_iter.as_mut().unwrap();
|
||||
source_max_iter.set(first_index);
|
||||
let mut values = source_max_iter
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.skip(first_index.unwrap_to_usize())
|
||||
.take(
|
||||
last_index
|
||||
.checked_sub(first_index)
|
||||
@@ -391,10 +389,9 @@ where
|
||||
}
|
||||
|
||||
if let Some(min) = self.min.as_mut() {
|
||||
let source_min_iter = source_min_iter.as_mut().unwrap();
|
||||
source_min_iter.set(first_index);
|
||||
let mut values = source_min_iter
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.skip(first_index.unwrap_to_usize())
|
||||
.take(
|
||||
last_index
|
||||
.checked_sub(first_index)
|
||||
@@ -410,10 +407,9 @@ where
|
||||
|
||||
if needs_average_sum_or_total {
|
||||
if let Some(average) = self.average.as_mut() {
|
||||
let source_average_iter = source_average_iter.as_mut().unwrap();
|
||||
source_average_iter.set(first_index);
|
||||
let values = source_average_iter
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.skip(first_index.unwrap_to_usize())
|
||||
.take(
|
||||
last_index
|
||||
.checked_sub(first_index)
|
||||
@@ -432,10 +428,9 @@ where
|
||||
}
|
||||
|
||||
if needs_sum_or_total {
|
||||
let source_sum_iter = source_sum_iter.as_mut().unwrap();
|
||||
source_sum_iter.set(first_index);
|
||||
let values = source_sum_iter
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.skip(first_index.unwrap_to_usize())
|
||||
.take(
|
||||
last_index
|
||||
.checked_sub(first_index)
|
||||
@@ -452,13 +447,9 @@ where
|
||||
}
|
||||
|
||||
if let Some(total_vec) = self.total.as_mut() {
|
||||
let prev = i
|
||||
.unwrap_to_usize()
|
||||
.checked_sub(1)
|
||||
.map_or(T::from(0_usize), |prev_i| {
|
||||
total_vec.double_unwrap_cached_get(I::from(prev_i))
|
||||
});
|
||||
total_vec.forced_push_at(i, prev + sum, exit)?;
|
||||
let t = total.as_ref().unwrap().clone() + sum;
|
||||
total.replace(t.clone());
|
||||
total_vec.forced_push_at(i, t, exit)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -706,13 +706,14 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut height_to_timestamp_iter = indexer_vecs.height_to_timestamp.iter();
|
||||
self.height_to_timestamp_fixed.compute_transform(
|
||||
starting_indexes.height,
|
||||
indexer_vecs.height_to_timestamp.vec(),
|
||||
|(h, timestamp, s, ..)| {
|
||||
|(h, timestamp, ..)| {
|
||||
let timestamp = h
|
||||
.decremented()
|
||||
.and_then(|h| s.unwrap_cached_get(h))
|
||||
.map(|h| height_to_timestamp_iter.unwrap_get_inner(h))
|
||||
.map_or(timestamp, |prev_d| prev_d.max(timestamp));
|
||||
(h, timestamp)
|
||||
},
|
||||
@@ -734,7 +735,8 @@ impl Vecs {
|
||||
|
||||
let starting_dateindex = self
|
||||
.height_to_dateindex
|
||||
.unwrap_cached_get(decremented_starting_height)
|
||||
.iter()
|
||||
.get_inner(decremented_starting_height)
|
||||
.unwrap_or_default();
|
||||
|
||||
self.height_to_dateindex.compute_transform(
|
||||
@@ -746,7 +748,8 @@ impl Vecs {
|
||||
|
||||
let starting_dateindex = if let Some(dateindex) = self
|
||||
.height_to_dateindex
|
||||
.unwrap_cached_get(decremented_starting_height)
|
||||
.iter()
|
||||
.get_inner(decremented_starting_height)
|
||||
{
|
||||
starting_dateindex.min(dateindex)
|
||||
} else {
|
||||
@@ -790,7 +793,8 @@ impl Vecs {
|
||||
|
||||
let starting_weekindex = self
|
||||
.dateindex_to_weekindex
|
||||
.unwrap_cached_get(starting_dateindex)
|
||||
.iter()
|
||||
.get_inner(starting_dateindex)
|
||||
.unwrap_or_default();
|
||||
|
||||
self.dateindex_to_weekindex.compute_range(
|
||||
@@ -828,7 +832,8 @@ impl Vecs {
|
||||
|
||||
let starting_difficultyepoch = self
|
||||
.height_to_difficultyepoch
|
||||
.unwrap_cached_get(decremented_starting_height)
|
||||
.iter()
|
||||
.get_inner(decremented_starting_height)
|
||||
.unwrap_or_default();
|
||||
|
||||
self.height_to_difficultyepoch.compute_range(
|
||||
@@ -866,7 +871,8 @@ impl Vecs {
|
||||
|
||||
let starting_monthindex = self
|
||||
.dateindex_to_monthindex
|
||||
.unwrap_cached_get(starting_dateindex)
|
||||
.iter()
|
||||
.get_inner(starting_dateindex)
|
||||
.unwrap_or_default();
|
||||
|
||||
self.dateindex_to_monthindex.compute_range(
|
||||
@@ -906,7 +912,8 @@ impl Vecs {
|
||||
|
||||
let starting_quarterindex = self
|
||||
.monthindex_to_quarterindex
|
||||
.unwrap_cached_get(starting_monthindex)
|
||||
.iter()
|
||||
.get_inner(starting_monthindex)
|
||||
.unwrap_or_default();
|
||||
|
||||
self.monthindex_to_quarterindex.compute_range(
|
||||
@@ -946,7 +953,8 @@ impl Vecs {
|
||||
|
||||
let starting_yearindex = self
|
||||
.monthindex_to_yearindex
|
||||
.unwrap_cached_get(starting_monthindex)
|
||||
.iter()
|
||||
.get_inner(starting_monthindex)
|
||||
.unwrap_or_default();
|
||||
|
||||
self.monthindex_to_yearindex.compute_range(
|
||||
@@ -986,7 +994,8 @@ impl Vecs {
|
||||
|
||||
let starting_halvingepoch = self
|
||||
.height_to_halvingepoch
|
||||
.unwrap_cached_get(decremented_starting_height)
|
||||
.iter()
|
||||
.get_inner(decremented_starting_height)
|
||||
.unwrap_or_default();
|
||||
|
||||
self.height_to_halvingepoch.compute_range(
|
||||
@@ -1024,7 +1033,8 @@ impl Vecs {
|
||||
|
||||
let starting_decadeindex = self
|
||||
.yearindex_to_decadeindex
|
||||
.unwrap_cached_get(starting_yearindex)
|
||||
.iter()
|
||||
.get_inner(starting_yearindex)
|
||||
.unwrap_or_default();
|
||||
|
||||
self.yearindex_to_decadeindex.compute_range(
|
||||
|
||||
@@ -333,10 +333,11 @@ impl Vecs {
|
||||
) -> color_eyre::Result<()> {
|
||||
let indexer_vecs = indexer.vecs();
|
||||
|
||||
let mut height_to_timestamp_iter = indexer_vecs.height_to_timestamp.iter();
|
||||
self.height_to_ohlc_in_cents.compute_transform(
|
||||
starting_indexes.height,
|
||||
indexer_vecs.height_to_timestamp.vec(),
|
||||
|(h, t, _, height_to_timestamp_iter)| {
|
||||
|(h, t)| {
|
||||
let ohlc = fetcher
|
||||
.get_height(
|
||||
h,
|
||||
@@ -551,6 +552,9 @@ impl Vecs {
|
||||
},
|
||||
)?;
|
||||
|
||||
let mut weekindex_first_iter = self.timeindexes_to_open.weekindex.unwrap_first().iter();
|
||||
let mut weekindex_max_iter = self.timeindexes_to_high.weekindex.unwrap_max().iter();
|
||||
let mut weekindex_min_iter = self.timeindexes_to_low.weekindex.unwrap_min().iter();
|
||||
self.weekindex_to_ohlc.compute_transform(
|
||||
starting_indexes.weekindex,
|
||||
self.timeindexes_to_close.weekindex.unwrap_last().vec(),
|
||||
@@ -558,21 +562,9 @@ impl Vecs {
|
||||
(
|
||||
i,
|
||||
OHLCDollars {
|
||||
open: self
|
||||
.timeindexes_to_open
|
||||
.weekindex
|
||||
.unwrap_first()
|
||||
.double_unwrap_cached_get(i),
|
||||
high: self
|
||||
.timeindexes_to_high
|
||||
.weekindex
|
||||
.unwrap_max()
|
||||
.double_unwrap_cached_get(i),
|
||||
low: self
|
||||
.timeindexes_to_low
|
||||
.weekindex
|
||||
.unwrap_min()
|
||||
.double_unwrap_cached_get(i),
|
||||
open: weekindex_first_iter.unwrap_get_inner(i),
|
||||
high: weekindex_max_iter.unwrap_get_inner(i),
|
||||
low: weekindex_min_iter.unwrap_get_inner(i),
|
||||
close,
|
||||
},
|
||||
)
|
||||
@@ -580,6 +572,18 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut difficultyepoch_first_iter = self
|
||||
.chainindexes_to_open
|
||||
.difficultyepoch
|
||||
.unwrap_first()
|
||||
.iter();
|
||||
let mut difficultyepoch_max_iter = self
|
||||
.chainindexes_to_high
|
||||
.difficultyepoch
|
||||
.unwrap_max()
|
||||
.iter();
|
||||
let mut difficultyepoch_min_iter =
|
||||
self.chainindexes_to_low.difficultyepoch.unwrap_min().iter();
|
||||
self.difficultyepoch_to_ohlc.compute_transform(
|
||||
starting_indexes.difficultyepoch,
|
||||
self.chainindexes_to_close
|
||||
@@ -590,21 +594,9 @@ impl Vecs {
|
||||
(
|
||||
i,
|
||||
OHLCDollars {
|
||||
open: self
|
||||
.chainindexes_to_open
|
||||
.difficultyepoch
|
||||
.unwrap_first()
|
||||
.double_unwrap_cached_get(i),
|
||||
high: self
|
||||
.chainindexes_to_high
|
||||
.difficultyepoch
|
||||
.unwrap_max()
|
||||
.double_unwrap_cached_get(i),
|
||||
low: self
|
||||
.chainindexes_to_low
|
||||
.difficultyepoch
|
||||
.unwrap_min()
|
||||
.double_unwrap_cached_get(i),
|
||||
open: difficultyepoch_first_iter.unwrap_get_inner(i),
|
||||
high: difficultyepoch_max_iter.unwrap_get_inner(i),
|
||||
low: difficultyepoch_min_iter.unwrap_get_inner(i),
|
||||
close,
|
||||
},
|
||||
)
|
||||
@@ -612,6 +604,9 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut monthindex_first_iter = self.timeindexes_to_open.monthindex.unwrap_first().iter();
|
||||
let mut monthindex_max_iter = self.timeindexes_to_high.monthindex.unwrap_max().iter();
|
||||
let mut monthindex_min_iter = self.timeindexes_to_low.monthindex.unwrap_min().iter();
|
||||
self.monthindex_to_ohlc.compute_transform(
|
||||
starting_indexes.monthindex,
|
||||
self.timeindexes_to_close.monthindex.unwrap_last().vec(),
|
||||
@@ -619,21 +614,9 @@ impl Vecs {
|
||||
(
|
||||
i,
|
||||
OHLCDollars {
|
||||
open: self
|
||||
.timeindexes_to_open
|
||||
.monthindex
|
||||
.unwrap_first()
|
||||
.double_unwrap_cached_get(i),
|
||||
high: self
|
||||
.timeindexes_to_high
|
||||
.monthindex
|
||||
.unwrap_max()
|
||||
.double_unwrap_cached_get(i),
|
||||
low: self
|
||||
.timeindexes_to_low
|
||||
.monthindex
|
||||
.unwrap_min()
|
||||
.double_unwrap_cached_get(i),
|
||||
open: monthindex_first_iter.unwrap_get_inner(i),
|
||||
high: monthindex_max_iter.unwrap_get_inner(i),
|
||||
low: monthindex_min_iter.unwrap_get_inner(i),
|
||||
close,
|
||||
},
|
||||
)
|
||||
@@ -641,6 +624,10 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut quarterindex_first_iter =
|
||||
self.timeindexes_to_open.quarterindex.unwrap_first().iter();
|
||||
let mut quarterindex_max_iter = self.timeindexes_to_high.quarterindex.unwrap_max().iter();
|
||||
let mut quarterindex_min_iter = self.timeindexes_to_low.quarterindex.unwrap_min().iter();
|
||||
self.quarterindex_to_ohlc.compute_transform(
|
||||
starting_indexes.quarterindex,
|
||||
self.timeindexes_to_close.quarterindex.unwrap_last().vec(),
|
||||
@@ -648,21 +635,9 @@ impl Vecs {
|
||||
(
|
||||
i,
|
||||
OHLCDollars {
|
||||
open: self
|
||||
.timeindexes_to_open
|
||||
.quarterindex
|
||||
.unwrap_first()
|
||||
.double_unwrap_cached_get(i),
|
||||
high: self
|
||||
.timeindexes_to_high
|
||||
.quarterindex
|
||||
.unwrap_max()
|
||||
.double_unwrap_cached_get(i),
|
||||
low: self
|
||||
.timeindexes_to_low
|
||||
.quarterindex
|
||||
.unwrap_min()
|
||||
.double_unwrap_cached_get(i),
|
||||
open: quarterindex_first_iter.unwrap_get_inner(i),
|
||||
high: quarterindex_max_iter.unwrap_get_inner(i),
|
||||
low: quarterindex_min_iter.unwrap_get_inner(i),
|
||||
close,
|
||||
},
|
||||
)
|
||||
@@ -670,6 +645,9 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut yearindex_first_iter = self.timeindexes_to_open.yearindex.unwrap_first().iter();
|
||||
let mut yearindex_max_iter = self.timeindexes_to_high.yearindex.unwrap_max().iter();
|
||||
let mut yearindex_min_iter = self.timeindexes_to_low.yearindex.unwrap_min().iter();
|
||||
self.yearindex_to_ohlc.compute_transform(
|
||||
starting_indexes.yearindex,
|
||||
self.timeindexes_to_close.yearindex.unwrap_last().vec(),
|
||||
@@ -677,21 +655,9 @@ impl Vecs {
|
||||
(
|
||||
i,
|
||||
OHLCDollars {
|
||||
open: self
|
||||
.timeindexes_to_open
|
||||
.yearindex
|
||||
.unwrap_first()
|
||||
.double_unwrap_cached_get(i),
|
||||
high: self
|
||||
.timeindexes_to_high
|
||||
.yearindex
|
||||
.unwrap_max()
|
||||
.double_unwrap_cached_get(i),
|
||||
low: self
|
||||
.timeindexes_to_low
|
||||
.yearindex
|
||||
.unwrap_min()
|
||||
.double_unwrap_cached_get(i),
|
||||
open: yearindex_first_iter.unwrap_get_inner(i),
|
||||
high: yearindex_max_iter.unwrap_get_inner(i),
|
||||
low: yearindex_min_iter.unwrap_get_inner(i),
|
||||
close,
|
||||
},
|
||||
)
|
||||
@@ -702,6 +668,9 @@ impl Vecs {
|
||||
// self.halvingepoch_to_ohlc
|
||||
// .compute_transform(starting_indexes.halvingepoch, other, t, exit)?;
|
||||
|
||||
let mut decadeindex_first_iter = self.timeindexes_to_open.decadeindex.unwrap_first().iter();
|
||||
let mut decadeindex_max_iter = self.timeindexes_to_high.decadeindex.unwrap_max().iter();
|
||||
let mut decadeindex_min_iter = self.timeindexes_to_low.decadeindex.unwrap_min().iter();
|
||||
self.decadeindex_to_ohlc.compute_transform(
|
||||
starting_indexes.decadeindex,
|
||||
self.timeindexes_to_close.decadeindex.unwrap_last().vec(),
|
||||
@@ -709,21 +678,9 @@ impl Vecs {
|
||||
(
|
||||
i,
|
||||
OHLCDollars {
|
||||
open: self
|
||||
.timeindexes_to_open
|
||||
.decadeindex
|
||||
.unwrap_first()
|
||||
.double_unwrap_cached_get(i),
|
||||
high: self
|
||||
.timeindexes_to_high
|
||||
.decadeindex
|
||||
.unwrap_max()
|
||||
.double_unwrap_cached_get(i),
|
||||
low: self
|
||||
.timeindexes_to_low
|
||||
.decadeindex
|
||||
.unwrap_min()
|
||||
.double_unwrap_cached_get(i),
|
||||
open: decadeindex_first_iter.unwrap_get_inner(i),
|
||||
high: decadeindex_max_iter.unwrap_get_inner(i),
|
||||
low: decadeindex_min_iter.unwrap_get_inner(i),
|
||||
close,
|
||||
},
|
||||
)
|
||||
@@ -851,6 +808,9 @@ impl Vecs {
|
||||
},
|
||||
)?;
|
||||
|
||||
let mut height_first_iter = self.chainindexes_to_open_in_sats.height.iter();
|
||||
let mut height_max_iter = self.chainindexes_to_high_in_sats.height.iter();
|
||||
let mut height_min_iter = self.chainindexes_to_low_in_sats.height.iter();
|
||||
self.height_to_ohlc_in_sats.compute_transform(
|
||||
starting_indexes.height,
|
||||
self.chainindexes_to_close_in_sats.height.vec(),
|
||||
@@ -858,18 +818,9 @@ impl Vecs {
|
||||
(
|
||||
i,
|
||||
OHLCSats {
|
||||
open: self
|
||||
.chainindexes_to_open_in_sats
|
||||
.height
|
||||
.double_unwrap_cached_get(i),
|
||||
high: self
|
||||
.chainindexes_to_high_in_sats
|
||||
.height
|
||||
.double_unwrap_cached_get(i),
|
||||
low: self
|
||||
.chainindexes_to_low_in_sats
|
||||
.height
|
||||
.double_unwrap_cached_get(i),
|
||||
open: height_first_iter.unwrap_get_inner(i),
|
||||
high: height_max_iter.unwrap_get_inner(i),
|
||||
low: height_min_iter.unwrap_get_inner(i),
|
||||
close,
|
||||
},
|
||||
)
|
||||
@@ -877,6 +828,9 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut dateindex_first_iter = self.timeindexes_to_open_in_sats.dateindex.iter();
|
||||
let mut dateindex_max_iter = self.timeindexes_to_high_in_sats.dateindex.iter();
|
||||
let mut dateindex_min_iter = self.timeindexes_to_low_in_sats.dateindex.iter();
|
||||
self.dateindex_to_ohlc_in_sats.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
self.timeindexes_to_close_in_sats.dateindex.vec(),
|
||||
@@ -884,18 +838,9 @@ impl Vecs {
|
||||
(
|
||||
i,
|
||||
OHLCSats {
|
||||
open: self
|
||||
.timeindexes_to_open_in_sats
|
||||
.dateindex
|
||||
.double_unwrap_cached_get(i),
|
||||
high: self
|
||||
.timeindexes_to_high_in_sats
|
||||
.dateindex
|
||||
.double_unwrap_cached_get(i),
|
||||
low: self
|
||||
.timeindexes_to_low_in_sats
|
||||
.dateindex
|
||||
.double_unwrap_cached_get(i),
|
||||
open: dateindex_first_iter.unwrap_get_inner(i),
|
||||
high: dateindex_max_iter.unwrap_get_inner(i),
|
||||
low: dateindex_min_iter.unwrap_get_inner(i),
|
||||
close,
|
||||
},
|
||||
)
|
||||
@@ -903,6 +848,21 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut weekindex_first_iter = self
|
||||
.timeindexes_to_open_in_sats
|
||||
.weekindex
|
||||
.unwrap_first()
|
||||
.iter();
|
||||
let mut weekindex_max_iter = self
|
||||
.timeindexes_to_high_in_sats
|
||||
.weekindex
|
||||
.unwrap_max()
|
||||
.iter();
|
||||
let mut weekindex_min_iter = self
|
||||
.timeindexes_to_low_in_sats
|
||||
.weekindex
|
||||
.unwrap_min()
|
||||
.iter();
|
||||
self.weekindex_to_ohlc_in_sats.compute_transform(
|
||||
starting_indexes.weekindex,
|
||||
self.timeindexes_to_close_in_sats
|
||||
@@ -913,21 +873,9 @@ impl Vecs {
|
||||
(
|
||||
i,
|
||||
OHLCSats {
|
||||
open: self
|
||||
.timeindexes_to_open_in_sats
|
||||
.weekindex
|
||||
.unwrap_first()
|
||||
.double_unwrap_cached_get(i),
|
||||
high: self
|
||||
.timeindexes_to_high_in_sats
|
||||
.weekindex
|
||||
.unwrap_max()
|
||||
.double_unwrap_cached_get(i),
|
||||
low: self
|
||||
.timeindexes_to_low_in_sats
|
||||
.weekindex
|
||||
.unwrap_min()
|
||||
.double_unwrap_cached_get(i),
|
||||
open: weekindex_first_iter.unwrap_get_inner(i),
|
||||
high: weekindex_max_iter.unwrap_get_inner(i),
|
||||
low: weekindex_min_iter.unwrap_get_inner(i),
|
||||
close,
|
||||
},
|
||||
)
|
||||
@@ -935,6 +883,21 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut difficultyepoch_first_iter = self
|
||||
.chainindexes_to_open_in_sats
|
||||
.difficultyepoch
|
||||
.unwrap_first()
|
||||
.iter();
|
||||
let mut difficultyepoch_max_iter = self
|
||||
.chainindexes_to_high_in_sats
|
||||
.difficultyepoch
|
||||
.unwrap_max()
|
||||
.iter();
|
||||
let mut difficultyepoch_min_iter = self
|
||||
.chainindexes_to_low_in_sats
|
||||
.difficultyepoch
|
||||
.unwrap_min()
|
||||
.iter();
|
||||
self.difficultyepoch_to_ohlc_in_sats.compute_transform(
|
||||
starting_indexes.difficultyepoch,
|
||||
self.chainindexes_to_close_in_sats
|
||||
@@ -945,21 +908,9 @@ impl Vecs {
|
||||
(
|
||||
i,
|
||||
OHLCSats {
|
||||
open: self
|
||||
.chainindexes_to_open_in_sats
|
||||
.difficultyepoch
|
||||
.unwrap_first()
|
||||
.double_unwrap_cached_get(i),
|
||||
high: self
|
||||
.chainindexes_to_high_in_sats
|
||||
.difficultyepoch
|
||||
.unwrap_max()
|
||||
.double_unwrap_cached_get(i),
|
||||
low: self
|
||||
.chainindexes_to_low_in_sats
|
||||
.difficultyepoch
|
||||
.unwrap_min()
|
||||
.double_unwrap_cached_get(i),
|
||||
open: difficultyepoch_first_iter.unwrap_get_inner(i),
|
||||
high: difficultyepoch_max_iter.unwrap_get_inner(i),
|
||||
low: difficultyepoch_min_iter.unwrap_get_inner(i),
|
||||
close,
|
||||
},
|
||||
)
|
||||
@@ -967,6 +918,21 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut monthindex_first_iter = self
|
||||
.timeindexes_to_open_in_sats
|
||||
.monthindex
|
||||
.unwrap_first()
|
||||
.iter();
|
||||
let mut monthindex_max_iter = self
|
||||
.timeindexes_to_high_in_sats
|
||||
.monthindex
|
||||
.unwrap_max()
|
||||
.iter();
|
||||
let mut monthindex_min_iter = self
|
||||
.timeindexes_to_low_in_sats
|
||||
.monthindex
|
||||
.unwrap_min()
|
||||
.iter();
|
||||
self.monthindex_to_ohlc_in_sats.compute_transform(
|
||||
starting_indexes.monthindex,
|
||||
self.timeindexes_to_close_in_sats
|
||||
@@ -977,21 +943,9 @@ impl Vecs {
|
||||
(
|
||||
i,
|
||||
OHLCSats {
|
||||
open: self
|
||||
.timeindexes_to_open_in_sats
|
||||
.monthindex
|
||||
.unwrap_first()
|
||||
.double_unwrap_cached_get(i),
|
||||
high: self
|
||||
.timeindexes_to_high_in_sats
|
||||
.monthindex
|
||||
.unwrap_max()
|
||||
.double_unwrap_cached_get(i),
|
||||
low: self
|
||||
.timeindexes_to_low_in_sats
|
||||
.monthindex
|
||||
.unwrap_min()
|
||||
.double_unwrap_cached_get(i),
|
||||
open: monthindex_first_iter.unwrap_get_inner(i),
|
||||
high: monthindex_max_iter.unwrap_get_inner(i),
|
||||
low: monthindex_min_iter.unwrap_get_inner(i),
|
||||
close,
|
||||
},
|
||||
)
|
||||
@@ -999,6 +953,21 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut quarterindex_first_iter = self
|
||||
.timeindexes_to_open_in_sats
|
||||
.quarterindex
|
||||
.unwrap_first()
|
||||
.iter();
|
||||
let mut quarterindex_max_iter = self
|
||||
.timeindexes_to_high_in_sats
|
||||
.quarterindex
|
||||
.unwrap_max()
|
||||
.iter();
|
||||
let mut quarterindex_min_iter = self
|
||||
.timeindexes_to_low_in_sats
|
||||
.quarterindex
|
||||
.unwrap_min()
|
||||
.iter();
|
||||
self.quarterindex_to_ohlc_in_sats.compute_transform(
|
||||
starting_indexes.quarterindex,
|
||||
self.timeindexes_to_close_in_sats
|
||||
@@ -1009,21 +978,9 @@ impl Vecs {
|
||||
(
|
||||
i,
|
||||
OHLCSats {
|
||||
open: self
|
||||
.timeindexes_to_open_in_sats
|
||||
.quarterindex
|
||||
.unwrap_first()
|
||||
.double_unwrap_cached_get(i),
|
||||
high: self
|
||||
.timeindexes_to_high_in_sats
|
||||
.quarterindex
|
||||
.unwrap_max()
|
||||
.double_unwrap_cached_get(i),
|
||||
low: self
|
||||
.timeindexes_to_low_in_sats
|
||||
.quarterindex
|
||||
.unwrap_min()
|
||||
.double_unwrap_cached_get(i),
|
||||
open: quarterindex_first_iter.unwrap_get_inner(i),
|
||||
high: quarterindex_max_iter.unwrap_get_inner(i),
|
||||
low: quarterindex_min_iter.unwrap_get_inner(i),
|
||||
close,
|
||||
},
|
||||
)
|
||||
@@ -1031,6 +988,21 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
let mut yearindex_first_iter = self
|
||||
.timeindexes_to_open_in_sats
|
||||
.yearindex
|
||||
.unwrap_first()
|
||||
.iter();
|
||||
let mut yearindex_max_iter = self
|
||||
.timeindexes_to_high_in_sats
|
||||
.yearindex
|
||||
.unwrap_max()
|
||||
.iter();
|
||||
let mut yearindex_min_iter = self
|
||||
.timeindexes_to_low_in_sats
|
||||
.yearindex
|
||||
.unwrap_min()
|
||||
.iter();
|
||||
self.yearindex_to_ohlc_in_sats.compute_transform(
|
||||
starting_indexes.yearindex,
|
||||
self.timeindexes_to_close_in_sats
|
||||
@@ -1041,21 +1013,9 @@ impl Vecs {
|
||||
(
|
||||
i,
|
||||
OHLCSats {
|
||||
open: self
|
||||
.timeindexes_to_open_in_sats
|
||||
.yearindex
|
||||
.unwrap_first()
|
||||
.double_unwrap_cached_get(i),
|
||||
high: self
|
||||
.timeindexes_to_high_in_sats
|
||||
.yearindex
|
||||
.unwrap_max()
|
||||
.double_unwrap_cached_get(i),
|
||||
low: self
|
||||
.timeindexes_to_low_in_sats
|
||||
.yearindex
|
||||
.unwrap_min()
|
||||
.double_unwrap_cached_get(i),
|
||||
open: yearindex_first_iter.unwrap_get_inner(i),
|
||||
high: yearindex_max_iter.unwrap_get_inner(i),
|
||||
low: yearindex_min_iter.unwrap_get_inner(i),
|
||||
close,
|
||||
},
|
||||
)
|
||||
@@ -1066,6 +1026,21 @@ impl Vecs {
|
||||
// self.halvingepoch_to_ohlc
|
||||
// _in_sats.compute_transform(starting_indexes.halvingepoch, other, t, exit)?;
|
||||
|
||||
let mut decadeindex_first_iter = self
|
||||
.timeindexes_to_open_in_sats
|
||||
.decadeindex
|
||||
.unwrap_first()
|
||||
.iter();
|
||||
let mut decadeindex_max_iter = self
|
||||
.timeindexes_to_high_in_sats
|
||||
.decadeindex
|
||||
.unwrap_max()
|
||||
.iter();
|
||||
let mut decadeindex_min_iter = self
|
||||
.timeindexes_to_low_in_sats
|
||||
.decadeindex
|
||||
.unwrap_min()
|
||||
.iter();
|
||||
self.decadeindex_to_ohlc_in_sats.compute_transform(
|
||||
starting_indexes.decadeindex,
|
||||
self.timeindexes_to_close_in_sats
|
||||
@@ -1076,21 +1051,9 @@ impl Vecs {
|
||||
(
|
||||
i,
|
||||
OHLCSats {
|
||||
open: self
|
||||
.timeindexes_to_open_in_sats
|
||||
.decadeindex
|
||||
.unwrap_first()
|
||||
.double_unwrap_cached_get(i),
|
||||
high: self
|
||||
.timeindexes_to_high_in_sats
|
||||
.decadeindex
|
||||
.unwrap_max()
|
||||
.double_unwrap_cached_get(i),
|
||||
low: self
|
||||
.timeindexes_to_low_in_sats
|
||||
.decadeindex
|
||||
.unwrap_min()
|
||||
.double_unwrap_cached_get(i),
|
||||
open: decadeindex_first_iter.unwrap_get_inner(i),
|
||||
high: decadeindex_max_iter.unwrap_get_inner(i),
|
||||
low: decadeindex_min_iter.unwrap_get_inner(i),
|
||||
close,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -531,13 +531,13 @@ impl Vecs {
|
||||
self.inputindex_to_value.compute_transform(
|
||||
starting_indexes.inputindex,
|
||||
indexer.vecs().inputindex_to_outputindex.vec(),
|
||||
|(inputindex, outputindex, slf, ..)| {
|
||||
|(inputindex, outputindex)| {
|
||||
let value = if outputindex == OutputIndex::COINBASE {
|
||||
Sats::ZERO
|
||||
} else if let Some((_, value)) = outputindex_to_value_iter.get(outputindex) {
|
||||
value.into_inner()
|
||||
} else {
|
||||
dbg!(inputindex, outputindex, slf.len(), inputs_len);
|
||||
dbg!(inputindex, outputindex, inputs_len);
|
||||
panic!()
|
||||
};
|
||||
(inputindex, value)
|
||||
|
||||
@@ -120,18 +120,6 @@ where
|
||||
&mut self.inner
|
||||
}
|
||||
|
||||
pub fn unwrap_cached_get(&mut self, index: I) -> Option<T> {
|
||||
self.inner.unwrap_cached_get(index)
|
||||
}
|
||||
#[inline]
|
||||
pub fn double_unwrap_cached_get(&mut self, index: I) -> T {
|
||||
self.inner.double_unwrap_cached_get(index)
|
||||
}
|
||||
|
||||
// pub fn collect_inclusive_range(&self, from: I, to: I) -> Result<Vec<T>> {
|
||||
// self.inner.collect_inclusive_range(from, to)
|
||||
// }
|
||||
|
||||
pub fn path(&self) -> &Path {
|
||||
self.inner.path()
|
||||
}
|
||||
@@ -193,21 +181,17 @@ where
|
||||
where
|
||||
A: StoredIndex,
|
||||
B: StoredType,
|
||||
F: FnMut((A, B, &mut Self, &'_ mut StoredVecIterator<'_, A, B>)) -> (I, T),
|
||||
F: FnMut((A, B)) -> (I, T),
|
||||
{
|
||||
self.validate_computed_version_or_reset_file(
|
||||
Version::ZERO + self.version() + other.version(),
|
||||
)?;
|
||||
|
||||
let index = max_from.min(A::from(self.len()));
|
||||
let mut other_iter = other.iter();
|
||||
other
|
||||
.iter()
|
||||
.skip(index.unwrap_to_usize())
|
||||
.try_for_each(|(a, b)| {
|
||||
let (i, v) = t((a, b.into_inner(), self, &mut other_iter));
|
||||
self.forced_push_at(i, v, exit)
|
||||
})?;
|
||||
other.iter_at(index).try_for_each(|(a, b)| {
|
||||
let (i, v) = t((a, b.into_inner()));
|
||||
self.forced_push_at(i, v, exit)
|
||||
})?;
|
||||
|
||||
self.safe_flush(exit)
|
||||
}
|
||||
@@ -228,20 +212,14 @@ where
|
||||
|
||||
let index = max_from.min(
|
||||
self.inner
|
||||
.cached_get_last()?
|
||||
.map_or_else(T::default, |v| v.into_inner()),
|
||||
.iter()
|
||||
.last()
|
||||
.map_or_else(T::default, |(_, v)| v.into_inner()),
|
||||
);
|
||||
other
|
||||
.iter()
|
||||
.skip(index.unwrap_to_usize())
|
||||
.try_for_each(|(v, i)| {
|
||||
let i = i.into_inner();
|
||||
if self.unwrap_cached_get(i).is_none_or(|old_v| old_v > v) {
|
||||
self.forced_push_at(i, v, exit)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
})?;
|
||||
other.iter_at(index).try_for_each(|(v, i)| {
|
||||
let i = i.into_inner();
|
||||
self.forced_push_at(i, v, exit)
|
||||
})?;
|
||||
|
||||
self.safe_flush(exit)
|
||||
}
|
||||
@@ -265,11 +243,10 @@ where
|
||||
|
||||
let index = max_from.min(T::from(self.len()));
|
||||
first_indexes
|
||||
.iter()
|
||||
.skip(index.unwrap_to_usize())
|
||||
.iter_at(index)
|
||||
.try_for_each(|(value, first_index)| {
|
||||
let first_index = (first_index).to_usize()?;
|
||||
let last_index = last_indexes_iter.get(value).unwrap().1.to_usize()?;
|
||||
let last_index = last_indexes_iter.unwrap_get_inner(value).unwrap_to_usize();
|
||||
(first_index..=last_index)
|
||||
.try_for_each(|index| self.forced_push_at(I::from(index), value, exit))
|
||||
})?;
|
||||
@@ -295,8 +272,7 @@ where
|
||||
let one = T::from(1);
|
||||
let mut prev_index: Option<I> = None;
|
||||
first_indexes
|
||||
.iter()
|
||||
.skip(index.unwrap_to_usize())
|
||||
.iter_at(index)
|
||||
.try_for_each(|(index, v)| -> Result<()> {
|
||||
if let Some(prev_index) = prev_index.take() {
|
||||
let value = v.checked_sub(one).unwrap();
|
||||
@@ -396,8 +372,7 @@ where
|
||||
let mut other_iter = first_indexes.iter();
|
||||
let index = max_from.min(I::from(self.len()));
|
||||
first_indexes
|
||||
.iter()
|
||||
.skip(index.unwrap_to_usize())
|
||||
.iter_at(index)
|
||||
.try_for_each(|(i, first_index)| {
|
||||
let end = other_iter
|
||||
.get(i + 1)
|
||||
@@ -434,23 +409,20 @@ where
|
||||
|
||||
let mut other_to_self_iter = other_to_self.iter();
|
||||
let index = max_from.min(I::from(self.len()));
|
||||
self_to_other
|
||||
.iter()
|
||||
.skip(index.unwrap_to_usize())
|
||||
.try_for_each(|(i, other)| {
|
||||
self.forced_push_at(
|
||||
i,
|
||||
T::from(
|
||||
other_to_self_iter
|
||||
.get(other.into_inner())
|
||||
.unwrap()
|
||||
.1
|
||||
.into_inner()
|
||||
== i,
|
||||
),
|
||||
exit,
|
||||
)
|
||||
})?;
|
||||
self_to_other.iter_at(index).try_for_each(|(i, other)| {
|
||||
self.forced_push_at(
|
||||
i,
|
||||
T::from(
|
||||
other_to_self_iter
|
||||
.get(other.into_inner())
|
||||
.unwrap()
|
||||
.1
|
||||
.into_inner()
|
||||
== i,
|
||||
),
|
||||
exit,
|
||||
)
|
||||
})?;
|
||||
|
||||
self.safe_flush(exit)
|
||||
}
|
||||
@@ -475,8 +447,7 @@ where
|
||||
let mut source_iter = source.iter();
|
||||
let index = max_from.min(I::from(self.len()));
|
||||
first_indexes
|
||||
.iter()
|
||||
.skip(index.unwrap_to_usize())
|
||||
.iter_at(index)
|
||||
.try_for_each(|(i, first_index)| {
|
||||
let last_index = last_indexes_iter.get(i).unwrap().1.into_inner();
|
||||
let range = first_index.unwrap_to_usize()..=last_index.unwrap_to_usize();
|
||||
@@ -506,12 +477,10 @@ where
|
||||
)?;
|
||||
|
||||
let index = max_from.min(I::from(self.len()));
|
||||
sats.iter()
|
||||
.skip(index.unwrap_to_usize())
|
||||
.try_for_each(|(i, sats)| {
|
||||
let (i, v) = (i, Bitcoin::from(sats.into_inner()));
|
||||
self.forced_push_at(i, v, exit)
|
||||
})?;
|
||||
sats.iter_at(index).try_for_each(|(i, sats)| {
|
||||
let (i, v) = (i, Bitcoin::from(sats.into_inner()));
|
||||
self.forced_push_at(i, v, exit)
|
||||
})?;
|
||||
|
||||
self.safe_flush(exit)
|
||||
}
|
||||
@@ -531,14 +500,11 @@ impl EagerVec<Height, Dollars> {
|
||||
|
||||
let mut price_iter = price.iter();
|
||||
let index = max_from.min(Height::from(self.len()));
|
||||
bitcoin
|
||||
.iter()
|
||||
.skip(index.unwrap_to_usize())
|
||||
.try_for_each(|(i, bitcoin)| {
|
||||
let dollars = price_iter.get(i).unwrap().1.into_inner();
|
||||
let (i, v) = (i, *dollars * bitcoin.into_inner());
|
||||
self.forced_push_at(i, v, exit)
|
||||
})?;
|
||||
bitcoin.iter_at(index).try_for_each(|(i, bitcoin)| {
|
||||
let dollars = price_iter.get(i).unwrap().1.into_inner();
|
||||
let (i, v) = (i, *dollars * bitcoin.into_inner());
|
||||
self.forced_push_at(i, v, exit)
|
||||
})?;
|
||||
|
||||
self.safe_flush(exit)
|
||||
}
|
||||
@@ -560,15 +526,12 @@ impl EagerVec<TxIndex, Dollars> {
|
||||
let mut i_to_height_iter = i_to_height.iter();
|
||||
let mut price_iter = price.iter();
|
||||
let index = max_from.min(TxIndex::from(self.len()));
|
||||
bitcoin
|
||||
.iter()
|
||||
.skip(index.unwrap_to_usize())
|
||||
.try_for_each(|(i, bitcoin, ..)| {
|
||||
let height = i_to_height_iter.get(i).unwrap().1.into_inner();
|
||||
let dollars = price_iter.get(height).unwrap().1.into_inner();
|
||||
let (i, v) = (i, *dollars * bitcoin.into_inner());
|
||||
self.forced_push_at(i, v, exit)
|
||||
})?;
|
||||
bitcoin.iter_at(index).try_for_each(|(i, bitcoin, ..)| {
|
||||
let height = i_to_height_iter.get(i).unwrap().1.into_inner();
|
||||
let dollars = price_iter.get(height).unwrap().1.into_inner();
|
||||
let (i, v) = (i, *dollars * bitcoin.into_inner());
|
||||
self.forced_push_at(i, v, exit)
|
||||
})?;
|
||||
|
||||
self.safe_flush(exit)
|
||||
}
|
||||
|
||||
@@ -28,18 +28,6 @@ where
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.inner.is_empty()
|
||||
}
|
||||
|
||||
pub fn unwrap_cached_get(&mut self, index: I) -> Option<T> {
|
||||
self.inner.unwrap_cached_get(index)
|
||||
}
|
||||
#[inline]
|
||||
pub fn double_unwrap_cached_get(&mut self, index: I) -> T {
|
||||
self.inner.double_unwrap_cached_get(index)
|
||||
}
|
||||
|
||||
// pub fn collect_inclusive_range(&self, from: I, to: I) -> Result<Vec<T>> {
|
||||
// self.inner.collect_inclusive_range(from, to)
|
||||
// }
|
||||
}
|
||||
|
||||
impl<I, T> Clone for LazyVec<I, T>
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_core::{
|
||||
AddressBytes, AddressBytesHash, BlockHashPrefix, Height, OutputType, OutputTypeIndex, TxIndex,
|
||||
TxidPrefix,
|
||||
};
|
||||
use brk_vec::{StoredIndex, Value, Version};
|
||||
use brk_vec::{Value, Version};
|
||||
use fjall::{PersistMode, TransactionalKeyspace};
|
||||
|
||||
use crate::Indexes;
|
||||
@@ -88,8 +88,7 @@ impl Stores {
|
||||
|
||||
if starting_indexes.height != Height::ZERO {
|
||||
vecs.height_to_blockhash
|
||||
.into_iter()
|
||||
.skip(starting_indexes.height.unwrap_to_usize())
|
||||
.iter_at(starting_indexes.height)
|
||||
.for_each(|(_, v)| {
|
||||
let blockhashprefix = BlockHashPrefix::from(Value::into_inner(v));
|
||||
self.blockhashprefix_to_height.remove(blockhashprefix);
|
||||
@@ -235,8 +234,7 @@ impl Stores {
|
||||
|
||||
if starting_indexes.txindex != TxIndex::ZERO {
|
||||
vecs.txindex_to_txid
|
||||
.into_iter()
|
||||
.skip(starting_indexes.txindex.unwrap_to_usize())
|
||||
.iter_at(starting_indexes.txindex)
|
||||
.for_each(|(txindex, txid)| {
|
||||
let txidprefix = TxidPrefix::from(&txid.into_inner());
|
||||
|
||||
|
||||
@@ -45,14 +45,6 @@ where
|
||||
pub fn get(&self, index: I) -> Result<Option<Value<'_, T>>> {
|
||||
self.inner.get(index)
|
||||
}
|
||||
#[inline]
|
||||
pub fn unwrap_cached_get(&mut self, index: I) -> Option<T> {
|
||||
self.inner.unwrap_cached_get(index)
|
||||
}
|
||||
#[inline]
|
||||
pub fn double_unwrap_cached_get(&mut self, index: I) -> T {
|
||||
self.inner.double_unwrap_cached_get(index)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn push_if_needed(&mut self, index: I, value: T) -> Result<()> {
|
||||
@@ -124,6 +116,12 @@ where
|
||||
pub fn iter(&self) -> StoredVecIterator<'_, I, T> {
|
||||
self.into_iter()
|
||||
}
|
||||
|
||||
pub fn iter_at(&self, i: I) -> StoredVecIterator<'_, I, T> {
|
||||
let mut iter = self.into_iter();
|
||||
iter.set(i);
|
||||
iter
|
||||
}
|
||||
}
|
||||
|
||||
pub trait AnyIndexedVec: Send + Sync {
|
||||
|
||||
@@ -64,7 +64,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
dbg!(vec.collect_signed_range(Some(-5), None)?);
|
||||
|
||||
vec.push(vec.len() as u32);
|
||||
dbg!(vec.last()?);
|
||||
dbg!(vec.iter().last());
|
||||
|
||||
dbg!(vec.into_iter().collect::<Vec<_>>());
|
||||
}
|
||||
|
||||
+36
-21
@@ -56,6 +56,12 @@ where
|
||||
pub fn iter(&self) -> StoredVecIterator<'_, I, T> {
|
||||
self.into_iter()
|
||||
}
|
||||
|
||||
pub fn iter_at(&self, i: I) -> StoredVecIterator<'_, I, T> {
|
||||
let mut iter = self.into_iter();
|
||||
iter.set(i);
|
||||
iter
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, T> DynamicVec for StoredVec<I, T>
|
||||
@@ -73,13 +79,6 @@ where
|
||||
StoredVec::Compressed(v) => v.get_stored_(index, guard),
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
fn cached_get_stored_(&mut self, index: usize, guard: &Mmap) -> Result<Option<T>> {
|
||||
match self {
|
||||
StoredVec::Raw(v) => v.cached_get_stored_(index, guard),
|
||||
StoredVec::Compressed(v) => v.cached_get_stored_(index, guard),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn mmap(&self) -> &ArcSwap<Mmap> {
|
||||
@@ -244,7 +243,7 @@ where
|
||||
Compressed(CompressedVecIterator<'a, I, T>),
|
||||
}
|
||||
|
||||
impl<'a, I, T> StoredVecIterator<'a, I, T>
|
||||
impl<I, T> StoredVecIterator<'_, I, T>
|
||||
where
|
||||
I: StoredIndex,
|
||||
T: StoredType,
|
||||
@@ -255,33 +254,32 @@ where
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get(&mut self, i: I) -> Option<(I, Value<'a, T>)> {
|
||||
pub fn get_inner(&mut self, i: I) -> Option<T> {
|
||||
self.get_(i.unwrap_to_usize()).map(|(_, v)| v.into_inner())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get(&mut self, i: I) -> Option<(I, Value<'_, T>)> {
|
||||
self.get_(i.unwrap_to_usize())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_(&mut self, i: usize) -> Option<(I, Value<'a, T>)> {
|
||||
pub fn get_(&mut self, i: usize) -> Option<(I, Value<'_, T>)> {
|
||||
match self {
|
||||
Self::Compressed(iter) => {
|
||||
iter.set(i);
|
||||
iter.next()
|
||||
}
|
||||
Self::Raw(iter) => {
|
||||
iter.set(i);
|
||||
iter.next()
|
||||
}
|
||||
Self::Compressed(iter) => iter.get_(i),
|
||||
Self::Raw(iter) => iter.get_(i),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set(&mut self, i: I) {
|
||||
match self {
|
||||
Self::Compressed(iter) => {
|
||||
iter.set(i.unwrap_to_usize());
|
||||
iter.set(i);
|
||||
}
|
||||
Self::Raw(iter) => {
|
||||
iter.set(i.unwrap_to_usize());
|
||||
iter.set(i);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,6 +295,23 @@ where
|
||||
Self::Raw(i) => i.next(),
|
||||
}
|
||||
}
|
||||
|
||||
fn last(self) -> Option<Self::Item>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
match self {
|
||||
Self::Compressed(i) => i.last(),
|
||||
Self::Raw(i) => i.last(),
|
||||
}
|
||||
}
|
||||
|
||||
fn skip(self, _: usize) -> std::iter::Skip<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
todo!("")
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, I, T> IntoIterator for &'a StoredVec<I, T>
|
||||
|
||||
@@ -16,18 +16,6 @@ pub trait DynamicVec: Send + Sync {
|
||||
self.get_(index.to_usize()?)
|
||||
}
|
||||
#[inline]
|
||||
fn cached_get(&mut self, index: Self::I) -> Result<Option<Value<Self::T>>> {
|
||||
self.cached_get_(index.to_usize()?)
|
||||
}
|
||||
#[inline]
|
||||
fn unwrap_cached_get(&mut self, index: Self::I) -> Option<Self::T> {
|
||||
self.cached_get(index).unwrap().map(Value::into_inner)
|
||||
}
|
||||
#[inline]
|
||||
fn double_unwrap_cached_get(&mut self, index: Self::I) -> Self::T {
|
||||
self.unwrap_cached_get(index).unwrap()
|
||||
}
|
||||
#[inline]
|
||||
fn get_(&self, index: usize) -> Result<Option<Value<Self::T>>> {
|
||||
match self.index_to_pushed_index(index) {
|
||||
Ok(index) => {
|
||||
@@ -45,40 +33,13 @@ pub trait DynamicVec: Send + Sync {
|
||||
.map(Value::Owned))
|
||||
}
|
||||
fn get_stored_(&self, index: usize, mmap: &Mmap) -> Result<Option<Self::T>>;
|
||||
fn last(&self) -> Result<Option<Value<Self::T>>> {
|
||||
let len = self.len();
|
||||
if len == 0 {
|
||||
return Ok(None);
|
||||
}
|
||||
self.get_(len - 1)
|
||||
}
|
||||
#[inline]
|
||||
fn cached_get_(&mut self, index: usize) -> Result<Option<Value<Self::T>>> {
|
||||
match self.index_to_pushed_index(index) {
|
||||
Ok(index) => {
|
||||
if let Some(index) = index {
|
||||
return Ok(self.pushed().get(index).map(Value::Ref));
|
||||
}
|
||||
}
|
||||
Err(Error::IndexTooHigh) => return Ok(None),
|
||||
Err(Error::IndexTooLow) => {}
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
|
||||
let mmap = Arc::clone(self.guard().as_ref().unwrap());
|
||||
|
||||
Ok(self
|
||||
.cached_get_stored_(index.to_usize()?, &mmap)?
|
||||
.map(Value::Owned))
|
||||
}
|
||||
fn cached_get_stored_(&mut self, index: usize, mmap: &Mmap) -> Result<Option<Self::T>>;
|
||||
fn cached_get_last(&mut self) -> Result<Option<Value<Self::T>>> {
|
||||
let len = self.len();
|
||||
if len == 0 {
|
||||
return Ok(None);
|
||||
}
|
||||
self.cached_get_(len - 1)
|
||||
}
|
||||
// fn last(&self) -> Result<Option<Value<Self::T>>> {
|
||||
// let len = self.len();
|
||||
// if len == 0 {
|
||||
// return Ok(None);
|
||||
// }
|
||||
// self.get_(len - 1)
|
||||
// }
|
||||
|
||||
#[inline]
|
||||
fn len(&self) -> usize {
|
||||
|
||||
@@ -21,6 +21,7 @@ where
|
||||
fn unwrap_to_usize(self) -> usize;
|
||||
fn to_usize(self) -> Result<usize>;
|
||||
fn to_string<'a>() -> &'a str;
|
||||
fn decremented(self) -> Option<Self>;
|
||||
}
|
||||
impl<I> StoredIndex for I
|
||||
where
|
||||
@@ -52,4 +53,9 @@ where
|
||||
fn to_string<'a>() -> &'a str {
|
||||
std::any::type_name::<I>()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn decremented(self) -> Option<Self> {
|
||||
self.unwrap_to_usize().checked_sub(1).map(Self::from)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,8 @@ pub const MAX_PAGE_SIZE: usize = 16 * ONE_KIB;
|
||||
#[derive(Debug)]
|
||||
pub struct CompressedVec<I, T> {
|
||||
inner: RawVec<I, T>,
|
||||
decoded_page: Option<(usize, Vec<T>)>,
|
||||
decoded_pages: Option<Vec<OnceLock<Vec<T>>>>,
|
||||
pages_meta: Arc<ArcSwap<CompressedPagesMetadata>>,
|
||||
// pages: Option<Vec<OnceLock<Values<T>>>>,
|
||||
// page: Option<(usize, Values<T>)>,
|
||||
// length: Length
|
||||
}
|
||||
|
||||
impl<I, T> CompressedVec<I, T>
|
||||
@@ -71,7 +67,6 @@ where
|
||||
|
||||
Ok(Self {
|
||||
inner: RawVec::import(path, version)?,
|
||||
decoded_page: None,
|
||||
decoded_pages: None,
|
||||
pages_meta: Arc::new(ArcSwap::new(Arc::new(CompressedPagesMetadata::read(path)?))),
|
||||
})
|
||||
@@ -175,12 +170,7 @@ where
|
||||
self.decoded_pages.as_ref().map_or(0, |v| v.len())
|
||||
}
|
||||
|
||||
fn reset_small_cache(&mut self) {
|
||||
self.decoded_page.take();
|
||||
}
|
||||
|
||||
fn reset_caches(&mut self) {
|
||||
self.reset_small_cache();
|
||||
self.reset_large_cache();
|
||||
}
|
||||
|
||||
@@ -202,9 +192,22 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn iter(&self) -> CompressedVecIterator<'_, I, T> {
|
||||
self.into_iter()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn iter_at(&self, i: I) -> CompressedVecIterator<'_, I, T> {
|
||||
self.iter_at_(i.unwrap_to_usize())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn iter_at_(&self, i: usize) -> CompressedVecIterator<'_, I, T> {
|
||||
let mut iter = self.into_iter();
|
||||
iter.set_(i);
|
||||
iter
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, T> DynamicVec for CompressedVec<I, T>
|
||||
@@ -248,16 +251,6 @@ where
|
||||
.get(decoded_index)
|
||||
.cloned())
|
||||
}
|
||||
#[inline]
|
||||
fn cached_get_stored_(&mut self, index: usize, mmap: &Mmap) -> Result<Option<T>> {
|
||||
Self::cached_get_stored__(
|
||||
index,
|
||||
mmap,
|
||||
self.stored_len(),
|
||||
&mut self.decoded_page,
|
||||
&self.pages_meta.load(),
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn mmap(&self) -> &ArcSwap<Mmap> {
|
||||
@@ -307,8 +300,7 @@ where
|
||||
}
|
||||
|
||||
Ok(self
|
||||
.into_iter()
|
||||
.skip(from)
|
||||
.iter_at_(from)
|
||||
.take(to - from)
|
||||
.map(|(_, v)| v.into_inner())
|
||||
.collect::<Vec<_>>())
|
||||
@@ -342,12 +334,6 @@ where
|
||||
.and_then(|v| v.last_mut().and_then(|lock| lock.take()))
|
||||
{
|
||||
values
|
||||
} else if self
|
||||
.decoded_page
|
||||
.as_ref()
|
||||
.is_some_and(|(page_index, _)| *page_index == last_page_index)
|
||||
{
|
||||
self.decoded_page.take().unwrap().1
|
||||
} else {
|
||||
Self::decode_page_(
|
||||
stored_len,
|
||||
@@ -485,7 +471,6 @@ where
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
inner: self.inner.clone(),
|
||||
decoded_page: None,
|
||||
decoded_pages: None,
|
||||
pages_meta: self.pages_meta.clone(),
|
||||
}
|
||||
@@ -503,9 +488,31 @@ pub struct CompressedVecIterator<'a, I, T> {
|
||||
index: usize,
|
||||
}
|
||||
|
||||
impl<I, T> CompressedVecIterator<'_, I, T> {
|
||||
pub fn set(&mut self, i: usize) {
|
||||
self.index = i
|
||||
impl<I, T> CompressedVecIterator<'_, I, T>
|
||||
where
|
||||
I: StoredIndex,
|
||||
T: StoredType,
|
||||
{
|
||||
#[inline]
|
||||
pub fn set(&mut self, i: I) -> &mut Self {
|
||||
self.index = i.unwrap_to_usize();
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_(&mut self, i: usize) {
|
||||
self.index = i;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get(&mut self, i: I) -> Option<(I, Value<'_, T>)> {
|
||||
self.set(i).next()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_(&mut self, i: usize) -> Option<(I, Value<'_, T>)> {
|
||||
self.set_(i);
|
||||
self.next()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,9 +63,22 @@ where
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn iter(&self) -> RawVecIterator<'_, I, T> {
|
||||
self.into_iter()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn iter_at(&self, i: I) -> RawVecIterator<'_, I, T> {
|
||||
self.iter_at_(i.unwrap_to_usize())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn iter_at_(&self, i: usize) -> RawVecIterator<'_, I, T> {
|
||||
let mut iter = self.into_iter();
|
||||
iter.set_(i);
|
||||
iter
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, T> DynamicVec for RawVec<I, T>
|
||||
@@ -84,10 +97,6 @@ where
|
||||
.map(|v| Some(v))
|
||||
.map_err(Error::from)
|
||||
}
|
||||
#[inline]
|
||||
fn cached_get_stored_(&mut self, index: usize, mmap: &Mmap) -> Result<Option<T>> {
|
||||
self.get_stored_(index, mmap)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn mmap(&self) -> &ArcSwap<Mmap> {
|
||||
@@ -142,8 +151,7 @@ where
|
||||
}
|
||||
|
||||
Ok(self
|
||||
.into_iter()
|
||||
.skip(from)
|
||||
.iter_at_(from)
|
||||
.take(to - from)
|
||||
.map(|(_, v)| v.into_inner())
|
||||
.collect::<Vec<_>>())
|
||||
@@ -226,11 +234,33 @@ pub struct RawVecIterator<'a, I, T> {
|
||||
index: usize,
|
||||
}
|
||||
|
||||
impl<I, T> RawVecIterator<'_, I, T> {
|
||||
impl<I, T> RawVecIterator<'_, I, T>
|
||||
where
|
||||
I: StoredIndex,
|
||||
T: StoredType,
|
||||
{
|
||||
const SIZE_OF_T: usize = size_of::<T>();
|
||||
|
||||
pub fn set(&mut self, i: usize) {
|
||||
self.index = i
|
||||
#[inline]
|
||||
pub fn set(&mut self, i: I) -> &mut Self {
|
||||
self.index = i.unwrap_to_usize();
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_(&mut self, i: usize) {
|
||||
self.index = i;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get(&mut self, i: I) -> Option<(I, Value<'_, T>)> {
|
||||
self.set(i).next()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_(&mut self, i: usize) -> Option<(I, Value<'_, T>)> {
|
||||
self.set_(i);
|
||||
self.next()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,6 +292,18 @@ where
|
||||
self.index += 1;
|
||||
result
|
||||
}
|
||||
|
||||
fn last(mut self) -> Option<Self::Item>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let len = self.vec.len();
|
||||
if len == 0 {
|
||||
return None;
|
||||
}
|
||||
self.get_(len - 1)
|
||||
.map(|(i, v)| (i, Value::Owned(v.into_inner())))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, I, T> IntoIterator for &'a RawVec<I, T>
|
||||
|
||||
@@ -202,23 +202,11 @@ export function createVecIdToIndexes() {
|
||||
"is-coinbase": [TxIndex],
|
||||
"is-explicitly-rbf": [TxIndex],
|
||||
"last-dateindex": [MonthIndex, WeekIndex],
|
||||
"last-emptyoutputindex": [Height],
|
||||
"last-height": [DateIndex, DifficultyEpoch, HalvingEpoch],
|
||||
"last-inputindex": [TxIndex],
|
||||
"last-monthindex": [QuarterIndex, YearIndex],
|
||||
"last-opreturnindex": [Height],
|
||||
"last-outputindex": [TxIndex],
|
||||
"last-p2aindex": [Height],
|
||||
"last-p2msindex": [Height],
|
||||
"last-p2pk33index": [Height],
|
||||
"last-p2pk65index": [Height],
|
||||
"last-p2pkhindex": [Height],
|
||||
"last-p2shindex": [Height],
|
||||
"last-p2trindex": [Height],
|
||||
"last-p2wpkhindex": [Height],
|
||||
"last-p2wshindex": [Height],
|
||||
"last-txindex": [Height],
|
||||
"last-unknownoutputindex": [Height],
|
||||
"last-yearindex": [DecadeIndex],
|
||||
low: [DateIndex, DecadeIndex, DifficultyEpoch, Height, MonthIndex, QuarterIndex, WeekIndex, YearIndex],
|
||||
"low-in-cents": [DateIndex, Height],
|
||||
|
||||
Reference in New Issue
Block a user