mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-06-08 06:01:57 -07:00
global: replace Value enum with Cow
This commit is contained in:
@@ -66,7 +66,12 @@ impl Computer {
|
||||
exit: &Exit,
|
||||
) -> color_eyre::Result<()> {
|
||||
info!("Computing...");
|
||||
self.vecs
|
||||
.compute(indexer, starting_indexes, self.fetcher.as_mut(), exit)
|
||||
self.vecs.compute(
|
||||
indexer,
|
||||
starting_indexes,
|
||||
self.fetcher.as_mut(),
|
||||
exit,
|
||||
&mut self.stores,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ where
|
||||
cumulative_vec.iter().unwrap_get_inner(index)
|
||||
});
|
||||
source.iter_at(index).try_for_each(|(i, v)| -> Result<()> {
|
||||
cumulative = cumulative.clone() + v.into_inner();
|
||||
cumulative = cumulative.clone() + v.into_owned();
|
||||
cumulative_vec.forced_push_at(i, cumulative.clone(), exit)
|
||||
})?;
|
||||
|
||||
@@ -261,7 +261,7 @@ where
|
||||
first_indexes
|
||||
.iter_at(index)
|
||||
.try_for_each(|(i, first_index)| -> Result<()> {
|
||||
let first_index = first_index.into_inner();
|
||||
let first_index = first_index.into_owned();
|
||||
|
||||
let count_index = count_indexes_iter.unwrap_get_inner(i);
|
||||
|
||||
@@ -284,7 +284,7 @@ where
|
||||
// dbg!(first_index, count_index, last_index);
|
||||
// })
|
||||
// .unwrap()
|
||||
// .into_inner();
|
||||
// .into_owned();
|
||||
last.forced_push_at(index, v, exit)?;
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ where
|
||||
source_iter.set(first_index);
|
||||
let mut values = (&mut source_iter)
|
||||
.take(*count_index)
|
||||
.map(|(_, v)| v.into_inner())
|
||||
.map(|(_, v)| v.into_owned())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if needs_sorted {
|
||||
@@ -435,7 +435,7 @@ where
|
||||
first_indexes
|
||||
.iter_at(index)
|
||||
.try_for_each(|(i, first_index, ..)| -> Result<()> {
|
||||
let first_index = first_index.into_inner();
|
||||
let first_index = first_index.into_owned();
|
||||
|
||||
let count_index = count_indexes_iter.unwrap_get_inner(i);
|
||||
|
||||
@@ -473,7 +473,7 @@ where
|
||||
source_max_iter.set(first_index);
|
||||
let mut values = source_max_iter
|
||||
.take(*count_index)
|
||||
.map(|(_, v)| v.into_inner())
|
||||
.map(|(_, v)| v.into_owned())
|
||||
.collect::<Vec<_>>();
|
||||
values.sort_unstable();
|
||||
max.forced_push_at(i, values.last().unwrap().clone(), exit)?;
|
||||
@@ -484,7 +484,7 @@ where
|
||||
source_min_iter.set(first_index);
|
||||
let mut values = source_min_iter
|
||||
.take(*count_index)
|
||||
.map(|(_, v)| v.into_inner())
|
||||
.map(|(_, v)| v.into_owned())
|
||||
.collect::<Vec<_>>();
|
||||
values.sort_unstable();
|
||||
min.forced_push_at(i, values.first().unwrap().clone(), exit)?;
|
||||
@@ -497,7 +497,7 @@ where
|
||||
source_average_iter.set(first_index);
|
||||
let values = source_average_iter
|
||||
.take(*count_index)
|
||||
.map(|(_, v)| v.into_inner())
|
||||
.map(|(_, v)| v.into_owned())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let len = values.len();
|
||||
@@ -513,7 +513,7 @@ where
|
||||
source_sum_iter.set(first_index);
|
||||
let values = source_sum_iter
|
||||
.take(*count_index)
|
||||
.map(|(_, v)| v.into_inner())
|
||||
.map(|(_, v)| v.into_owned())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let sum = values.into_iter().fold(T::from(0), |a, b| a + b);
|
||||
|
||||
@@ -677,7 +677,7 @@ impl ComputedRatioVecsFromDateIndex {
|
||||
.unwrap()
|
||||
.forced_push_at(index, nan, exit)?;
|
||||
} else {
|
||||
let ratio = ratio.into_inner();
|
||||
let ratio = ratio.into_owned();
|
||||
let pos = sorted.binary_search(&ratio).unwrap_or_else(|pos| pos);
|
||||
sorted.insert(pos, ratio);
|
||||
self.ratio_p0_1.dateindex.as_mut().unwrap().forced_push_at(
|
||||
|
||||
@@ -69,7 +69,7 @@ impl ComputedValueVecsFromTxindex {
|
||||
source.map_or_else(|| sats.txindex.as_ref().unwrap().boxed_clone(), |s| s),
|
||||
|txindex: TxIndex, iter| {
|
||||
iter.next_at(txindex.unwrap_to_usize()).map(|(_, value)| {
|
||||
let sats = value.into_inner();
|
||||
let sats = value.into_owned();
|
||||
Bitcoin::from(sats)
|
||||
})
|
||||
},
|
||||
@@ -100,14 +100,14 @@ impl ComputedValueVecsFromTxindex {
|
||||
height_to_close_iter| {
|
||||
let txindex = txindex.unwrap_to_usize();
|
||||
txindex_to_btc_iter.next_at(txindex).and_then(|(_, value)| {
|
||||
let btc = value.into_inner();
|
||||
let btc = value.into_owned();
|
||||
txindex_to_height_iter
|
||||
.next_at(txindex)
|
||||
.and_then(|(_, value)| {
|
||||
let height = value.into_inner();
|
||||
let height = value.into_owned();
|
||||
height_to_close_iter
|
||||
.next_at(height.unwrap_to_usize())
|
||||
.map(|(_, close)| *close.into_inner() * btc)
|
||||
.map(|(_, close)| *close.into_owned() * btc)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
@@ -144,10 +144,10 @@ impl Vecs {
|
||||
txindex_to_first_inputindex_iter
|
||||
.next_at(txindex)
|
||||
.map(|(_, start)| {
|
||||
let start = usize::from(start.into_inner());
|
||||
let start = usize::from(start.into_owned());
|
||||
let end = txindex_to_first_inputindex_iter
|
||||
.next_at(txindex + 1)
|
||||
.map(|(_, v)| usize::from(v.into_inner()))
|
||||
.map(|(_, v)| usize::from(v.into_owned()))
|
||||
.unwrap_or_else(|| inputindex_to_outputindex_iter.len());
|
||||
StoredUsize::from((start..end).count())
|
||||
})
|
||||
@@ -167,10 +167,10 @@ impl Vecs {
|
||||
txindex_to_first_outputindex_iter
|
||||
.next_at(txindex)
|
||||
.map(|(_, start)| {
|
||||
let start = usize::from(start.into_inner());
|
||||
let start = usize::from(start.into_owned());
|
||||
let end = txindex_to_first_outputindex_iter
|
||||
.next_at(txindex + 1)
|
||||
.map(|(_, v)| usize::from(v.into_inner()))
|
||||
.map(|(_, v)| usize::from(v.into_owned()))
|
||||
.unwrap_or_else(|| outputindex_to_value_iter.len());
|
||||
StoredUsize::from((start..end).count())
|
||||
})
|
||||
|
||||
@@ -20,6 +20,8 @@ pub mod transactions;
|
||||
pub use indexes::Indexes;
|
||||
use log::info;
|
||||
|
||||
use crate::stores::Stores;
|
||||
|
||||
const VERSION: Version = Version::ONE;
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -121,6 +123,7 @@ impl Vecs {
|
||||
starting_indexes: brk_indexer::Indexes,
|
||||
fetcher: Option<&mut Fetcher>,
|
||||
exit: &Exit,
|
||||
stores: &mut Stores,
|
||||
) -> color_eyre::Result<()> {
|
||||
info!("Computing indexes...");
|
||||
let mut starting_indexes = self.indexes.compute(indexer, starting_indexes, exit)?;
|
||||
@@ -178,6 +181,7 @@ impl Vecs {
|
||||
&self.market,
|
||||
&mut starting_indexes,
|
||||
exit,
|
||||
stores,
|
||||
)?;
|
||||
|
||||
self.cointime.compute(
|
||||
|
||||
@@ -15,7 +15,10 @@ use rayon::prelude::*;
|
||||
|
||||
use brk_state::{BlockState, CohortStateTrait, SupplyState, Transacted};
|
||||
|
||||
use crate::vecs::{market, stateful::r#trait::CohortVecs};
|
||||
use crate::{
|
||||
stores::Stores,
|
||||
vecs::{market, stateful::r#trait::CohortVecs},
|
||||
};
|
||||
|
||||
use super::{
|
||||
Indexes, fetched,
|
||||
@@ -185,6 +188,7 @@ impl Vecs {
|
||||
// Must take ownership as its indexes will be updated for this specific function
|
||||
starting_indexes: &mut Indexes,
|
||||
exit: &Exit,
|
||||
stores: &mut Stores,
|
||||
) -> color_eyre::Result<()> {
|
||||
let height_to_first_outputindex = &indexer.vecs.height_to_first_outputindex;
|
||||
let height_to_first_inputindex = &indexer.vecs.height_to_first_inputindex;
|
||||
@@ -389,19 +393,19 @@ impl Vecs {
|
||||
.get_or_read(inputindex, &inputindex_to_outputindex_mmap)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.into_inner();
|
||||
.into_owned();
|
||||
|
||||
let value = outputindex_to_value
|
||||
.get_or_read(outputindex, &outputindex_to_value_mmap)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.into_inner();
|
||||
.into_owned();
|
||||
|
||||
let input_type = outputindex_to_outputtype
|
||||
.get_or_read(outputindex, &outputindex_to_outputtype_mmap)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.into_inner();
|
||||
.into_owned();
|
||||
|
||||
// dbg!(input_type);
|
||||
|
||||
@@ -413,13 +417,13 @@ impl Vecs {
|
||||
.get_or_read(outputindex, &outputindex_to_txindex_mmap)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.into_inner();
|
||||
.into_owned();
|
||||
|
||||
let height = txindex_to_height
|
||||
.get_or_read(input_txindex, &txindex_to_height_mmap)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.into_inner();
|
||||
.into_owned();
|
||||
|
||||
(height, value, input_type)
|
||||
})
|
||||
@@ -452,13 +456,13 @@ impl Vecs {
|
||||
.get_or_read(outputindex, &outputindex_to_value_mmap)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.into_inner();
|
||||
.into_owned();
|
||||
|
||||
let output_type = outputindex_to_outputtype
|
||||
.get_or_read(outputindex, &outputindex_to_outputtype_mmap)
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.into_inner();
|
||||
.into_owned();
|
||||
|
||||
(value, output_type)
|
||||
})
|
||||
|
||||
@@ -110,13 +110,13 @@ impl Vecs {
|
||||
inputindex_to_outputindex_iter
|
||||
.next_at(index.unwrap_to_usize())
|
||||
.map(|(inputindex, outputindex)| {
|
||||
let outputindex = outputindex.into_inner();
|
||||
let outputindex = outputindex.into_owned();
|
||||
if outputindex == OutputIndex::COINBASE {
|
||||
Sats::ZERO
|
||||
} else if let Some((_, value)) =
|
||||
outputindex_to_value_iter.next_at(outputindex.unwrap_to_usize())
|
||||
{
|
||||
value.into_inner()
|
||||
value.into_owned()
|
||||
} else {
|
||||
dbg!(inputindex, outputindex);
|
||||
panic!()
|
||||
@@ -138,12 +138,12 @@ impl Vecs {
|
||||
txindex_to_base_size_iter
|
||||
.next_at(index)
|
||||
.map(|(_, base_size)| {
|
||||
let base_size = base_size.into_inner();
|
||||
let base_size = base_size.into_owned();
|
||||
let total_size = txindex_to_total_size_iter
|
||||
.next_at(index)
|
||||
.unwrap()
|
||||
.1
|
||||
.into_inner();
|
||||
.into_owned();
|
||||
|
||||
// This is the exact definition of a weight unit, as defined by BIP-141 (quote above).
|
||||
let wu = usize::from(base_size) * 3 + usize::from(total_size);
|
||||
@@ -164,7 +164,7 @@ impl Vecs {
|
||||
let index = index.unwrap_to_usize();
|
||||
iter.next_at(index).map(|(_, weight)| {
|
||||
StoredUsize::from(
|
||||
bitcoin::Weight::from(weight.into_inner()).to_vbytes_ceil() as usize
|
||||
bitcoin::Weight::from(weight.into_owned()).to_vbytes_ceil() as usize
|
||||
)
|
||||
})
|
||||
},
|
||||
@@ -182,12 +182,12 @@ impl Vecs {
|
||||
txindex_to_height_iter
|
||||
.next_at(index.unwrap_to_usize())
|
||||
.map(|(_, height)| {
|
||||
let height = height.into_inner();
|
||||
let height = height.into_owned();
|
||||
let txindex = height_to_first_txindex_iter
|
||||
.next_at(height.unwrap_to_usize())
|
||||
.unwrap()
|
||||
.1
|
||||
.into_inner();
|
||||
.into_owned();
|
||||
|
||||
index == txindex
|
||||
})
|
||||
@@ -211,12 +211,12 @@ impl Vecs {
|
||||
txindex_to_first_inputindex_iter
|
||||
.next_at(txindex)
|
||||
.map(|(_, first_index)| {
|
||||
let first_index = usize::from(first_index.into_inner());
|
||||
let first_index = usize::from(first_index.into_owned());
|
||||
let count = *txindex_to_input_count_iter
|
||||
.next_at(txindex)
|
||||
.unwrap()
|
||||
.1
|
||||
.into_inner();
|
||||
.into_owned();
|
||||
let range = first_index..first_index + count;
|
||||
range.into_iter().fold(Sats::ZERO, |total, inputindex| {
|
||||
total
|
||||
@@ -224,7 +224,7 @@ impl Vecs {
|
||||
.next_at(inputindex)
|
||||
.unwrap()
|
||||
.1
|
||||
.into_inner()
|
||||
.into_owned()
|
||||
})
|
||||
})
|
||||
},
|
||||
@@ -260,12 +260,12 @@ impl Vecs {
|
||||
txindex_to_first_outputindex_iter
|
||||
.next_at(txindex)
|
||||
.map(|(_, first_index)| {
|
||||
let first_index = usize::from(first_index.into_inner());
|
||||
let first_index = usize::from(first_index.into_owned());
|
||||
let count = *txindex_to_output_count_iter
|
||||
.next_at(txindex)
|
||||
.unwrap()
|
||||
.1
|
||||
.into_inner();
|
||||
.into_owned();
|
||||
let range = first_index..first_index + count;
|
||||
range.into_iter().fold(Sats::ZERO, |total, outputindex| {
|
||||
total
|
||||
@@ -273,7 +273,7 @@ impl Vecs {
|
||||
.next_at(outputindex)
|
||||
.unwrap()
|
||||
.1
|
||||
.into_inner()
|
||||
.into_owned()
|
||||
})
|
||||
})
|
||||
},
|
||||
@@ -303,12 +303,12 @@ impl Vecs {
|
||||
|txindex: TxIndex, input_iter, output_iter| {
|
||||
let txindex = txindex.unwrap_to_usize();
|
||||
input_iter.next_at(txindex).and_then(|(_, value)| {
|
||||
let input = value.into_inner();
|
||||
let input = value.into_owned();
|
||||
if input.is_zero() {
|
||||
return Some(Sats::ZERO);
|
||||
}
|
||||
output_iter.next_at(txindex).map(|(_, value)| {
|
||||
let output = value.into_inner();
|
||||
let output = value.into_owned();
|
||||
input.checked_sub(output).unwrap()
|
||||
})
|
||||
})
|
||||
@@ -326,9 +326,9 @@ impl Vecs {
|
||||
|txindex: TxIndex, fee_iter, vsize_iter| {
|
||||
let txindex = txindex.unwrap_to_usize();
|
||||
fee_iter.next_at(txindex).and_then(|(_, value)| {
|
||||
let fee = value.into_inner();
|
||||
let fee = value.into_owned();
|
||||
vsize_iter.next_at(txindex).map(|(_, value)| {
|
||||
let vsize = value.into_inner();
|
||||
let vsize = value.into_owned();
|
||||
Feerate::from((fee, vsize))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
mod error;
|
||||
mod value;
|
||||
|
||||
pub use error::*;
|
||||
pub use value::*;
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
use std::{fmt::Debug, ops::Deref};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Value<'a, T> {
|
||||
Ref(&'a T),
|
||||
Owned(T),
|
||||
}
|
||||
|
||||
impl<T> Value<'_, T>
|
||||
where
|
||||
T: Sized + Debug + Clone,
|
||||
{
|
||||
pub fn into_inner(self) -> T {
|
||||
match self {
|
||||
Self::Ref(t) => t.to_owned(),
|
||||
Self::Owned(t) => t,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<T> Deref for Value<'_, T> {
|
||||
type Target = T;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
match self {
|
||||
Self::Ref(t) => t,
|
||||
Self::Owned(t) => t,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<T> AsRef<T> for Value<'_, T>
|
||||
where
|
||||
T: Sized + Debug + Clone,
|
||||
{
|
||||
fn as_ref(&self) -> &T {
|
||||
match self {
|
||||
Self::Ref(t) => t,
|
||||
Self::Owned(t) => t,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -242,7 +242,7 @@ impl Indexer {
|
||||
.context("Expect outputindex to not be none")
|
||||
.inspect_err(|_| {
|
||||
dbg!(outpoint.txid, prev_txindex, vout);
|
||||
})?.into_inner()
|
||||
})?.into_owned()
|
||||
+ vout;
|
||||
|
||||
Ok((inputindex, InputSource::PreviousBlock((
|
||||
@@ -326,35 +326,35 @@ impl Indexer {
|
||||
OutputType::P2PK65 => vecs
|
||||
.p2pk65addressindex_to_p2pk65bytes
|
||||
.get_or_read(typeindex.into(), &p2pk65addressindex_to_p2pk65bytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_inner())),
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2PK33 => vecs
|
||||
.p2pk33addressindex_to_p2pk33bytes
|
||||
.get_or_read(typeindex.into(), &p2pk33addressindex_to_p2pk33bytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_inner())),
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2PKH => vecs
|
||||
.p2pkhaddressindex_to_p2pkhbytes
|
||||
.get_or_read(typeindex.into(), &p2pkhaddressindex_to_p2pkhbytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_inner())),
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2SH => vecs
|
||||
.p2shaddressindex_to_p2shbytes
|
||||
.get_or_read(typeindex.into(), &p2shaddressindex_to_p2shbytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_inner())),
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2WPKH => vecs
|
||||
.p2wpkhaddressindex_to_p2wpkhbytes
|
||||
.get_or_read(typeindex.into(), &p2wpkhaddressindex_to_p2wpkhbytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_inner())),
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2WSH => vecs
|
||||
.p2wshaddressindex_to_p2wshbytes
|
||||
.get_or_read(typeindex.into(), &p2wshaddressindex_to_p2wshbytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_inner())),
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2TR => vecs
|
||||
.p2traddressindex_to_p2trbytes
|
||||
.get_or_read(typeindex.into(), &p2traddressindex_to_p2trbytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_inner())),
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::P2A => vecs
|
||||
.p2aaddressindex_to_p2abytes
|
||||
.get_or_read(typeindex.into(), &p2aaddressindex_to_p2abytes_mmap)?
|
||||
.map(|v| AddressBytes::from(v.into_inner())),
|
||||
.map(|v| AddressBytes::from(v.into_owned())),
|
||||
OutputType::Empty | OutputType::OpReturn | OutputType::P2MS | OutputType::Unknown => {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use std::{fs, path::Path, thread};
|
||||
use std::{borrow::Cow, fs, path::Path, thread};
|
||||
|
||||
use brk_core::{
|
||||
AddressBytes, AddressBytesHash, BlockHashPrefix, Height, OutputType, Result, TxIndex,
|
||||
TxidPrefix, TypeIndex, Value, Version,
|
||||
TxidPrefix, TypeIndex, Version,
|
||||
};
|
||||
use brk_store::{AnyStore, Store};
|
||||
use brk_vec::AnyIterableVec;
|
||||
@@ -89,7 +89,7 @@ impl Stores {
|
||||
vecs.height_to_blockhash
|
||||
.iter_at(starting_indexes.height)
|
||||
.for_each(|(_, v)| {
|
||||
let blockhashprefix = BlockHashPrefix::from(Value::into_inner(v));
|
||||
let blockhashprefix = BlockHashPrefix::from(v.into_owned());
|
||||
self.blockhashprefix_to_height.remove(blockhashprefix);
|
||||
});
|
||||
|
||||
@@ -97,14 +97,14 @@ impl Stores {
|
||||
.height_to_first_p2pk65addressindex
|
||||
.iter()
|
||||
.get(starting_indexes.height)
|
||||
.map(Value::into_inner)
|
||||
.map(Cow::into_owned)
|
||||
{
|
||||
let mut p2pk65addressindex_to_p2pk65bytes_iter =
|
||||
vecs.p2pk65addressindex_to_p2pk65bytes.iter();
|
||||
|
||||
while let Some(typedbytes) = p2pk65addressindex_to_p2pk65bytes_iter
|
||||
.get(index)
|
||||
.map(Value::into_inner)
|
||||
.map(Cow::into_owned)
|
||||
{
|
||||
let bytes = AddressBytes::from(typedbytes);
|
||||
let hash = AddressBytesHash::from((&bytes, OutputType::P2PK65));
|
||||
@@ -117,14 +117,14 @@ impl Stores {
|
||||
.height_to_first_p2pk33addressindex
|
||||
.iter()
|
||||
.get(starting_indexes.height)
|
||||
.map(Value::into_inner)
|
||||
.map(Cow::into_owned)
|
||||
{
|
||||
let mut p2pk33addressindex_to_p2pk33bytes_iter =
|
||||
vecs.p2pk33addressindex_to_p2pk33bytes.iter();
|
||||
|
||||
while let Some(typedbytes) = p2pk33addressindex_to_p2pk33bytes_iter
|
||||
.get(index)
|
||||
.map(Value::into_inner)
|
||||
.map(Cow::into_owned)
|
||||
{
|
||||
let bytes = AddressBytes::from(typedbytes);
|
||||
let hash = AddressBytesHash::from((&bytes, OutputType::P2PK33));
|
||||
@@ -137,14 +137,14 @@ impl Stores {
|
||||
.height_to_first_p2pkhaddressindex
|
||||
.iter()
|
||||
.get(starting_indexes.height)
|
||||
.map(Value::into_inner)
|
||||
.map(Cow::into_owned)
|
||||
{
|
||||
let mut p2pkhaddressindex_to_p2pkhbytes_iter =
|
||||
vecs.p2pkhaddressindex_to_p2pkhbytes.iter();
|
||||
|
||||
while let Some(typedbytes) = p2pkhaddressindex_to_p2pkhbytes_iter
|
||||
.get(index)
|
||||
.map(Value::into_inner)
|
||||
.map(Cow::into_owned)
|
||||
{
|
||||
let bytes = AddressBytes::from(typedbytes);
|
||||
let hash = AddressBytesHash::from((&bytes, OutputType::P2PKH));
|
||||
@@ -157,14 +157,14 @@ impl Stores {
|
||||
.height_to_first_p2shaddressindex
|
||||
.iter()
|
||||
.get(starting_indexes.height)
|
||||
.map(Value::into_inner)
|
||||
.map(Cow::into_owned)
|
||||
{
|
||||
let mut p2shaddressindex_to_p2shbytes_iter =
|
||||
vecs.p2shaddressindex_to_p2shbytes.iter();
|
||||
|
||||
while let Some(typedbytes) = p2shaddressindex_to_p2shbytes_iter
|
||||
.get(index)
|
||||
.map(Value::into_inner)
|
||||
.map(Cow::into_owned)
|
||||
{
|
||||
let bytes = AddressBytes::from(typedbytes);
|
||||
let hash = AddressBytesHash::from((&bytes, OutputType::P2SH));
|
||||
@@ -177,14 +177,14 @@ impl Stores {
|
||||
.height_to_first_p2traddressindex
|
||||
.iter()
|
||||
.get(starting_indexes.height)
|
||||
.map(Value::into_inner)
|
||||
.map(Cow::into_owned)
|
||||
{
|
||||
let mut p2traddressindex_to_p2trbytes_iter =
|
||||
vecs.p2traddressindex_to_p2trbytes.iter();
|
||||
|
||||
while let Some(typedbytes) = p2traddressindex_to_p2trbytes_iter
|
||||
.get(index)
|
||||
.map(Value::into_inner)
|
||||
.map(Cow::into_owned)
|
||||
{
|
||||
let bytes = AddressBytes::from(typedbytes);
|
||||
let hash = AddressBytesHash::from((&bytes, OutputType::P2TR));
|
||||
@@ -197,14 +197,14 @@ impl Stores {
|
||||
.height_to_first_p2wpkhaddressindex
|
||||
.iter()
|
||||
.get(starting_indexes.height)
|
||||
.map(Value::into_inner)
|
||||
.map(Cow::into_owned)
|
||||
{
|
||||
let mut p2wpkhaddressindex_to_p2wpkhbytes_iter =
|
||||
vecs.p2wpkhaddressindex_to_p2wpkhbytes.iter();
|
||||
|
||||
while let Some(typedbytes) = p2wpkhaddressindex_to_p2wpkhbytes_iter
|
||||
.get(index)
|
||||
.map(Value::into_inner)
|
||||
.map(Cow::into_owned)
|
||||
{
|
||||
let bytes = AddressBytes::from(typedbytes);
|
||||
let hash = AddressBytesHash::from((&bytes, OutputType::P2WPKH));
|
||||
@@ -217,14 +217,14 @@ impl Stores {
|
||||
.height_to_first_p2wshaddressindex
|
||||
.iter()
|
||||
.get(starting_indexes.height)
|
||||
.map(Value::into_inner)
|
||||
.map(Cow::into_owned)
|
||||
{
|
||||
let mut p2wshaddressindex_to_p2wshbytes_iter =
|
||||
vecs.p2wshaddressindex_to_p2wshbytes.iter();
|
||||
|
||||
while let Some(typedbytes) = p2wshaddressindex_to_p2wshbytes_iter
|
||||
.get(index)
|
||||
.map(Value::into_inner)
|
||||
.map(Cow::into_owned)
|
||||
{
|
||||
let bytes = AddressBytes::from(typedbytes);
|
||||
let hash = AddressBytesHash::from((&bytes, OutputType::P2WSH));
|
||||
@@ -237,13 +237,13 @@ impl Stores {
|
||||
.height_to_first_p2aaddressindex
|
||||
.iter()
|
||||
.get(starting_indexes.height)
|
||||
.map(Value::into_inner)
|
||||
.map(Cow::into_owned)
|
||||
{
|
||||
let mut p2aaddressindex_to_p2abytes_iter = vecs.p2aaddressindex_to_p2abytes.iter();
|
||||
|
||||
while let Some(typedbytes) = p2aaddressindex_to_p2abytes_iter
|
||||
.get(index)
|
||||
.map(Value::into_inner)
|
||||
.map(Cow::into_owned)
|
||||
{
|
||||
let bytes = AddressBytes::from(typedbytes);
|
||||
let hash = AddressBytesHash::from((&bytes, OutputType::P2A));
|
||||
@@ -260,7 +260,7 @@ impl Stores {
|
||||
vecs.txindex_to_txid
|
||||
.iter_at(starting_indexes.txindex)
|
||||
.for_each(|(txindex, txid)| {
|
||||
let txidprefix = TxidPrefix::from(&txid.into_inner());
|
||||
let txidprefix = TxidPrefix::from(&txid.into_owned());
|
||||
|
||||
// "d5d27987d2a3dfc724e359870c6644b40e497bdc0589a033220fe15429d88599"
|
||||
let is_not_first_dup = txindex != TxIndex::new(142783)
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
#![doc = "```"]
|
||||
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
fmt::Debug,
|
||||
mem,
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use brk_core::{Height, Result, Value, Version};
|
||||
use brk_core::{Height, Result, Version};
|
||||
use byteview::ByteView;
|
||||
use fjall::{
|
||||
PartitionCreateOptions, PersistMode, ReadTransaction, TransactionalKeyspace,
|
||||
@@ -25,7 +26,7 @@ pub use r#trait::*;
|
||||
|
||||
pub struct Store<Key, Value> {
|
||||
meta: StoreMeta,
|
||||
name: String,
|
||||
name: &'static str,
|
||||
keyspace: TransactionalKeyspace,
|
||||
partition: Option<TransactionalPartitionHandle>,
|
||||
rtx: ReadTransaction,
|
||||
@@ -74,7 +75,7 @@ where
|
||||
|
||||
Ok(Self {
|
||||
meta,
|
||||
name: name.to_owned(),
|
||||
name: Box::leak(Box::new(name.to_string())),
|
||||
keyspace: keyspace.clone(),
|
||||
partition: Some(partition),
|
||||
rtx,
|
||||
@@ -84,14 +85,14 @@ where
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get(&self, key: &'a K) -> Result<Option<Value<V>>> {
|
||||
pub fn get(&self, key: &'a K) -> Result<Option<Cow<V>>> {
|
||||
if let Some(v) = self.puts.get(key) {
|
||||
Ok(Some(Value::Ref(v)))
|
||||
Ok(Some(Cow::Borrowed(v)))
|
||||
} else if let Some(slice) = self
|
||||
.rtx
|
||||
.get(self.partition.as_ref().unwrap(), ByteView::from(key))?
|
||||
{
|
||||
Ok(Some(Value::Owned(V::from(ByteView::from(slice)))))
|
||||
Ok(Some(Cow::Owned(V::from(ByteView::from(slice)))))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
@@ -190,7 +191,7 @@ where
|
||||
self.meta.reset();
|
||||
|
||||
let partition =
|
||||
Self::open_partition_handle(&self.keyspace, &self.name, self.bloom_filter_bits)?;
|
||||
Self::open_partition_handle(&self.keyspace, self.name, self.bloom_filter_bits)?;
|
||||
|
||||
self.partition.replace(partition);
|
||||
|
||||
@@ -283,7 +284,7 @@ where
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
meta: self.meta.clone(),
|
||||
name: self.name.clone(),
|
||||
name: self.name,
|
||||
keyspace: self.keyspace.clone(),
|
||||
partition: None,
|
||||
rtx: self.keyspace.read_tx(),
|
||||
|
||||
@@ -20,7 +20,7 @@ where
|
||||
Ok(self
|
||||
.iter_at_(from)
|
||||
.take(to - from)
|
||||
.map(|(_, v)| v.into_inner())
|
||||
.map(|(_, v)| v.into_owned())
|
||||
.collect::<Vec<_>>())
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
fs::{File, OpenOptions},
|
||||
io::{self, Seek, SeekFrom, Write},
|
||||
path::{Path, PathBuf},
|
||||
@@ -6,7 +7,7 @@ use std::{
|
||||
};
|
||||
|
||||
use arc_swap::ArcSwap;
|
||||
use brk_core::{Result, Value};
|
||||
use brk_core::Result;
|
||||
use memmap2::Mmap;
|
||||
|
||||
use crate::{AnyVec, HEADER_OFFSET, Header};
|
||||
@@ -28,11 +29,11 @@ where
|
||||
fn read_(&self, index: usize, mmap: &Mmap) -> Result<Option<T>>;
|
||||
|
||||
#[inline]
|
||||
fn get_or_read(&self, index: I, mmap: &Mmap) -> Result<Option<Value<T>>> {
|
||||
fn get_or_read(&self, index: I, mmap: &Mmap) -> Result<Option<Cow<T>>> {
|
||||
self.get_or_read_(index.to_usize()?, mmap)
|
||||
}
|
||||
#[inline]
|
||||
fn get_or_read_(&self, index: usize, mmap: &Mmap) -> Result<Option<Value<T>>> {
|
||||
fn get_or_read_(&self, index: usize, mmap: &Mmap) -> Result<Option<Cow<T>>> {
|
||||
let stored_len = self.stored_len_(mmap);
|
||||
|
||||
if index >= stored_len {
|
||||
@@ -41,9 +42,9 @@ where
|
||||
if j >= pushed.len() {
|
||||
return Ok(None);
|
||||
}
|
||||
Ok(pushed.get(j).map(Value::Ref))
|
||||
Ok(pushed.get(j).map(Cow::Borrowed))
|
||||
} else {
|
||||
Ok(self.read_(index, mmap)?.map(Value::Owned))
|
||||
Ok(self.read_(index, mmap)?.map(Cow::Owned))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::iter::Skip;
|
||||
use std::{borrow::Cow, iter::Skip};
|
||||
|
||||
use brk_core::{Printable, Value};
|
||||
use brk_core::Printable;
|
||||
|
||||
use super::{StoredIndex, StoredType};
|
||||
|
||||
@@ -34,7 +34,7 @@ pub trait BaseVecIterator: Iterator {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait VecIterator<'a>: BaseVecIterator<Item = (Self::I, Value<'a, Self::T>)> {
|
||||
pub trait VecIterator<'a>: BaseVecIterator<Item = (Self::I, Cow<'a, Self::T>)> {
|
||||
type I: StoredIndex;
|
||||
type T: StoredType + 'a;
|
||||
|
||||
@@ -44,12 +44,12 @@ pub trait VecIterator<'a>: BaseVecIterator<Item = (Self::I, Value<'a, Self::T>)>
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_(&mut self, i: usize) -> Option<Value<'a, Self::T>> {
|
||||
fn get_(&mut self, i: usize) -> Option<Cow<'a, Self::T>> {
|
||||
self.next_at(i).map(|(_, v)| v)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get(&mut self, i: Self::I) -> Option<Value<'a, Self::T>> {
|
||||
fn get(&mut self, i: Self::I) -> Option<Cow<'a, Self::T>> {
|
||||
self.get_(i.unwrap_to_usize())
|
||||
}
|
||||
|
||||
@@ -65,12 +65,12 @@ pub trait VecIterator<'a>: BaseVecIterator<Item = (Self::I, Value<'a, Self::T>)>
|
||||
dbg!(self.name(), i, self.len());
|
||||
panic!("unwrap_get_inner_")
|
||||
})
|
||||
.into_inner()
|
||||
.into_owned()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_inner(&mut self, i: Self::I) -> Option<Self::T> {
|
||||
self.get_(i.unwrap_to_usize()).map(|v| v.into_inner())
|
||||
self.get_(i.unwrap_to_usize()).map(|v| v.into_owned())
|
||||
}
|
||||
|
||||
fn last(mut self) -> Option<Self::Item>
|
||||
@@ -83,7 +83,7 @@ pub trait VecIterator<'a>: BaseVecIterator<Item = (Self::I, Value<'a, Self::T>)>
|
||||
}
|
||||
let i = len - 1;
|
||||
self.set_(i);
|
||||
self.next().map(|(i, v)| (i, Value::Owned(v.into_inner())))
|
||||
self.next()
|
||||
}
|
||||
|
||||
fn index_type_to_string(&self) -> &'static str {
|
||||
@@ -93,7 +93,7 @@ pub trait VecIterator<'a>: BaseVecIterator<Item = (Self::I, Value<'a, Self::T>)>
|
||||
|
||||
impl<'a, I, T, Iter> VecIterator<'a> for Iter
|
||||
where
|
||||
Iter: BaseVecIterator<Item = (I, Value<'a, T>)>,
|
||||
Iter: BaseVecIterator<Item = (I, Cow<'a, T>)>,
|
||||
I: StoredIndex,
|
||||
T: StoredType + 'a,
|
||||
{
|
||||
@@ -102,4 +102,4 @@ where
|
||||
}
|
||||
|
||||
pub type BoxedVecIterator<'a, I, T> =
|
||||
Box<dyn VecIterator<'a, I = I, T = T, Item = (I, Value<'a, T>)> + 'a>;
|
||||
Box<dyn VecIterator<'a, I = I, T = T, Item = (I, Cow<'a, T>)> + 'a>;
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
fs, mem,
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use arc_swap::{ArcSwap, Guard};
|
||||
use brk_core::{Error, Result, Value, Version};
|
||||
use brk_core::{Error, Result, Version};
|
||||
use memmap2::Mmap;
|
||||
use rayon::prelude::*;
|
||||
use zstd::DEFAULT_COMPRESSION_LEVEL;
|
||||
@@ -441,7 +442,7 @@ where
|
||||
I: StoredIndex,
|
||||
T: StoredType,
|
||||
{
|
||||
type Item = (I, Value<'a, T>);
|
||||
type Item = (I, Cow<'a, T>);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let mmap = &self.guard;
|
||||
@@ -456,7 +457,7 @@ where
|
||||
self.vec
|
||||
.pushed()
|
||||
.get(j)
|
||||
.map(|v| (I::from(i), Value::Ref(v)))
|
||||
.map(|v| (I::from(i), Cow::Borrowed(v)))
|
||||
} else {
|
||||
let page_index = i / Self::PER_PAGE;
|
||||
|
||||
@@ -476,7 +477,7 @@ where
|
||||
.unwrap()
|
||||
.1
|
||||
.get(i % Self::PER_PAGE)
|
||||
.map(|v| (I::from(i), Value::Owned(v.clone())))
|
||||
.map(|v| (I::from(i), Cow::Owned(v.clone())))
|
||||
};
|
||||
|
||||
self.index += 1;
|
||||
@@ -490,7 +491,7 @@ where
|
||||
I: StoredIndex,
|
||||
T: StoredType,
|
||||
{
|
||||
type Item = (I, Value<'a, T>);
|
||||
type Item = (I, Cow<'a, T>);
|
||||
type IntoIter = CompressedVecIterator<'a, I, T>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::{fs, path::Path};
|
||||
use std::{borrow::Cow, fs, path::Path};
|
||||
|
||||
use brk_exit::Exit;
|
||||
use clap_derive::ValueEnum;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use brk_core::{Result, StoredPhantom, Value, Version};
|
||||
use brk_core::{Result, StoredPhantom, Version};
|
||||
|
||||
use crate::{
|
||||
AnyCollectableVec, AnyIterableVec, AnyVec, BaseVecIterator, BoxedAnyIterableVec,
|
||||
@@ -36,7 +36,12 @@ impl Computation {
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum Dependencies<I, T, S1I, S1T, S2I, S2T, S3I, S3T> {
|
||||
pub enum Dependencies<I, T, S1I, S1T, S2I, S2T, S3I, S3T>
|
||||
where
|
||||
S1T: Clone,
|
||||
S2T: Clone,
|
||||
S3T: Clone,
|
||||
{
|
||||
From1(BoxedAnyIterableVec<S1I, S1T>, ComputeFrom1<I, T, S1I, S1T>),
|
||||
From2(
|
||||
(BoxedAnyIterableVec<S1I, S1T>, BoxedAnyIterableVec<S2I, S2T>),
|
||||
@@ -60,7 +65,12 @@ pub type ComputedVecFrom3<I, T, S1I, S1T, S2I, S2T, S3I, S3T> =
|
||||
ComputedVec<I, T, S1I, S1T, S2I, S2T, S3I, S3T>;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ComputedVec<I, T, S1I, S1T, S2I, S2T, S3I, S3T> {
|
||||
pub enum ComputedVec<I, T, S1I, S1T, S2I, S2T, S3I, S3T>
|
||||
where
|
||||
S1T: Clone,
|
||||
S2T: Clone,
|
||||
S3T: Clone,
|
||||
{
|
||||
Eager {
|
||||
vec: EagerVec<I, T>,
|
||||
deps: Dependencies<I, T, S1I, S1T, S2I, S2T, S3I, S3T>,
|
||||
@@ -251,7 +261,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub enum ComputedVecIterator<'a, I, T, S1I, S1T, S2I, S2T, S3I, S3T> {
|
||||
pub enum ComputedVecIterator<'a, I, T, S1I, S1T, S2I, S2T, S3I, S3T>
|
||||
where
|
||||
S1T: Clone,
|
||||
S2T: Clone,
|
||||
S3T: Clone,
|
||||
{
|
||||
Eager(StoredVecIterator<'a, I, T>),
|
||||
LazyFrom1(LazyVecFrom1Iterator<'a, I, T, S1I, S1T>),
|
||||
LazyFrom2(LazyVecFrom2Iterator<'a, I, T, S1I, S1T, S2I, S2T>),
|
||||
@@ -270,7 +285,7 @@ where
|
||||
S3I: StoredIndex,
|
||||
S3T: StoredType,
|
||||
{
|
||||
type Item = (I, Value<'a, T>);
|
||||
type Item = (I, Cow<'a, T>);
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self {
|
||||
Self::Eager(i) => i.next(),
|
||||
@@ -335,7 +350,7 @@ where
|
||||
S3I: StoredIndex,
|
||||
S3T: StoredType,
|
||||
{
|
||||
type Item = (I, Value<'a, T>);
|
||||
type Item = (I, Cow<'a, T>);
|
||||
type IntoIter = ComputedVecIterator<'a, I, T, S1I, S1T, S2I, S2T, S3I, S3T>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use core::error;
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
cmp::Ordering,
|
||||
f32,
|
||||
fmt::Debug,
|
||||
@@ -10,7 +11,7 @@ use std::{
|
||||
use arc_swap::ArcSwap;
|
||||
use brk_core::{
|
||||
Bitcoin, CheckedSub, Close, Date, DateIndex, Dollars, Error, Result, Sats, StoredF32,
|
||||
StoredUsize, Value, Version,
|
||||
StoredUsize, Version,
|
||||
};
|
||||
use brk_exit::Exit;
|
||||
use log::info;
|
||||
@@ -103,7 +104,7 @@ where
|
||||
self.0.path()
|
||||
}
|
||||
|
||||
pub fn get_or_read(&self, index: I, mmap: &Mmap) -> Result<Option<Value<T>>> {
|
||||
pub fn get_or_read(&self, index: I, mmap: &Mmap) -> Result<Option<Cow<T>>> {
|
||||
self.0.get_or_read(index, mmap)
|
||||
}
|
||||
|
||||
@@ -213,7 +214,7 @@ where
|
||||
|
||||
let index = max_from.min(A::from(self.len()));
|
||||
other.iter_at(index).try_for_each(|(a, b)| {
|
||||
let (i, v) = t((a, b.into_inner(), self));
|
||||
let (i, v) = t((a, b.into_owned(), self));
|
||||
self.forced_push_at(i, v, exit)
|
||||
})?;
|
||||
|
||||
@@ -238,7 +239,7 @@ where
|
||||
let mut adder_iter = adder.iter();
|
||||
|
||||
added.iter_at(index).try_for_each(|(i, v)| {
|
||||
let v = v.into_inner() + adder_iter.unwrap_get_inner(i);
|
||||
let v = v.into_owned() + adder_iter.unwrap_get_inner(i);
|
||||
|
||||
self.forced_push_at(i, v, exit)
|
||||
})?;
|
||||
@@ -265,7 +266,7 @@ where
|
||||
|
||||
subtracted.iter_at(index).try_for_each(|(i, v)| {
|
||||
let v = v
|
||||
.into_inner()
|
||||
.into_owned()
|
||||
.checked_sub(subtracter_iter.unwrap_get_inner(i))
|
||||
.unwrap();
|
||||
|
||||
@@ -302,7 +303,7 @@ where
|
||||
T::from(source.iter().unwrap_get_inner_(0))
|
||||
});
|
||||
}
|
||||
let max = prev.clone().unwrap().max(T::from(v.into_inner()));
|
||||
let max = prev.clone().unwrap().max(T::from(v.into_owned()));
|
||||
prev.replace(max.clone());
|
||||
|
||||
self.forced_push_at(i, max, exit)
|
||||
@@ -332,7 +333,7 @@ where
|
||||
let mut multiplier_iter = multiplier.iter();
|
||||
|
||||
multiplied.iter_at(index).try_for_each(|(i, v)| {
|
||||
let v = v.into_inner() * multiplier_iter.unwrap_get_inner(i);
|
||||
let v = v.into_owned() * multiplier_iter.unwrap_get_inner(i);
|
||||
|
||||
self.forced_push_at(i, v.into(), exit)
|
||||
})?;
|
||||
@@ -416,7 +417,7 @@ where
|
||||
|
||||
let mut divider_iter = divider.iter();
|
||||
divided.iter_at(index).try_for_each(|(i, divided)| {
|
||||
let divided = divided.into_inner();
|
||||
let divided = divided.into_owned();
|
||||
let divider = divider_iter.unwrap_get_inner(i);
|
||||
|
||||
let v = if as_percentage {
|
||||
@@ -451,7 +452,7 @@ where
|
||||
let index = max_from.min(I::from(self.len()));
|
||||
let mut close_iter = close.iter();
|
||||
ath.iter_at(index).try_for_each(|(i, ath)| {
|
||||
let ath = ath.into_inner();
|
||||
let ath = ath.into_owned();
|
||||
if ath == Dollars::ZERO {
|
||||
self.forced_push_at(i, T::from(StoredF32::default()), exit)
|
||||
} else {
|
||||
@@ -479,11 +480,11 @@ where
|
||||
)?;
|
||||
|
||||
let index = max_from.min(
|
||||
VecIterator::last(self.0.into_iter()).map_or_else(T::default, |(_, v)| v.into_inner()),
|
||||
VecIterator::last(self.0.into_iter()).map_or_else(T::default, |(_, v)| v.into_owned()),
|
||||
);
|
||||
let mut prev_i = None;
|
||||
other.iter_at(index).try_for_each(|(v, i)| -> Result<()> {
|
||||
let i = i.into_inner();
|
||||
let i = i.into_owned();
|
||||
if prev_i.is_some_and(|prev_i| prev_i == i) {
|
||||
return Ok(());
|
||||
}
|
||||
@@ -647,7 +648,7 @@ where
|
||||
self_to_other.iter_at(index).try_for_each(|(i, other)| {
|
||||
self.forced_push_at(
|
||||
i,
|
||||
T::from(other_to_self_iter.unwrap_get_inner(other.into_inner()) == i),
|
||||
T::from(other_to_self_iter.unwrap_get_inner(other.into_owned()) == i),
|
||||
exit,
|
||||
)
|
||||
})?;
|
||||
@@ -715,7 +716,7 @@ where
|
||||
.unwrap()
|
||||
.iter_at(index)
|
||||
.try_for_each(|(i, v)| {
|
||||
let mut sum = v.into_inner();
|
||||
let mut sum = v.into_owned();
|
||||
others_iter.iter_mut().for_each(|iter| {
|
||||
sum = sum.clone() + iter.unwrap_get_inner(i);
|
||||
});
|
||||
@@ -750,7 +751,7 @@ where
|
||||
.unwrap()
|
||||
.iter_at(index)
|
||||
.try_for_each(|(i, v)| {
|
||||
let min = v.into_inner();
|
||||
let min = v.into_owned();
|
||||
let min = others_iter
|
||||
.iter_mut()
|
||||
.map(|iter| iter.unwrap_get_inner(i))
|
||||
@@ -787,7 +788,7 @@ where
|
||||
.unwrap()
|
||||
.iter_at(index)
|
||||
.try_for_each(|(i, v)| {
|
||||
let max = v.into_inner();
|
||||
let max = v.into_owned();
|
||||
let max = others_iter
|
||||
.iter_mut()
|
||||
.map(|iter| iter.unwrap_get_inner(i))
|
||||
@@ -836,7 +837,7 @@ where
|
||||
let min_prev_i = min_i.unwrap_or_default().unwrap_to_usize();
|
||||
let mut other_iter = source.iter();
|
||||
source.iter_at(index).try_for_each(|(i, value)| {
|
||||
let value = value.into_inner();
|
||||
let value = value.into_owned();
|
||||
|
||||
if min_i.is_none() || min_i.is_some_and(|min_i| min_i <= i) {
|
||||
if prev.is_none() {
|
||||
@@ -924,7 +925,7 @@ where
|
||||
let index = max_from.min(I::from(self.len()));
|
||||
let mut source_iter = source.iter();
|
||||
source.iter_at(index).try_for_each(|(i, current)| {
|
||||
let current = current.into_inner();
|
||||
let current = current.into_owned();
|
||||
|
||||
let prev = i
|
||||
.checked_sub(I::from(len))
|
||||
@@ -963,7 +964,7 @@ where
|
||||
.unwrap_or_default(),
|
||||
);
|
||||
|
||||
let last_value = f32::from(b.into_inner());
|
||||
let last_value = f32::from(b.into_owned());
|
||||
|
||||
let percentage_change = ((last_value / previous_value) - 1.0) * 100.0;
|
||||
|
||||
@@ -999,7 +1000,7 @@ where
|
||||
percentage_returns
|
||||
.iter_at(index)
|
||||
.try_for_each(|(i, percentage)| {
|
||||
let percentage = percentage.into_inner();
|
||||
let percentage = percentage.into_owned();
|
||||
|
||||
let cagr = (((f32::from(percentage) / 100.0 + 1.0).powf(1.0 / years as f32)) - 1.0)
|
||||
* 100.0;
|
||||
@@ -1054,7 +1055,7 @@ impl EagerVec<DateIndex, Sats> {
|
||||
|
||||
let index = max_from.min(DateIndex::from(self.len()));
|
||||
closes.iter_at(index).try_for_each(|(i, closes)| {
|
||||
let price = *closes.into_inner();
|
||||
let price = *closes.into_owned();
|
||||
let i_usize = i.unwrap_to_usize();
|
||||
if prev.is_none() {
|
||||
if i_usize == 0 {
|
||||
@@ -1102,7 +1103,7 @@ impl EagerVec<DateIndex, Sats> {
|
||||
|
||||
let index = max_from.min(DateIndex::from(self.len()));
|
||||
closes.iter_at(index).try_for_each(|(i, closes)| {
|
||||
let price = *closes.into_inner();
|
||||
let price = *closes.into_owned();
|
||||
let i_usize = i.unwrap_to_usize();
|
||||
if prev.is_none() {
|
||||
if i_usize == 0 {
|
||||
@@ -1144,7 +1145,7 @@ impl EagerVec<DateIndex, Dollars> {
|
||||
let first_price_date = DateIndex::try_from(Date::new(2010, 7, 12)).unwrap();
|
||||
|
||||
stacks.iter_at(index).try_for_each(|(i, stack)| {
|
||||
let stack = stack.into_inner();
|
||||
let stack = stack.into_owned();
|
||||
let mut avg_price = Dollars::from(f64::NAN);
|
||||
if i > first_price_date {
|
||||
avg_price = DCA_AMOUNT
|
||||
@@ -1175,7 +1176,7 @@ impl EagerVec<DateIndex, Dollars> {
|
||||
let from_usize = from.unwrap_to_usize();
|
||||
|
||||
stacks.iter_at(index).try_for_each(|(i, stack)| {
|
||||
let stack = stack.into_inner();
|
||||
let stack = stack.into_owned();
|
||||
let mut avg_price = Dollars::from(f64::NAN);
|
||||
if i >= from {
|
||||
avg_price =
|
||||
@@ -1204,7 +1205,7 @@ where
|
||||
|
||||
let index = max_from.min(I::from(self.len()));
|
||||
sats.iter_at(index).try_for_each(|(i, sats)| {
|
||||
let (i, v) = (i, Bitcoin::from(sats.into_inner()));
|
||||
let (i, v) = (i, Bitcoin::from(sats.into_owned()));
|
||||
self.forced_push_at(i, v, exit)
|
||||
})?;
|
||||
|
||||
@@ -1231,7 +1232,7 @@ where
|
||||
let index = max_from.min(I::from(self.len()));
|
||||
bitcoin.iter_at(index).try_for_each(|(i, bitcoin)| {
|
||||
let dollars = price_iter.unwrap_get_inner(i);
|
||||
let (i, v) = (i, *dollars * bitcoin.into_inner());
|
||||
let (i, v) = (i, *dollars * bitcoin.into_owned());
|
||||
self.forced_push_at(i, v, exit)
|
||||
})?;
|
||||
|
||||
@@ -1262,7 +1263,7 @@ where
|
||||
// bitcoin.iter_at(index).try_for_each(|(i, bitcoin, ..)| {
|
||||
// let height = i_to_height_iter.unwrap_get_inner(i);
|
||||
// let dollars = price_iter.unwrap_get_inner(height);
|
||||
// let (i, v) = (i, *dollars * bitcoin.into_inner());
|
||||
// let (i, v) = (i, *dollars * bitcoin.into_owned());
|
||||
// self.forced_push_at(i, v, exit)
|
||||
// })?;
|
||||
|
||||
@@ -1275,7 +1276,7 @@ where
|
||||
I: StoredIndex,
|
||||
T: StoredType,
|
||||
{
|
||||
type Item = (I, Value<'a, T>);
|
||||
type Item = (I, Cow<'a, T>);
|
||||
type IntoIter = StoredVecIterator<'a, I, T>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::{cmp::Ordering, fmt::Debug, path::Path};
|
||||
use std::{borrow::Cow, cmp::Ordering, fmt::Debug, path::Path};
|
||||
|
||||
use arc_swap::ArcSwap;
|
||||
use brk_core::{Error, Height, Result, Value, Version};
|
||||
use brk_core::{Error, Height, Result, Version};
|
||||
|
||||
use crate::{
|
||||
AnyCollectableVec, AnyIterableVec, AnyVec, BoxedVecIterator, CollectableVec, Format,
|
||||
@@ -30,7 +30,7 @@ where
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_or_read(&self, index: I, mmap: &Mmap) -> Result<Option<Value<T>>> {
|
||||
pub fn get_or_read(&self, index: I, mmap: &Mmap) -> Result<Option<Cow<T>>> {
|
||||
self.0.get_or_read(index, mmap)
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ where
|
||||
I: StoredIndex,
|
||||
T: StoredType,
|
||||
{
|
||||
type Item = (I, Value<'a, T>);
|
||||
type Item = (I, Cow<'a, T>);
|
||||
type IntoIter = StoredVecIterator<'a, I, T>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::marker::PhantomData;
|
||||
use std::{borrow::Cow, marker::PhantomData};
|
||||
|
||||
use brk_core::{Result, Value, Version};
|
||||
use brk_core::{Result, Version};
|
||||
|
||||
use crate::{
|
||||
AnyCollectableVec, AnyIterableVec, AnyVec, BaseVecIterator, BoxedAnyIterableVec,
|
||||
@@ -8,10 +8,13 @@ use crate::{
|
||||
};
|
||||
|
||||
pub type ComputeFrom1<I, T, S1I, S1T> =
|
||||
for<'a> fn(I, &mut dyn BaseVecIterator<Item = (S1I, Value<'a, S1T>)>) -> Option<T>;
|
||||
for<'a> fn(I, &mut dyn BaseVecIterator<Item = (S1I, Cow<'a, S1T>)>) -> Option<T>;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct LazyVecFrom1<I, T, S1I, S1T> {
|
||||
pub struct LazyVecFrom1<I, T, S1I, S1T>
|
||||
where
|
||||
S1T: Clone,
|
||||
{
|
||||
name: String,
|
||||
version: Version,
|
||||
source: BoxedAnyIterableVec<S1I, S1T>,
|
||||
@@ -50,7 +53,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LazyVecFrom1Iterator<'a, I, T, S1I, S1T> {
|
||||
pub struct LazyVecFrom1Iterator<'a, I, T, S1I, S1T>
|
||||
where
|
||||
S1T: Clone,
|
||||
{
|
||||
lazy: &'a LazyVecFrom1<I, T, S1I, S1T>,
|
||||
source: BoxedVecIterator<'a, S1I, S1T>,
|
||||
index: usize,
|
||||
@@ -63,14 +69,14 @@ where
|
||||
S1I: StoredIndex,
|
||||
S1T: StoredType,
|
||||
{
|
||||
type Item = (I, Value<'a, T>);
|
||||
type Item = (I, Cow<'a, T>);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.index >= self.len() {
|
||||
return None;
|
||||
}
|
||||
let index = I::from(self.index);
|
||||
let opt = (self.lazy.compute)(index, &mut *self.source).map(|v| (index, Value::Owned(v)));
|
||||
let opt = (self.lazy.compute)(index, &mut *self.source).map(|v| (index, Cow::Owned(v)));
|
||||
if opt.is_some() {
|
||||
self.index += 1;
|
||||
}
|
||||
@@ -108,7 +114,7 @@ where
|
||||
S1I: StoredIndex,
|
||||
S1T: StoredType,
|
||||
{
|
||||
type Item = (I, Value<'a, T>);
|
||||
type Item = (I, Cow<'a, T>);
|
||||
type IntoIter = LazyVecFrom1Iterator<'a, I, T, S1I, S1T>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::marker::PhantomData;
|
||||
use std::{borrow::Cow, marker::PhantomData};
|
||||
|
||||
use brk_core::{Result, Value, Version};
|
||||
use brk_core::{Result, Version};
|
||||
|
||||
use crate::{
|
||||
AnyCollectableVec, AnyIterableVec, AnyVec, BaseVecIterator, BoxedAnyIterableVec,
|
||||
@@ -9,12 +9,16 @@ use crate::{
|
||||
|
||||
pub type ComputeFrom2<I, T, S1I, S1T, S2I, S2T> = for<'a> fn(
|
||||
I,
|
||||
&mut dyn BaseVecIterator<Item = (S1I, Value<'a, S1T>)>,
|
||||
&mut dyn BaseVecIterator<Item = (S2I, Value<'a, S2T>)>,
|
||||
&mut dyn BaseVecIterator<Item = (S1I, Cow<'a, S1T>)>,
|
||||
&mut dyn BaseVecIterator<Item = (S2I, Cow<'a, S2T>)>,
|
||||
) -> Option<T>;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct LazyVecFrom2<I, T, S1I, S1T, S2I, S2T> {
|
||||
pub struct LazyVecFrom2<I, T, S1I, S1T, S2I, S2T>
|
||||
where
|
||||
S1T: Clone,
|
||||
S2T: Clone,
|
||||
{
|
||||
name: String,
|
||||
version: Version,
|
||||
source1: BoxedAnyIterableVec<S1I, S1T>,
|
||||
@@ -66,7 +70,11 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LazyVecFrom2Iterator<'a, I, T, S1I, S1T, S2I, S2T> {
|
||||
pub struct LazyVecFrom2Iterator<'a, I, T, S1I, S1T, S2I, S2T>
|
||||
where
|
||||
S1T: Clone,
|
||||
S2T: Clone,
|
||||
{
|
||||
lazy: &'a LazyVecFrom2<I, T, S1I, S1T, S2I, S2T>,
|
||||
source1: BoxedVecIterator<'a, S1I, S1T>,
|
||||
source2: BoxedVecIterator<'a, S2I, S2T>,
|
||||
@@ -82,12 +90,12 @@ where
|
||||
S2I: StoredIndex,
|
||||
S2T: StoredType,
|
||||
{
|
||||
type Item = (I, Value<'a, T>);
|
||||
type Item = (I, Cow<'a, T>);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let index = I::from(self.index);
|
||||
let opt = (self.lazy.compute)(index, &mut *self.source1, &mut *self.source2)
|
||||
.map(|v| (index, Value::Owned(v)));
|
||||
.map(|v| (index, Cow::Owned(v)));
|
||||
if opt.is_some() {
|
||||
self.index += 1;
|
||||
}
|
||||
@@ -140,7 +148,7 @@ where
|
||||
S2I: StoredIndex,
|
||||
S2T: StoredType,
|
||||
{
|
||||
type Item = (I, Value<'a, T>);
|
||||
type Item = (I, Cow<'a, T>);
|
||||
type IntoIter = LazyVecFrom2Iterator<'a, I, T, S1I, S1T, S2I, S2T>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::marker::PhantomData;
|
||||
use std::{borrow::Cow, marker::PhantomData};
|
||||
|
||||
use brk_core::{Result, Value, Version};
|
||||
use brk_core::{Result, Version};
|
||||
|
||||
use crate::{
|
||||
AnyCollectableVec, AnyIterableVec, AnyVec, BaseVecIterator, BoxedAnyIterableVec,
|
||||
@@ -9,13 +9,18 @@ use crate::{
|
||||
|
||||
pub type ComputeFrom3<I, T, S1I, S1T, S2I, S2T, S3I, S3T> = for<'a> fn(
|
||||
I,
|
||||
&mut dyn BaseVecIterator<Item = (S1I, Value<'a, S1T>)>,
|
||||
&mut dyn BaseVecIterator<Item = (S2I, Value<'a, S2T>)>,
|
||||
&mut dyn BaseVecIterator<Item = (S3I, Value<'a, S3T>)>,
|
||||
&mut dyn BaseVecIterator<Item = (S1I, Cow<'a, S1T>)>,
|
||||
&mut dyn BaseVecIterator<Item = (S2I, Cow<'a, S2T>)>,
|
||||
&mut dyn BaseVecIterator<Item = (S3I, Cow<'a, S3T>)>,
|
||||
) -> Option<T>;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct LazyVecFrom3<I, T, S1I, S1T, S2I, S2T, S3I, S3T> {
|
||||
pub struct LazyVecFrom3<I, T, S1I, S1T, S2I, S2T, S3I, S3T>
|
||||
where
|
||||
S1T: Clone,
|
||||
S2T: Clone,
|
||||
S3T: Clone,
|
||||
{
|
||||
name: String,
|
||||
version: Version,
|
||||
source1: BoxedAnyIterableVec<S1I, S1T>,
|
||||
@@ -73,7 +78,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LazyVecFrom3Iterator<'a, I, T, S1I, S1T, S2I, S2T, S3I, S3T> {
|
||||
pub struct LazyVecFrom3Iterator<'a, I, T, S1I, S1T, S2I, S2T, S3I, S3T>
|
||||
where
|
||||
S1T: Clone,
|
||||
S2T: Clone,
|
||||
S3T: Clone,
|
||||
{
|
||||
lazy: &'a LazyVecFrom3<I, T, S1I, S1T, S2I, S2T, S3I, S3T>,
|
||||
source1: BoxedVecIterator<'a, S1I, S1T>,
|
||||
source2: BoxedVecIterator<'a, S2I, S2T>,
|
||||
@@ -93,7 +103,7 @@ where
|
||||
S3I: StoredIndex,
|
||||
S3T: StoredType,
|
||||
{
|
||||
type Item = (I, Value<'a, T>);
|
||||
type Item = (I, Cow<'a, T>);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let index = I::from(self.index);
|
||||
@@ -103,7 +113,7 @@ where
|
||||
&mut *self.source2,
|
||||
&mut *self.source3,
|
||||
)
|
||||
.map(|v| (index, Value::Owned(v)));
|
||||
.map(|v| (index, Cow::Owned(v)));
|
||||
if opt.is_some() {
|
||||
self.index += 1;
|
||||
}
|
||||
@@ -166,7 +176,7 @@ where
|
||||
S3I: StoredIndex,
|
||||
S3T: StoredType,
|
||||
{
|
||||
type Item = (I, Value<'a, T>);
|
||||
type Item = (I, Cow<'a, T>);
|
||||
type IntoIter = LazyVecFrom3Iterator<'a, I, T, S1I, S1T, S2I, S2T, S3I, S3T>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
fs::{self, File},
|
||||
io,
|
||||
marker::PhantomData,
|
||||
@@ -8,7 +9,7 @@ use std::{
|
||||
};
|
||||
|
||||
use arc_swap::{ArcSwap, Guard};
|
||||
use brk_core::{Error, Result, Value, Version};
|
||||
use brk_core::{Error, Result, Version};
|
||||
use memmap2::Mmap;
|
||||
use rayon::prelude::*;
|
||||
|
||||
@@ -23,7 +24,7 @@ const VERSION: Version = Version::ONE;
|
||||
pub struct RawVec<I, T> {
|
||||
header: Header,
|
||||
parent: PathBuf,
|
||||
name: String,
|
||||
name: &'static str,
|
||||
// Consider Arc<ArcSwap<Option<Mmap>>> for dataraces when reorg ?
|
||||
mmap: Arc<ArcSwap<Mmap>>,
|
||||
pushed: Vec<T>,
|
||||
@@ -83,7 +84,7 @@ where
|
||||
Ok(Self {
|
||||
mmap,
|
||||
header,
|
||||
name: name.to_string(),
|
||||
name: Box::leak(Box::new(name.to_string())),
|
||||
parent: parent.to_owned(),
|
||||
pushed: vec![],
|
||||
phantom: PhantomData,
|
||||
@@ -236,7 +237,7 @@ where
|
||||
|
||||
#[inline]
|
||||
fn name(&self) -> &str {
|
||||
&self.name
|
||||
self.name
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -260,7 +261,7 @@ impl<I, T> Clone for RawVec<I, T> {
|
||||
Self {
|
||||
header: self.header.clone(),
|
||||
parent: self.parent.clone(),
|
||||
name: self.name.clone(),
|
||||
name: self.name,
|
||||
mmap: self.mmap.clone(),
|
||||
pushed: vec![],
|
||||
phantom: PhantomData,
|
||||
@@ -301,7 +302,7 @@ where
|
||||
I: StoredIndex,
|
||||
T: StoredType,
|
||||
{
|
||||
type Item = (I, Value<'a, T>);
|
||||
type Item = (I, Cow<'a, T>);
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let mmap = &self.guard;
|
||||
@@ -326,7 +327,7 @@ where
|
||||
I: StoredIndex,
|
||||
T: StoredType,
|
||||
{
|
||||
type Item = (I, Value<'a, T>);
|
||||
type Item = (I, Cow<'a, T>);
|
||||
type IntoIter = RawVecIterator<'a, I, T>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use arc_swap::ArcSwap;
|
||||
use brk_core::{Result, Value, Version};
|
||||
use brk_core::{Result, Version};
|
||||
use memmap2::Mmap;
|
||||
|
||||
use crate::{
|
||||
@@ -195,7 +198,7 @@ where
|
||||
I: StoredIndex,
|
||||
T: StoredType,
|
||||
{
|
||||
type Item = (I, Value<'a, T>);
|
||||
type Item = (I, Cow<'a, T>);
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self {
|
||||
Self::Compressed(i) => i.next(),
|
||||
@@ -238,7 +241,7 @@ where
|
||||
I: StoredIndex,
|
||||
T: StoredType,
|
||||
{
|
||||
type Item = (I, Value<'a, T>);
|
||||
type Item = (I, Cow<'a, T>);
|
||||
type IntoIter = StoredVecIterator<'a, I, T>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
|
||||
Reference in New Issue
Block a user