computer: fix stateful

This commit is contained in:
nym21
2025-12-03 15:43:50 +01:00
parent f48ad577d3
commit fcc74ba212
8 changed files with 169 additions and 82 deletions

View File

@@ -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))),
}
}

View File

@@ -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()
}
}

View File

@@ -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())
}
}