mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-29 17:19:57 -07:00
global: vec iter part 2
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user