mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-25 15:19:58 -07:00
computer: use count instead of last_index
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use std::path::Path;
|
||||
|
||||
use brk_core::CheckedSub;
|
||||
use brk_core::{CheckedSub, StoredUsize};
|
||||
use brk_exit::Exit;
|
||||
use brk_vec::{Compressed, DynamicVec, Result, StoredIndex, StoredType, StoredVec, Version};
|
||||
use color_eyre::eyre::ContextCompat;
|
||||
@@ -162,7 +162,7 @@ where
|
||||
max_from: I,
|
||||
source: &StoredVec<I2, T>,
|
||||
first_indexes: &StoredVec<I, I2>,
|
||||
last_indexes: &StoredVec<I, I2>,
|
||||
count_indexes: &StoredVec<I, StoredUsize>,
|
||||
exit: &Exit,
|
||||
) -> Result<()>
|
||||
where
|
||||
@@ -170,7 +170,7 @@ where
|
||||
{
|
||||
let index = self.starting_index(max_from);
|
||||
|
||||
let mut last_indexes_iter = last_indexes.iter();
|
||||
let mut count_indexes_iter = count_indexes.iter();
|
||||
let mut source_iter = source.iter();
|
||||
|
||||
let total_vec = self.total.as_mut();
|
||||
@@ -186,14 +186,17 @@ where
|
||||
.try_for_each(|(i, first_index)| -> Result<()> {
|
||||
let first_index = first_index.into_inner();
|
||||
|
||||
let last_index = last_indexes_iter.get(i).unwrap().1.into_inner();
|
||||
let count_index = count_indexes_iter.get(i).unwrap().1.into_inner();
|
||||
|
||||
if let Some(first) = self.first.as_mut() {
|
||||
let v = source_iter.get(first_index).unwrap().1.into_inner();
|
||||
first.forced_push_at(index, v, exit)?;
|
||||
let f = source_iter
|
||||
.get(first_index)
|
||||
.map_or(T::from(0_usize), |f| f.1.into_inner());
|
||||
first.forced_push_at(index, f, exit)?;
|
||||
}
|
||||
|
||||
if let Some(last) = self.last.as_mut() {
|
||||
let last_index = first_index + *count_index;
|
||||
let v = source_iter.get(last_index).unwrap().1.into_inner();
|
||||
last.forced_push_at(index, v, exit)?;
|
||||
}
|
||||
@@ -212,12 +215,7 @@ where
|
||||
if needs_values {
|
||||
source_iter.set(first_index);
|
||||
let mut values = (&mut source_iter)
|
||||
.take(
|
||||
last_index
|
||||
.checked_sub(first_index)
|
||||
.unwrap()
|
||||
.unwrap_to_usize(),
|
||||
)
|
||||
.take(*count_index)
|
||||
.map(|(_, v)| v.into_inner())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@@ -236,8 +234,8 @@ where
|
||||
max.path(),
|
||||
first_indexes.path(),
|
||||
first_index,
|
||||
last_indexes.path(),
|
||||
last_index,
|
||||
count_indexes.path(),
|
||||
count_index,
|
||||
source.len(),
|
||||
source.path()
|
||||
);
|
||||
@@ -310,7 +308,7 @@ where
|
||||
max_from: I,
|
||||
source: &ComputedVecBuilder<I2, T>,
|
||||
first_indexes: &StoredVec<I, I2>,
|
||||
last_indexes: &StoredVec<I, I2>,
|
||||
count_indexes: &StoredVec<I, StoredUsize>,
|
||||
exit: &Exit,
|
||||
) -> Result<()>
|
||||
where
|
||||
@@ -327,7 +325,7 @@ where
|
||||
|
||||
let index = self.starting_index(max_from);
|
||||
|
||||
let mut last_indexes_iter = last_indexes.iter();
|
||||
let mut count_indexes_iter = count_indexes.iter();
|
||||
|
||||
let mut source_first_iter = source.first.as_ref().map(|f| f.iter());
|
||||
let mut source_last_iter = source.last.as_ref().map(|f| f.iter());
|
||||
@@ -347,7 +345,7 @@ where
|
||||
.try_for_each(|(i, first_index, ..)| -> Result<()> {
|
||||
let first_index = first_index.into_inner();
|
||||
|
||||
let last_index = last_indexes_iter.get(i).unwrap().1.into_inner();
|
||||
let count_index = count_indexes_iter.get(i).unwrap().1.into_inner();
|
||||
|
||||
if let Some(first) = self.first.as_mut() {
|
||||
let v = source_first_iter
|
||||
@@ -358,6 +356,7 @@ where
|
||||
}
|
||||
|
||||
if let Some(last) = self.last.as_mut() {
|
||||
let last_index = first_index + *count_index;
|
||||
let v = source_last_iter
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
@@ -376,12 +375,7 @@ where
|
||||
let source_max_iter = source_max_iter.as_mut().unwrap();
|
||||
source_max_iter.set(first_index);
|
||||
let mut values = source_max_iter
|
||||
.take(
|
||||
last_index
|
||||
.checked_sub(first_index)
|
||||
.unwrap()
|
||||
.unwrap_to_usize(),
|
||||
)
|
||||
.take(*count_index)
|
||||
.map(|(_, v)| v.into_inner())
|
||||
.collect::<Vec<_>>();
|
||||
values.sort_unstable();
|
||||
@@ -392,12 +386,7 @@ where
|
||||
let source_min_iter = source_min_iter.as_mut().unwrap();
|
||||
source_min_iter.set(first_index);
|
||||
let mut values = source_min_iter
|
||||
.take(
|
||||
last_index
|
||||
.checked_sub(first_index)
|
||||
.unwrap()
|
||||
.unwrap_to_usize(),
|
||||
)
|
||||
.take(*count_index)
|
||||
.map(|(_, v)| v.into_inner())
|
||||
.collect::<Vec<_>>();
|
||||
values.sort_unstable();
|
||||
@@ -410,12 +399,7 @@ where
|
||||
let source_average_iter = source_average_iter.as_mut().unwrap();
|
||||
source_average_iter.set(first_index);
|
||||
let values = source_average_iter
|
||||
.take(
|
||||
last_index
|
||||
.checked_sub(first_index)
|
||||
.unwrap()
|
||||
.unwrap_to_usize(),
|
||||
)
|
||||
.take(*count_index)
|
||||
.map(|(_, v)| v.into_inner())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@@ -431,12 +415,7 @@ where
|
||||
let source_sum_iter = source_sum_iter.as_mut().unwrap();
|
||||
source_sum_iter.set(first_index);
|
||||
let values = source_sum_iter
|
||||
.take(
|
||||
last_index
|
||||
.checked_sub(first_index)
|
||||
.unwrap()
|
||||
.unwrap_to_usize(),
|
||||
)
|
||||
.take(*count_index)
|
||||
.map(|(_, v)| v.into_inner())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ where
|
||||
starting_indexes.weekindex,
|
||||
self.dateindex.vec(),
|
||||
indexes.weekindex_to_first_dateindex.vec(),
|
||||
indexes.weekindex_to_last_dateindex.vec(),
|
||||
indexes.weekindex_to_dateindex_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -109,7 +109,7 @@ where
|
||||
starting_indexes.monthindex,
|
||||
self.dateindex.vec(),
|
||||
indexes.monthindex_to_first_dateindex.vec(),
|
||||
indexes.monthindex_to_last_dateindex.vec(),
|
||||
indexes.monthindex_to_dateindex_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -117,7 +117,7 @@ where
|
||||
starting_indexes.quarterindex,
|
||||
&self.monthindex,
|
||||
indexes.quarterindex_to_first_monthindex.vec(),
|
||||
indexes.quarterindex_to_last_monthindex.vec(),
|
||||
indexes.quarterindex_to_monthindex_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -125,7 +125,7 @@ where
|
||||
starting_indexes.yearindex,
|
||||
&self.monthindex,
|
||||
indexes.yearindex_to_first_monthindex.vec(),
|
||||
indexes.yearindex_to_last_monthindex.vec(),
|
||||
indexes.yearindex_to_monthindex_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -133,7 +133,7 @@ where
|
||||
starting_indexes.decadeindex,
|
||||
&self.yearindex,
|
||||
indexes.decadeindex_to_first_yearindex.vec(),
|
||||
indexes.decadeindex_to_last_yearindex.vec(),
|
||||
indexes.decadeindex_to_yearindex_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ where
|
||||
starting_indexes.dateindex,
|
||||
height,
|
||||
indexes.dateindex_to_first_height.vec(),
|
||||
indexes.dateindex_to_last_height.vec(),
|
||||
indexes.dateindex_to_height_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -133,7 +133,7 @@ where
|
||||
starting_indexes.weekindex,
|
||||
&self.dateindex,
|
||||
indexes.weekindex_to_first_dateindex.vec(),
|
||||
indexes.weekindex_to_last_dateindex.vec(),
|
||||
indexes.weekindex_to_dateindex_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -141,7 +141,7 @@ where
|
||||
starting_indexes.monthindex,
|
||||
&self.dateindex,
|
||||
indexes.monthindex_to_first_dateindex.vec(),
|
||||
indexes.monthindex_to_last_dateindex.vec(),
|
||||
indexes.monthindex_to_dateindex_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -149,7 +149,7 @@ where
|
||||
starting_indexes.quarterindex,
|
||||
&self.monthindex,
|
||||
indexes.quarterindex_to_first_monthindex.vec(),
|
||||
indexes.quarterindex_to_last_monthindex.vec(),
|
||||
indexes.quarterindex_to_monthindex_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -157,7 +157,7 @@ where
|
||||
starting_indexes.yearindex,
|
||||
&self.monthindex,
|
||||
indexes.yearindex_to_first_monthindex.vec(),
|
||||
indexes.yearindex_to_last_monthindex.vec(),
|
||||
indexes.yearindex_to_monthindex_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -165,7 +165,7 @@ where
|
||||
starting_indexes.decadeindex,
|
||||
&self.yearindex,
|
||||
indexes.decadeindex_to_first_yearindex.vec(),
|
||||
indexes.decadeindex_to_last_yearindex.vec(),
|
||||
indexes.decadeindex_to_yearindex_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -173,7 +173,7 @@ where
|
||||
starting_indexes.difficultyepoch,
|
||||
height,
|
||||
indexes.difficultyepoch_to_first_height.vec(),
|
||||
indexes.difficultyepoch_to_last_height.vec(),
|
||||
indexes.difficultyepoch_to_height_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ where
|
||||
starting_indexes.difficultyepoch,
|
||||
self.height.vec(),
|
||||
indexes.difficultyepoch_to_first_height.vec(),
|
||||
indexes.difficultyepoch_to_last_height.vec(),
|
||||
indexes.difficultyepoch_to_height_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ where
|
||||
starting_indexes.height,
|
||||
txindex,
|
||||
indexer.vecs().height_to_first_txindex.vec(),
|
||||
indexes.height_to_last_txindex.vec(),
|
||||
indexes.height_to_txindex_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -133,7 +133,7 @@ where
|
||||
starting_indexes.dateindex,
|
||||
&self.height,
|
||||
indexes.dateindex_to_first_height.vec(),
|
||||
indexes.dateindex_to_last_height.vec(),
|
||||
indexes.dateindex_to_height_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -141,7 +141,7 @@ where
|
||||
starting_indexes.weekindex,
|
||||
&self.dateindex,
|
||||
indexes.weekindex_to_first_dateindex.vec(),
|
||||
indexes.weekindex_to_last_dateindex.vec(),
|
||||
indexes.weekindex_to_dateindex_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -149,7 +149,7 @@ where
|
||||
starting_indexes.monthindex,
|
||||
&self.dateindex,
|
||||
indexes.monthindex_to_first_dateindex.vec(),
|
||||
indexes.monthindex_to_last_dateindex.vec(),
|
||||
indexes.monthindex_to_dateindex_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -157,7 +157,7 @@ where
|
||||
starting_indexes.quarterindex,
|
||||
&self.monthindex,
|
||||
indexes.quarterindex_to_first_monthindex.vec(),
|
||||
indexes.quarterindex_to_last_monthindex.vec(),
|
||||
indexes.quarterindex_to_monthindex_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -165,7 +165,7 @@ where
|
||||
starting_indexes.yearindex,
|
||||
&self.monthindex,
|
||||
indexes.yearindex_to_first_monthindex.vec(),
|
||||
indexes.yearindex_to_last_monthindex.vec(),
|
||||
indexes.yearindex_to_monthindex_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -173,7 +173,7 @@ where
|
||||
starting_indexes.decadeindex,
|
||||
&self.yearindex,
|
||||
indexes.decadeindex_to_first_yearindex.vec(),
|
||||
indexes.decadeindex_to_last_yearindex.vec(),
|
||||
indexes.decadeindex_to_yearindex_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -181,7 +181,7 @@ where
|
||||
starting_indexes.difficultyepoch,
|
||||
&self.height,
|
||||
indexes.difficultyepoch_to_first_height.vec(),
|
||||
indexes.difficultyepoch_to_last_height.vec(),
|
||||
indexes.difficultyepoch_to_height_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use brk_core::{
|
||||
Date, DateIndex, DecadeIndex, DifficultyEpoch, EmptyOutputIndex, HalvingEpoch, Height,
|
||||
InputIndex, MonthIndex, OpReturnIndex, OutputIndex, P2AIndex, P2MSIndex, P2PK33Index,
|
||||
P2PK65Index, P2PKHIndex, P2SHIndex, P2TRIndex, P2WPKHIndex, P2WSHIndex, QuarterIndex,
|
||||
Timestamp, TxIndex, UnknownOutputIndex, WeekIndex, YearIndex,
|
||||
StoredUsize, Timestamp, TxIndex, UnknownOutputIndex, WeekIndex, YearIndex,
|
||||
};
|
||||
use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
@@ -17,14 +17,17 @@ pub struct Vecs {
|
||||
pub dateindex_to_date: EagerVec<DateIndex, Date>,
|
||||
pub dateindex_to_dateindex: EagerVec<DateIndex, DateIndex>,
|
||||
pub dateindex_to_first_height: EagerVec<DateIndex, Height>,
|
||||
pub dateindex_to_height_count: EagerVec<DateIndex, StoredUsize>,
|
||||
pub dateindex_to_last_height: EagerVec<DateIndex, Height>,
|
||||
pub dateindex_to_monthindex: EagerVec<DateIndex, MonthIndex>,
|
||||
pub dateindex_to_weekindex: EagerVec<DateIndex, WeekIndex>,
|
||||
pub decadeindex_to_decadeindex: EagerVec<DecadeIndex, DecadeIndex>,
|
||||
pub decadeindex_to_first_yearindex: EagerVec<DecadeIndex, YearIndex>,
|
||||
pub decadeindex_to_last_yearindex: EagerVec<DecadeIndex, YearIndex>,
|
||||
pub decadeindex_to_yearindex_count: EagerVec<DecadeIndex, StoredUsize>,
|
||||
pub difficultyepoch_to_difficultyepoch: EagerVec<DifficultyEpoch, DifficultyEpoch>,
|
||||
pub difficultyepoch_to_first_height: EagerVec<DifficultyEpoch, Height>,
|
||||
pub difficultyepoch_to_height_count: EagerVec<DifficultyEpoch, StoredUsize>,
|
||||
pub difficultyepoch_to_last_height: EagerVec<DifficultyEpoch, Height>,
|
||||
pub emptyoutputindex_to_emptyoutputindex: EagerVec<EmptyOutputIndex, EmptyOutputIndex>,
|
||||
pub halvingepoch_to_first_height: EagerVec<HalvingEpoch, Height>,
|
||||
@@ -36,21 +39,11 @@ pub struct Vecs {
|
||||
pub height_to_difficultyepoch: EagerVec<Height, DifficultyEpoch>,
|
||||
pub height_to_halvingepoch: EagerVec<Height, HalvingEpoch>,
|
||||
pub height_to_height: EagerVec<Height, Height>,
|
||||
// pub height_to_last_emptyoutputindex: EagerVec<Height, EmptyOutputIndex>,
|
||||
// pub height_to_last_opreturnindex: EagerVec<Height, OpReturnIndex>,
|
||||
// pub height_to_last_p2aindex: EagerVec<Height, P2AIndex>,
|
||||
// pub height_to_last_p2msindex: EagerVec<Height, P2MSIndex>,
|
||||
// pub height_to_last_p2pk33index: EagerVec<Height, P2PK33Index>,
|
||||
// pub height_to_last_p2pk65index: EagerVec<Height, P2PK65Index>,
|
||||
// pub height_to_last_p2pkhindex: EagerVec<Height, P2PKHIndex>,
|
||||
// pub height_to_last_p2shindex: EagerVec<Height, P2SHIndex>,
|
||||
// pub height_to_last_p2trindex: EagerVec<Height, P2TRIndex>,
|
||||
// pub height_to_last_p2wpkhindex: EagerVec<Height, P2WPKHIndex>,
|
||||
// pub height_to_last_p2wshindex: EagerVec<Height, P2WSHIndex>,
|
||||
pub height_to_last_txindex: EagerVec<Height, TxIndex>,
|
||||
// pub height_to_last_unknownoutputindex: EagerVec<Height, UnknownOutputIndex>,
|
||||
pub height_to_timestamp_fixed: EagerVec<Height, Timestamp>,
|
||||
pub height_to_txindex_count: EagerVec<Height, StoredUsize>,
|
||||
pub inputindex_to_inputindex: EagerVec<InputIndex, InputIndex>,
|
||||
pub monthindex_to_dateindex_count: EagerVec<MonthIndex, StoredUsize>,
|
||||
pub monthindex_to_first_dateindex: EagerVec<MonthIndex, DateIndex>,
|
||||
pub monthindex_to_last_dateindex: EagerVec<MonthIndex, DateIndex>,
|
||||
pub monthindex_to_monthindex: EagerVec<MonthIndex, MonthIndex>,
|
||||
@@ -69,18 +62,21 @@ pub struct Vecs {
|
||||
pub p2wshindex_to_p2wshindex: EagerVec<P2WSHIndex, P2WSHIndex>,
|
||||
pub quarterindex_to_first_monthindex: EagerVec<QuarterIndex, MonthIndex>,
|
||||
pub quarterindex_to_last_monthindex: EagerVec<QuarterIndex, MonthIndex>,
|
||||
pub quarterindex_to_monthindex_count: EagerVec<QuarterIndex, StoredUsize>,
|
||||
pub quarterindex_to_quarterindex: EagerVec<QuarterIndex, QuarterIndex>,
|
||||
pub txindex_to_height: EagerVec<TxIndex, Height>,
|
||||
pub txindex_to_last_inputindex: EagerVec<TxIndex, InputIndex>,
|
||||
pub txindex_to_last_outputindex: EagerVec<TxIndex, OutputIndex>,
|
||||
pub txindex_to_txindex: EagerVec<TxIndex, TxIndex>,
|
||||
pub unknownoutputindex_to_unknownoutputindex: EagerVec<UnknownOutputIndex, UnknownOutputIndex>,
|
||||
pub weekindex_to_dateindex_count: EagerVec<WeekIndex, StoredUsize>,
|
||||
pub weekindex_to_first_dateindex: EagerVec<WeekIndex, DateIndex>,
|
||||
pub weekindex_to_last_dateindex: EagerVec<WeekIndex, DateIndex>,
|
||||
pub weekindex_to_weekindex: EagerVec<WeekIndex, WeekIndex>,
|
||||
pub yearindex_to_decadeindex: EagerVec<YearIndex, DecadeIndex>,
|
||||
pub yearindex_to_first_monthindex: EagerVec<YearIndex, MonthIndex>,
|
||||
pub yearindex_to_last_monthindex: EagerVec<YearIndex, MonthIndex>,
|
||||
pub yearindex_to_monthindex_count: EagerVec<YearIndex, StoredUsize>,
|
||||
pub yearindex_to_yearindex: EagerVec<YearIndex, YearIndex>,
|
||||
}
|
||||
|
||||
@@ -369,6 +365,46 @@ impl Vecs {
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
height_to_txindex_count: EagerVec::forced_import(
|
||||
&path.join("height_to_txindex_count"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
dateindex_to_height_count: EagerVec::forced_import(
|
||||
&path.join("dateindex_to_height_count"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
weekindex_to_dateindex_count: EagerVec::forced_import(
|
||||
&path.join("weekindex_to_dateindex_count"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
difficultyepoch_to_height_count: EagerVec::forced_import(
|
||||
&path.join("difficultyepoch_to_height_count"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
monthindex_to_dateindex_count: EagerVec::forced_import(
|
||||
&path.join("monthindex_to_dateindex_count"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
quarterindex_to_monthindex_count: EagerVec::forced_import(
|
||||
&path.join("quarterindex_to_monthindex_count"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
yearindex_to_monthindex_count: EagerVec::forced_import(
|
||||
&path.join("yearindex_to_monthindex_count"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
decadeindex_to_yearindex_count: EagerVec::forced_import(
|
||||
&path.join("decadeindex_to_yearindex_count"),
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
// height_to_last_p2aindex: EagerVec::forced_import(
|
||||
// &path.join("height_to_last_p2aindex"),
|
||||
// Version::ZERO,
|
||||
@@ -681,10 +717,17 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.height_to_txindex_count.compute_count_from_indexes(
|
||||
starting_indexes.height,
|
||||
indexer_vecs.height_to_first_txindex.vec(),
|
||||
indexer_vecs.txindex_to_txid.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.txindex_to_height.compute_inverse_less_to_more(
|
||||
starting_indexes.height,
|
||||
indexer_vecs.height_to_first_txindex.vec(),
|
||||
self.height_to_last_txindex.vec(),
|
||||
self.height_to_txindex_count.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
@@ -787,6 +830,13 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.dateindex_to_height_count.compute_count_from_indexes(
|
||||
starting_dateindex,
|
||||
self.dateindex_to_first_height.vec(),
|
||||
indexer_vecs.height_to_weight.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// ---
|
||||
// WeekIndex
|
||||
// ---
|
||||
@@ -826,6 +876,14 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.weekindex_to_dateindex_count
|
||||
.compute_count_from_indexes(
|
||||
starting_weekindex,
|
||||
self.weekindex_to_first_dateindex.vec(),
|
||||
self.dateindex_to_date.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// ---
|
||||
// DifficultyEpoch
|
||||
// ---
|
||||
@@ -865,6 +923,14 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.difficultyepoch_to_height_count
|
||||
.compute_count_from_indexes(
|
||||
starting_difficultyepoch,
|
||||
self.difficultyepoch_to_first_height.vec(),
|
||||
self.height_to_date.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// ---
|
||||
// MonthIndex
|
||||
// ---
|
||||
@@ -906,6 +972,14 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.monthindex_to_dateindex_count
|
||||
.compute_count_from_indexes(
|
||||
starting_monthindex,
|
||||
self.monthindex_to_first_dateindex.vec(),
|
||||
self.dateindex_to_date.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// ---
|
||||
// QuarterIndex
|
||||
// ---
|
||||
@@ -947,6 +1021,14 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.quarterindex_to_monthindex_count
|
||||
.compute_count_from_indexes(
|
||||
starting_quarterindex,
|
||||
self.quarterindex_to_first_monthindex.vec(),
|
||||
self.monthindex_to_monthindex.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
// ---
|
||||
// YearIndex
|
||||
// ---
|
||||
@@ -988,6 +1070,13 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.yearindex_to_monthindex_count
|
||||
.compute_count_from_indexes(
|
||||
starting_yearindex,
|
||||
self.yearindex_to_first_monthindex.vec(),
|
||||
self.monthindex_to_monthindex.vec(),
|
||||
exit,
|
||||
)?;
|
||||
// ---
|
||||
// HalvingEpoch
|
||||
// ---
|
||||
@@ -1066,6 +1155,14 @@ impl Vecs {
|
||||
exit,
|
||||
)?;
|
||||
|
||||
self.decadeindex_to_yearindex_count
|
||||
.compute_count_from_indexes(
|
||||
starting_decadeindex,
|
||||
self.decadeindex_to_first_yearindex.vec(),
|
||||
self.yearindex_to_yearindex.vec(),
|
||||
exit,
|
||||
)?;
|
||||
|
||||
Ok(Indexes {
|
||||
indexes: starting_indexes,
|
||||
dateindex: starting_dateindex,
|
||||
@@ -1136,6 +1233,14 @@ impl Vecs {
|
||||
self.p2aindex_to_p2aindex.any_vec(),
|
||||
self.unknownoutputindex_to_unknownoutputindex.any_vec(),
|
||||
self.outputindex_to_outputindex.any_vec(),
|
||||
self.height_to_txindex_count.any_vec(),
|
||||
self.dateindex_to_height_count.any_vec(),
|
||||
self.weekindex_to_dateindex_count.any_vec(),
|
||||
self.difficultyepoch_to_height_count.any_vec(),
|
||||
self.monthindex_to_dateindex_count.any_vec(),
|
||||
self.quarterindex_to_monthindex_count.any_vec(),
|
||||
self.yearindex_to_monthindex_count.any_vec(),
|
||||
self.decadeindex_to_yearindex_count.any_vec(),
|
||||
// self.height_to_last_p2aindex.any_vec(),
|
||||
// self.height_to_last_p2msindex.any_vec(),
|
||||
// self.height_to_last_p2pk33index.any_vec(),
|
||||
|
||||
@@ -64,7 +64,7 @@ impl Vecs {
|
||||
|vec, _, indexes, starting_indexes, exit| {
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
indexes.dateindex_to_last_height.vec(),
|
||||
indexes.dateindex_to_first_height.vec(),
|
||||
|(di, height, ..)| {
|
||||
(
|
||||
di,
|
||||
@@ -89,7 +89,7 @@ impl Vecs {
|
||||
|vec, _, indexes, starting_indexes, exit| {
|
||||
vec.compute_transform(
|
||||
starting_indexes.dateindex,
|
||||
indexes.dateindex_to_last_height.vec(),
|
||||
indexes.dateindex_to_first_height.vec(),
|
||||
|(di, height, ..)| (di, height_to_halvingepoch_iter.unwrap_get_inner(height)),
|
||||
exit,
|
||||
)
|
||||
|
||||
@@ -18,11 +18,11 @@ pub use vec::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Vecs {
|
||||
pub blocks: blocks::Vecs,
|
||||
pub indexes: indexes::Vecs,
|
||||
pub mining: mining::Vecs,
|
||||
pub transactions: transactions::Vecs,
|
||||
pub marketprice: Option<marketprice::Vecs>,
|
||||
// pub blocks: blocks::Vecs,
|
||||
// pub mining: mining::Vecs,
|
||||
// pub transactions: transactions::Vecs,
|
||||
// pub marketprice: Option<marketprice::Vecs>,
|
||||
}
|
||||
|
||||
impl Vecs {
|
||||
@@ -30,11 +30,11 @@ impl Vecs {
|
||||
fs::create_dir_all(path)?;
|
||||
|
||||
Ok(Self {
|
||||
blocks: blocks::Vecs::forced_import(path, compressed)?,
|
||||
// blocks: blocks::Vecs::forced_import(path, compressed)?,
|
||||
indexes: indexes::Vecs::forced_import(path, compressed)?,
|
||||
mining: mining::Vecs::forced_import(path, compressed)?,
|
||||
transactions: transactions::Vecs::forced_import(path, compressed, fetch)?,
|
||||
marketprice: fetch.then(|| marketprice::Vecs::forced_import(path, compressed).unwrap()),
|
||||
// mining: mining::Vecs::forced_import(path, compressed)?,
|
||||
// transactions: transactions::Vecs::forced_import(path, compressed, fetch)?,
|
||||
// marketprice: fetch.then(|| marketprice::Vecs::forced_import(path, compressed).unwrap()),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -47,29 +47,29 @@ impl Vecs {
|
||||
) -> color_eyre::Result<()> {
|
||||
let starting_indexes = self.indexes.compute(indexer, starting_indexes, exit)?;
|
||||
|
||||
self.blocks
|
||||
.compute(indexer, &self.indexes, &starting_indexes, exit)?;
|
||||
// self.blocks
|
||||
// .compute(indexer, &self.indexes, &starting_indexes, exit)?;
|
||||
|
||||
self.mining
|
||||
.compute(indexer, &self.indexes, &starting_indexes, exit)?;
|
||||
// self.mining
|
||||
// .compute(indexer, &self.indexes, &starting_indexes, exit)?;
|
||||
|
||||
if let Some(marketprice) = self.marketprice.as_mut() {
|
||||
marketprice.compute(
|
||||
indexer,
|
||||
&self.indexes,
|
||||
&starting_indexes,
|
||||
fetcher.unwrap(),
|
||||
exit,
|
||||
)?;
|
||||
}
|
||||
// if let Some(marketprice) = self.marketprice.as_mut() {
|
||||
// marketprice.compute(
|
||||
// indexer,
|
||||
// &self.indexes,
|
||||
// &starting_indexes,
|
||||
// fetcher.unwrap(),
|
||||
// exit,
|
||||
// )?;
|
||||
// }
|
||||
|
||||
self.transactions.compute(
|
||||
indexer,
|
||||
&self.indexes,
|
||||
&starting_indexes,
|
||||
self.marketprice.as_ref(),
|
||||
exit,
|
||||
)?;
|
||||
// self.transactions.compute(
|
||||
// indexer,
|
||||
// &self.indexes,
|
||||
// &starting_indexes,
|
||||
// self.marketprice.as_ref(),
|
||||
// exit,
|
||||
// )?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -77,12 +77,12 @@ impl Vecs {
|
||||
pub fn as_any_vecs(&self) -> Vec<&dyn AnyStoredVec> {
|
||||
[
|
||||
self.indexes.as_any_vecs(),
|
||||
self.blocks.as_any_vecs(),
|
||||
self.mining.as_any_vecs(),
|
||||
self.transactions.as_any_vecs(),
|
||||
self.marketprice
|
||||
.as_ref()
|
||||
.map_or(vec![], |v| v.as_any_vecs()),
|
||||
// self.blocks.as_any_vecs(),
|
||||
// self.mining.as_any_vecs(),
|
||||
// self.transactions.as_any_vecs(),
|
||||
// self.marketprice
|
||||
// .as_ref()
|
||||
// .map_or(vec![], |v| v.as_any_vecs()),
|
||||
]
|
||||
.concat()
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
use std::{fs, path::Path};
|
||||
|
||||
use brk_core::{
|
||||
CheckedSub, Feerate, InputIndex, OutputIndex, Sats, StoredU32, StoredU64, StoredUsize, TxIndex,
|
||||
TxVersion, Weight,
|
||||
CheckedSub, Feerate, InputIndex, OutputIndex, Sats, StoredUsize, TxIndex, TxVersion, Weight,
|
||||
};
|
||||
use brk_exit::Exit;
|
||||
use brk_indexer::Indexer;
|
||||
@@ -24,34 +23,34 @@ pub struct Vecs {
|
||||
// pub txindex_to_is_v2: LazyVec<Txindex, bool>,
|
||||
// pub txindex_to_is_v3: LazyVec<Txindex, bool>,
|
||||
pub indexes_to_coinbase: ComputedValueVecsFromHeight,
|
||||
pub indexes_to_emptyoutput_count: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_emptyoutput_count: ComputedVecsFromHeight<StoredUsize>,
|
||||
pub indexes_to_fee: ComputedValueVecsFromTxindex,
|
||||
pub indexes_to_feerate: ComputedVecsFromTxindex<Feerate>,
|
||||
/// Value == 0 when Coinbase
|
||||
pub indexes_to_input_value: ComputedVecsFromTxindex<Sats>,
|
||||
pub indexes_to_opreturn_count: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_opreturn_count: ComputedVecsFromHeight<StoredUsize>,
|
||||
pub indexes_to_output_value: ComputedVecsFromTxindex<Sats>,
|
||||
pub indexes_to_p2a_count: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_p2ms_count: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_p2pk33_count: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_p2pk65_count: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_p2pkh_count: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_p2sh_count: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_p2tr_count: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_p2wpkh_count: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_p2wsh_count: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_p2a_count: ComputedVecsFromHeight<StoredUsize>,
|
||||
pub indexes_to_p2ms_count: ComputedVecsFromHeight<StoredUsize>,
|
||||
pub indexes_to_p2pk33_count: ComputedVecsFromHeight<StoredUsize>,
|
||||
pub indexes_to_p2pk65_count: ComputedVecsFromHeight<StoredUsize>,
|
||||
pub indexes_to_p2pkh_count: ComputedVecsFromHeight<StoredUsize>,
|
||||
pub indexes_to_p2sh_count: ComputedVecsFromHeight<StoredUsize>,
|
||||
pub indexes_to_p2tr_count: ComputedVecsFromHeight<StoredUsize>,
|
||||
pub indexes_to_p2wpkh_count: ComputedVecsFromHeight<StoredUsize>,
|
||||
pub indexes_to_p2wsh_count: ComputedVecsFromHeight<StoredUsize>,
|
||||
pub indexes_to_subsidy: ComputedValueVecsFromHeight,
|
||||
pub indexes_to_tx_count: ComputedVecsFromHeight<StoredU64>,
|
||||
pub indexes_to_tx_v1: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_tx_v2: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_tx_v3: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_tx_count: ComputedVecsFromHeight<StoredUsize>,
|
||||
pub indexes_to_tx_v1: ComputedVecsFromHeight<StoredUsize>,
|
||||
pub indexes_to_tx_v2: ComputedVecsFromHeight<StoredUsize>,
|
||||
pub indexes_to_tx_v3: ComputedVecsFromHeight<StoredUsize>,
|
||||
pub indexes_to_tx_vsize: ComputedVecsFromTxindex<StoredUsize>,
|
||||
pub indexes_to_tx_weight: ComputedVecsFromTxindex<Weight>,
|
||||
pub indexes_to_unknownoutput_count: ComputedVecsFromHeight<StoredU32>,
|
||||
pub indexes_to_unknownoutput_count: ComputedVecsFromHeight<StoredUsize>,
|
||||
pub inputindex_to_value: EagerVec<InputIndex, Sats>,
|
||||
pub txindex_to_input_count: ComputedVecsFromTxindex<StoredU64>,
|
||||
pub indexes_to_input_count: ComputedVecsFromTxindex<StoredUsize>,
|
||||
pub txindex_to_is_coinbase: EagerVec<TxIndex, bool>,
|
||||
pub txindex_to_output_count: ComputedVecsFromTxindex<StoredU64>,
|
||||
pub indexes_to_output_count: ComputedVecsFromTxindex<StoredUsize>,
|
||||
pub txindex_to_vsize: EagerVec<TxIndex, StoredUsize>,
|
||||
pub txindex_to_weight: EagerVec<TxIndex, Weight>,
|
||||
}
|
||||
@@ -84,7 +83,7 @@ impl Vecs {
|
||||
Version::ZERO,
|
||||
compressed,
|
||||
)?,
|
||||
txindex_to_input_count: ComputedVecsFromTxindex::forced_import(
|
||||
indexes_to_input_count: ComputedVecsFromTxindex::forced_import(
|
||||
path,
|
||||
"input_count",
|
||||
true,
|
||||
@@ -97,7 +96,7 @@ impl Vecs {
|
||||
.add_sum()
|
||||
.add_total(),
|
||||
)?,
|
||||
txindex_to_output_count: ComputedVecsFromTxindex::forced_import(
|
||||
indexes_to_output_count: ComputedVecsFromTxindex::forced_import(
|
||||
path,
|
||||
"output_count",
|
||||
true,
|
||||
@@ -428,7 +427,7 @@ impl Vecs {
|
||||
},
|
||||
)?;
|
||||
|
||||
self.txindex_to_input_count.compute_all(
|
||||
self.indexes_to_input_count.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
@@ -443,7 +442,7 @@ impl Vecs {
|
||||
},
|
||||
)?;
|
||||
|
||||
self.txindex_to_output_count.compute_all(
|
||||
self.indexes_to_output_count.compute_all(
|
||||
indexer,
|
||||
indexes,
|
||||
starting_indexes,
|
||||
@@ -459,7 +458,7 @@ impl Vecs {
|
||||
)?;
|
||||
|
||||
let compute_indexes_to_tx_vany =
|
||||
|indexes_to_tx_vany: &mut ComputedVecsFromHeight<StoredU32>, txversion| {
|
||||
|indexes_to_tx_vany: &mut ComputedVecsFromHeight<StoredUsize>, txversion| {
|
||||
let mut txindex_to_txversion_iter = indexer.vecs().txindex_to_txversion.iter();
|
||||
indexes_to_tx_vany.compute_all(
|
||||
indexer,
|
||||
@@ -550,11 +549,11 @@ impl Vecs {
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, indexer, indexes, starting_indexes, exit| {
|
||||
|vec, indexer, _, starting_indexes, exit| {
|
||||
vec.compute_sum_from_indexes(
|
||||
starting_indexes.txindex,
|
||||
indexer.vecs().txindex_to_first_outputindex.vec(),
|
||||
indexes.txindex_to_last_outputindex.vec(),
|
||||
self.indexes_to_output_count.txindex.as_ref().unwrap().vec(),
|
||||
indexer.vecs().outputindex_to_value.vec(),
|
||||
exit,
|
||||
)
|
||||
@@ -566,11 +565,11 @@ impl Vecs {
|
||||
indexes,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, indexer, indexes, starting_indexes, exit| {
|
||||
|vec, indexer, _, starting_indexes, exit| {
|
||||
vec.compute_sum_from_indexes(
|
||||
starting_indexes.txindex,
|
||||
indexer.vecs().txindex_to_first_inputindex.vec(),
|
||||
indexes.txindex_to_last_inputindex.vec(),
|
||||
self.indexes_to_input_count.txindex.as_ref().unwrap().vec(),
|
||||
self.inputindex_to_value.vec(),
|
||||
exit,
|
||||
)
|
||||
@@ -648,11 +647,15 @@ impl Vecs {
|
||||
marketprices,
|
||||
starting_indexes,
|
||||
exit,
|
||||
|vec, indexer, indexes, starting_indexes, exit| {
|
||||
|vec, indexer, _, starting_indexes, exit| {
|
||||
let mut txindex_to_first_outputindex_iter =
|
||||
indexer.vecs().txindex_to_first_outputindex.iter();
|
||||
let mut txindex_to_last_outputindex_iter =
|
||||
indexes.txindex_to_last_outputindex.iter();
|
||||
let mut txindex_to_output_count_iter = self
|
||||
.indexes_to_output_count
|
||||
.txindex
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.iter();
|
||||
let mut outputindex_to_value_iter = indexer.vecs().outputindex_to_value.iter();
|
||||
vec.compute_transform(
|
||||
starting_indexes.height,
|
||||
@@ -661,14 +664,14 @@ impl Vecs {
|
||||
let first_outputindex = txindex_to_first_outputindex_iter
|
||||
.unwrap_get_inner(txindex)
|
||||
.unwrap_to_usize();
|
||||
let last_outputindex = txindex_to_last_outputindex_iter
|
||||
.unwrap_get_inner(txindex)
|
||||
.unwrap_to_usize();
|
||||
let output_count = txindex_to_output_count_iter.unwrap_get_inner(txindex);
|
||||
let mut sats = Sats::ZERO;
|
||||
(first_outputindex..=last_outputindex).for_each(|outputindex| {
|
||||
sats += outputindex_to_value_iter
|
||||
.unwrap_get_inner(OutputIndex::from(outputindex));
|
||||
});
|
||||
(first_outputindex..first_outputindex + *output_count).for_each(
|
||||
|outputindex| {
|
||||
sats += outputindex_to_value_iter
|
||||
.unwrap_get_inner(OutputIndex::from(outputindex));
|
||||
},
|
||||
);
|
||||
(height, sats)
|
||||
},
|
||||
exit,
|
||||
@@ -889,8 +892,8 @@ impl Vecs {
|
||||
self.indexes_to_tx_v3.any_vecs(),
|
||||
self.indexes_to_tx_vsize.any_vecs(),
|
||||
self.indexes_to_tx_weight.any_vecs(),
|
||||
self.txindex_to_input_count.any_vecs(),
|
||||
self.txindex_to_output_count.any_vecs(),
|
||||
self.indexes_to_input_count.any_vecs(),
|
||||
self.indexes_to_output_count.any_vecs(),
|
||||
self.indexes_to_p2a_count.any_vecs(),
|
||||
self.indexes_to_p2ms_count.any_vecs(),
|
||||
self.indexes_to_p2pk33_count.any_vecs(),
|
||||
|
||||
@@ -6,12 +6,13 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use brk_core::{Bitcoin, CheckedSub, Close, Dollars, Height, Sats, TxIndex};
|
||||
use brk_core::{Bitcoin, CheckedSub, Close, Dollars, Height, Sats, StoredUsize, TxIndex};
|
||||
use brk_exit::Exit;
|
||||
use brk_vec::{
|
||||
Compressed, DynamicVec, Error, GenericVec, Result, StoredIndex, StoredType, StoredVec,
|
||||
StoredVecIterator, Value, Version,
|
||||
};
|
||||
use color_eyre::eyre::ContextCompat;
|
||||
use log::info;
|
||||
|
||||
const ONE_KIB: usize = 1024;
|
||||
@@ -228,7 +229,7 @@ where
|
||||
&mut self,
|
||||
max_from: T,
|
||||
first_indexes: &StoredVec<T, I>,
|
||||
last_indexes: &StoredVec<T, I>,
|
||||
indexes_count: &StoredVec<T, StoredUsize>,
|
||||
exit: &Exit,
|
||||
) -> Result<()>
|
||||
where
|
||||
@@ -236,18 +237,18 @@ where
|
||||
T: StoredIndex,
|
||||
{
|
||||
self.validate_computed_version_or_reset_file(
|
||||
Version::ZERO + self.version() + first_indexes.version() + last_indexes.version(),
|
||||
Version::ZERO + self.version() + first_indexes.version() + indexes_count.version(),
|
||||
)?;
|
||||
|
||||
let mut last_indexes_iter = last_indexes.iter();
|
||||
let mut indexes_count_iter = indexes_count.iter();
|
||||
|
||||
let index = max_from.min(T::from(self.len()));
|
||||
first_indexes
|
||||
.iter_at(index)
|
||||
.try_for_each(|(value, first_index)| {
|
||||
let first_index = (first_index).to_usize()?;
|
||||
let last_index = last_indexes_iter.unwrap_get_inner(value).unwrap_to_usize();
|
||||
(first_index..=last_index)
|
||||
let count = *indexes_count_iter.unwrap_get_inner(value);
|
||||
(first_index..first_index + count)
|
||||
.try_for_each(|index| self.forced_push_at(I::from(index), value, exit))
|
||||
})?;
|
||||
|
||||
@@ -275,7 +276,13 @@ where
|
||||
.iter_at(index)
|
||||
.try_for_each(|(index, v)| -> Result<()> {
|
||||
if let Some(prev_index) = prev_index.take() {
|
||||
let value = v.checked_sub(one).unwrap();
|
||||
let value = v
|
||||
.checked_sub(one)
|
||||
.context("Should work")
|
||||
.inspect_err(|_| {
|
||||
dbg!(index, prev_index, v);
|
||||
})
|
||||
.unwrap();
|
||||
self.forced_push_at(prev_index, value, exit)?;
|
||||
}
|
||||
prev_index.replace(index);
|
||||
@@ -431,7 +438,7 @@ where
|
||||
&mut self,
|
||||
max_from: I,
|
||||
first_indexes: &StoredVec<I, T2>,
|
||||
last_indexes: &StoredVec<I, T2>,
|
||||
indexes_count: &StoredVec<I, StoredUsize>,
|
||||
source: &StoredVec<T2, T>,
|
||||
exit: &Exit,
|
||||
) -> Result<()>
|
||||
@@ -440,17 +447,18 @@ where
|
||||
T2: StoredIndex + StoredType,
|
||||
{
|
||||
self.validate_computed_version_or_reset_file(
|
||||
Version::ZERO + self.version() + first_indexes.version() + last_indexes.version(),
|
||||
Version::ZERO + self.version() + first_indexes.version() + indexes_count.version(),
|
||||
)?;
|
||||
|
||||
let mut last_indexes_iter = last_indexes.iter();
|
||||
let mut indexes_count_iter = indexes_count.iter();
|
||||
let mut source_iter = source.iter();
|
||||
let index = max_from.min(I::from(self.len()));
|
||||
first_indexes
|
||||
.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();
|
||||
let count = *indexes_count_iter.get(i).unwrap().1.into_inner();
|
||||
let first_index = first_index.unwrap_to_usize();
|
||||
let range = first_index..first_index + count;
|
||||
let mut sum = T::from(0_usize);
|
||||
range.into_iter().for_each(|i| {
|
||||
sum = sum.clone() + source_iter.get(T2::from(i)).unwrap().1.into_inner();
|
||||
|
||||
Reference in New Issue
Block a user