mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-05-26 01:34:45 -07:00
computer: fix stateful
This commit is contained in:
@@ -31,7 +31,7 @@ impl<T> ByAmountRange<T> {
|
||||
F: FnMut(Filter) -> T,
|
||||
{
|
||||
Self {
|
||||
_0sats: create(Filter::Amount(AmountFilter::LowerThan(Sats::_1))),
|
||||
_0sats: create(Filter::Amount(AmountFilter::Range(Sats::ZERO..Sats::_1))),
|
||||
_1sat_to_10sats: create(Filter::Amount(AmountFilter::Range(Sats::_1..Sats::_10))),
|
||||
_10sats_to_100sats: create(Filter::Amount(AmountFilter::Range(Sats::_10..Sats::_100))),
|
||||
_100sats_to_1k_sats: create(Filter::Amount(AmountFilter::Range(Sats::_100..Sats::_1K))),
|
||||
@@ -45,7 +45,7 @@ impl<T> ByAmountRange<T> {
|
||||
_100btc_to_1k_btc: create(Filter::Amount(AmountFilter::Range(Sats::_100BTC..Sats::_1K_BTC))),
|
||||
_1k_btc_to_10k_btc: create(Filter::Amount(AmountFilter::Range(Sats::_1K_BTC..Sats::_10K_BTC))),
|
||||
_10k_btc_to_100k_btc: create(Filter::Amount(AmountFilter::Range(Sats::_10K_BTC..Sats::_100K_BTC))),
|
||||
_100k_btc_or_more: create(Filter::Amount(AmountFilter::GreaterOrEqual(Sats::_100K_BTC))),
|
||||
_100k_btc_or_more: create(Filter::Amount(AmountFilter::Range(Sats::_100K_BTC..Sats::MAX))),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use brk_traversable::Traversable;
|
||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||
|
||||
use super::{Filter, Term};
|
||||
|
||||
@@ -26,4 +27,18 @@ impl<T> ByTerm<T> {
|
||||
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
[&mut self.short, &mut self.long].into_iter()
|
||||
}
|
||||
|
||||
pub fn par_iter(&self) -> impl ParallelIterator<Item = &T>
|
||||
where
|
||||
T: Send + Sync,
|
||||
{
|
||||
[&self.short, &self.long].into_par_iter()
|
||||
}
|
||||
|
||||
pub fn par_iter_mut(&mut self) -> impl ParallelIterator<Item = &mut T>
|
||||
where
|
||||
T: Send + Sync,
|
||||
{
|
||||
[&mut self.short, &mut self.long].into_par_iter()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,11 +102,25 @@ impl<T> UTXOGroups<T> {
|
||||
[&self.all].into_iter().chain(self.term.iter())
|
||||
}
|
||||
|
||||
pub fn par_iter_aggregate(&self) -> impl ParallelIterator<Item = &T>
|
||||
where
|
||||
T: Send + Sync,
|
||||
{
|
||||
[&self.all].into_par_iter().chain(self.term.par_iter())
|
||||
}
|
||||
|
||||
/// Iterator over aggregate cohorts (all, sth, lth) that compute values from sub-cohorts.
|
||||
/// These are cohorts with StateLevel::PriceOnly that derive values from stateful sub-cohorts.
|
||||
pub fn iter_aggregate_mut(&mut self) -> impl Iterator<Item = &mut T> {
|
||||
[&mut self.all].into_iter().chain(self.term.iter_mut())
|
||||
}
|
||||
|
||||
pub fn par_iter_aggregate_mut(&mut self) -> impl ParallelIterator<Item = &mut T>
|
||||
where
|
||||
T: Send + Sync,
|
||||
{
|
||||
[&mut self.all]
|
||||
.into_iter()
|
||||
.chain(self.term.iter_mut())
|
||||
.into_par_iter()
|
||||
.chain(self.term.par_iter_mut())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user