mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-20 15:38:11 -07:00
global: traversable
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
use brk_vecs::{IVecs, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use super::{ByAmountRange, ByGreatEqualAmount, ByLowerThanAmount, GroupFilter};
|
||||
use crate::Filtered;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
use super::{ByAmountRange, ByGreatEqualAmount, ByLowerThanAmount};
|
||||
|
||||
#[derive(Default, Clone, Traversable)]
|
||||
pub struct AddressGroups<T> {
|
||||
pub ge_amount: ByGreatEqualAmount<T>,
|
||||
pub amount_range: ByAmountRange<T>,
|
||||
@@ -27,7 +28,7 @@ impl<T> AddressGroups<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> AddressGroups<(GroupFilter, T)> {
|
||||
impl<T> AddressGroups<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
self.amount_range
|
||||
.iter_right()
|
||||
@@ -36,7 +37,7 @@ impl<T> AddressGroups<(GroupFilter, T)> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<AddressGroups<T>> for AddressGroups<(GroupFilter, T)> {
|
||||
impl<T> From<AddressGroups<T>> for AddressGroups<Filtered<T>> {
|
||||
fn from(value: AddressGroups<T>) -> Self {
|
||||
Self {
|
||||
amount_range: ByAmountRange::from(value.amount_range),
|
||||
@@ -45,26 +46,3 @@ impl<T> From<AddressGroups<T>> for AddressGroups<(GroupFilter, T)> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IVecs> IVecs for AddressGroups<(GroupFilter, T)> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
[
|
||||
("ge_amount", self.ge_amount.to_tree_node()),
|
||||
("amount_range", self.amount_range.to_tree_node()),
|
||||
("lt_amount", self.lt_amount.to_tree_node()),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(name, node)| (name.to_string(), node))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
let mut iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
|
||||
Box::new(self.ge_amount.iter());
|
||||
iter = Box::new(iter.chain(IVecs::iter(&self.amount_range)));
|
||||
iter = Box::new(iter.chain(self.lt_amount.iter()));
|
||||
iter
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use std::ops::{Add, AddAssign};
|
||||
|
||||
use brk_vecs::{IVecs, TreeNode};
|
||||
use brk_traversable::{Traversable, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
|
||||
use super::GroupFilter;
|
||||
use crate::OutputType;
|
||||
use super::Filter;
|
||||
use crate::{Filtered, OutputType};
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct ByAddressType<T> {
|
||||
@@ -122,7 +122,7 @@ impl<T> ByAddressType<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByAddressType<(GroupFilter, T)> {
|
||||
impl<T> ByAddressType<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&self.p2pk65.1,
|
||||
@@ -138,17 +138,17 @@ impl<T> ByAddressType<(GroupFilter, T)> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<ByAddressType<T>> for ByAddressType<(GroupFilter, T)> {
|
||||
impl<T> From<ByAddressType<T>> for ByAddressType<Filtered<T>> {
|
||||
fn from(value: ByAddressType<T>) -> Self {
|
||||
Self {
|
||||
p2pk65: (GroupFilter::Type(OutputType::P2PK65), value.p2pk65),
|
||||
p2pk33: (GroupFilter::Type(OutputType::P2PK33), value.p2pk33),
|
||||
p2pkh: (GroupFilter::Type(OutputType::P2PKH), value.p2pkh),
|
||||
p2sh: (GroupFilter::Type(OutputType::P2SH), value.p2sh),
|
||||
p2wpkh: (GroupFilter::Type(OutputType::P2WPKH), value.p2wpkh),
|
||||
p2wsh: (GroupFilter::Type(OutputType::P2WSH), value.p2wsh),
|
||||
p2tr: (GroupFilter::Type(OutputType::P2TR), value.p2tr),
|
||||
p2a: (GroupFilter::Type(OutputType::P2A), value.p2a),
|
||||
p2pk65: (Filter::Type(OutputType::P2PK65), value.p2pk65).into(),
|
||||
p2pk33: (Filter::Type(OutputType::P2PK33), value.p2pk33).into(),
|
||||
p2pkh: (Filter::Type(OutputType::P2PKH), value.p2pkh).into(),
|
||||
p2sh: (Filter::Type(OutputType::P2SH), value.p2sh).into(),
|
||||
p2wpkh: (Filter::Type(OutputType::P2WPKH), value.p2wpkh).into(),
|
||||
p2wsh: (Filter::Type(OutputType::P2WSH), value.p2wsh).into(),
|
||||
p2tr: (Filter::Type(OutputType::P2TR), value.p2tr).into(),
|
||||
p2a: (Filter::Type(OutputType::P2A), value.p2a).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,41 +196,7 @@ impl<T> ByAddressType<Option<T>> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: AnyCollectableVec + !IVecs> IVecs for ByAddressType<T> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
[
|
||||
("p2pk65", &self.p2pk65),
|
||||
("p2pk33", &self.p2pk33),
|
||||
("p2pkh", &self.p2pkh),
|
||||
("p2sh", &self.p2sh),
|
||||
("p2wpkh", &self.p2wpkh),
|
||||
("p2wsh", &self.p2wsh),
|
||||
("p2tr", &self.p2tr),
|
||||
("p2a", &self.p2a),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(name, field)| (name.to_string(), TreeNode::Leaf(field.name().to_string())))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
[
|
||||
&self.p2pk65 as &dyn AnyCollectableVec,
|
||||
&self.p2pk33,
|
||||
&self.p2pkh,
|
||||
&self.p2sh,
|
||||
&self.p2wpkh,
|
||||
&self.p2wsh,
|
||||
&self.p2tr,
|
||||
&self.p2a,
|
||||
]
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IVecs> IVecs for ByAddressType<T> {
|
||||
impl<T: Traversable> Traversable for ByAddressType<T> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
[
|
||||
@@ -249,16 +215,16 @@ impl<T: IVecs> IVecs for ByAddressType<T> {
|
||||
)
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
fn iter_any_collectable(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
let mut iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
|
||||
Box::new(self.p2pk65.iter());
|
||||
iter = Box::new(iter.chain(self.p2pk33.iter()));
|
||||
iter = Box::new(iter.chain(self.p2pkh.iter()));
|
||||
iter = Box::new(iter.chain(self.p2sh.iter()));
|
||||
iter = Box::new(iter.chain(self.p2wpkh.iter()));
|
||||
iter = Box::new(iter.chain(self.p2wsh.iter()));
|
||||
iter = Box::new(iter.chain(self.p2tr.iter()));
|
||||
iter = Box::new(iter.chain(self.p2a.iter()));
|
||||
Box::new(self.p2pk65.iter_any_collectable());
|
||||
iter = Box::new(iter.chain(self.p2pk33.iter_any_collectable()));
|
||||
iter = Box::new(iter.chain(self.p2pkh.iter_any_collectable()));
|
||||
iter = Box::new(iter.chain(self.p2sh.iter_any_collectable()));
|
||||
iter = Box::new(iter.chain(self.p2wpkh.iter_any_collectable()));
|
||||
iter = Box::new(iter.chain(self.p2wsh.iter_any_collectable()));
|
||||
iter = Box::new(iter.chain(self.p2tr.iter_any_collectable()));
|
||||
iter = Box::new(iter.chain(self.p2a.iter_any_collectable()));
|
||||
iter
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use brk_vecs::{IVecs, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use super::GroupFilter;
|
||||
use crate::Filtered;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
use super::Filter;
|
||||
|
||||
#[derive(Default, Clone, Traversable)]
|
||||
pub struct ByAgeRange<T> {
|
||||
pub up_to_1d: T,
|
||||
pub _1d_to_1w: T,
|
||||
@@ -27,29 +28,29 @@ pub struct ByAgeRange<T> {
|
||||
pub from_15y: T,
|
||||
}
|
||||
|
||||
impl<T> From<ByAgeRange<T>> for ByAgeRange<(GroupFilter, T)> {
|
||||
impl<T> From<ByAgeRange<T>> for ByAgeRange<Filtered<T>> {
|
||||
fn from(value: ByAgeRange<T>) -> Self {
|
||||
Self {
|
||||
up_to_1d: (GroupFilter::LowerThan(1), value.up_to_1d),
|
||||
_1d_to_1w: (GroupFilter::Range(1..7), value._1d_to_1w),
|
||||
_1w_to_1m: (GroupFilter::Range(7..30), value._1w_to_1m),
|
||||
_1m_to_2m: (GroupFilter::Range(30..2 * 30), value._1m_to_2m),
|
||||
_2m_to_3m: (GroupFilter::Range(2 * 30..3 * 30), value._2m_to_3m),
|
||||
_3m_to_4m: (GroupFilter::Range(3 * 30..4 * 30), value._3m_to_4m),
|
||||
_4m_to_5m: (GroupFilter::Range(4 * 30..5 * 30), value._4m_to_5m),
|
||||
_5m_to_6m: (GroupFilter::Range(5 * 30..6 * 30), value._5m_to_6m),
|
||||
_6m_to_1y: (GroupFilter::Range(6 * 30..365), value._6m_to_1y),
|
||||
_1y_to_2y: (GroupFilter::Range(365..2 * 365), value._1y_to_2y),
|
||||
_2y_to_3y: (GroupFilter::Range(2 * 365..3 * 365), value._2y_to_3y),
|
||||
_3y_to_4y: (GroupFilter::Range(3 * 365..4 * 365), value._3y_to_4y),
|
||||
_4y_to_5y: (GroupFilter::Range(4 * 365..5 * 365), value._4y_to_5y),
|
||||
_5y_to_6y: (GroupFilter::Range(5 * 365..6 * 365), value._5y_to_6y),
|
||||
_6y_to_7y: (GroupFilter::Range(6 * 365..7 * 365), value._6y_to_7y),
|
||||
_7y_to_8y: (GroupFilter::Range(7 * 365..8 * 365), value._7y_to_8y),
|
||||
_8y_to_10y: (GroupFilter::Range(8 * 365..10 * 365), value._8y_to_10y),
|
||||
_10y_to_12y: (GroupFilter::Range(10 * 365..12 * 365), value._10y_to_12y),
|
||||
_12y_to_15y: (GroupFilter::Range(12 * 365..15 * 365), value._12y_to_15y),
|
||||
from_15y: (GroupFilter::GreaterOrEqual(15 * 365), value.from_15y),
|
||||
up_to_1d: (Filter::LowerThan(1), value.up_to_1d).into(),
|
||||
_1d_to_1w: (Filter::Range(1..7), value._1d_to_1w).into(),
|
||||
_1w_to_1m: (Filter::Range(7..30), value._1w_to_1m).into(),
|
||||
_1m_to_2m: (Filter::Range(30..2 * 30), value._1m_to_2m).into(),
|
||||
_2m_to_3m: (Filter::Range(2 * 30..3 * 30), value._2m_to_3m).into(),
|
||||
_3m_to_4m: (Filter::Range(3 * 30..4 * 30), value._3m_to_4m).into(),
|
||||
_4m_to_5m: (Filter::Range(4 * 30..5 * 30), value._4m_to_5m).into(),
|
||||
_5m_to_6m: (Filter::Range(5 * 30..6 * 30), value._5m_to_6m).into(),
|
||||
_6m_to_1y: (Filter::Range(6 * 30..365), value._6m_to_1y).into(),
|
||||
_1y_to_2y: (Filter::Range(365..2 * 365), value._1y_to_2y).into(),
|
||||
_2y_to_3y: (Filter::Range(2 * 365..3 * 365), value._2y_to_3y).into(),
|
||||
_3y_to_4y: (Filter::Range(3 * 365..4 * 365), value._3y_to_4y).into(),
|
||||
_4y_to_5y: (Filter::Range(4 * 365..5 * 365), value._4y_to_5y).into(),
|
||||
_5y_to_6y: (Filter::Range(5 * 365..6 * 365), value._5y_to_6y).into(),
|
||||
_6y_to_7y: (Filter::Range(6 * 365..7 * 365), value._6y_to_7y).into(),
|
||||
_7y_to_8y: (Filter::Range(7 * 365..8 * 365), value._7y_to_8y).into(),
|
||||
_8y_to_10y: (Filter::Range(8 * 365..10 * 365), value._8y_to_10y).into(),
|
||||
_10y_to_12y: (Filter::Range(10 * 365..12 * 365), value._10y_to_12y).into(),
|
||||
_12y_to_15y: (Filter::Range(12 * 365..15 * 365), value._12y_to_15y).into(),
|
||||
from_15y: (Filter::GreaterOrEqual(15 * 365), value.from_15y).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -108,7 +109,7 @@ impl<T> ByAgeRange<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByAgeRange<(GroupFilter, T)> {
|
||||
impl<T> ByAgeRange<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&self.up_to_1d.1,
|
||||
@@ -135,60 +136,3 @@ impl<T> ByAgeRange<(GroupFilter, T)> {
|
||||
.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IVecs> IVecs for ByAgeRange<(GroupFilter, T)> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
[
|
||||
("up_to_1d", &self.up_to_1d),
|
||||
("1d_to_1w", &self._1d_to_1w),
|
||||
("1w_to_1m", &self._1w_to_1m),
|
||||
("1m_to_2m", &self._1m_to_2m),
|
||||
("2m_to_3m", &self._2m_to_3m),
|
||||
("3m_to_4m", &self._3m_to_4m),
|
||||
("4m_to_5m", &self._4m_to_5m),
|
||||
("5m_to_6m", &self._5m_to_6m),
|
||||
("6m_to_1y", &self._6m_to_1y),
|
||||
("1y_to_2y", &self._1y_to_2y),
|
||||
("2y_to_3y", &self._2y_to_3y),
|
||||
("3y_to_4y", &self._3y_to_4y),
|
||||
("4y_to_5y", &self._4y_to_5y),
|
||||
("5y_to_6y", &self._5y_to_6y),
|
||||
("6y_to_7y", &self._6y_to_7y),
|
||||
("7y_to_8y", &self._7y_to_8y),
|
||||
("8y_to_10y", &self._8y_to_10y),
|
||||
("10y_to_12y", &self._10y_to_12y),
|
||||
("12y_to_15y", &self._12y_to_15y),
|
||||
("from_15y", &self.from_15y),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(name, (_, field))| (name.to_string(), field.to_tree_node()))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
let mut iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
|
||||
Box::new(self.up_to_1d.1.iter());
|
||||
iter = Box::new(iter.chain(self._1d_to_1w.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1w_to_1m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1m_to_2m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._2m_to_3m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._3m_to_4m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._4m_to_5m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._5m_to_6m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._6m_to_1y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1y_to_2y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._2y_to_3y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._3y_to_4y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._4y_to_5y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._5y_to_6y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._6y_to_7y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._7y_to_8y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._8y_to_10y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._10y_to_12y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._12y_to_15y.1.iter()));
|
||||
iter = Box::new(iter.chain(self.from_15y.1.iter()));
|
||||
iter
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
use std::ops::{Add, AddAssign};
|
||||
|
||||
use brk_vecs::{IVecs, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use crate::Sats;
|
||||
use crate::{Filtered, Sats};
|
||||
|
||||
use super::GroupFilter;
|
||||
use super::Filter;
|
||||
|
||||
#[derive(Debug, Default, Clone)]
|
||||
#[derive(Debug, Default, Clone, Traversable)]
|
||||
pub struct ByAmountRange<T> {
|
||||
pub _0sats: T,
|
||||
pub _1sat_to_10sats: T,
|
||||
@@ -26,67 +25,81 @@ pub struct ByAmountRange<T> {
|
||||
pub _100k_btc_or_more: T,
|
||||
}
|
||||
|
||||
impl<T> From<ByAmountRange<T>> for ByAmountRange<(GroupFilter, T)> {
|
||||
impl<T> From<ByAmountRange<T>> for ByAmountRange<Filtered<T>> {
|
||||
fn from(value: ByAmountRange<T>) -> Self {
|
||||
#[allow(clippy::inconsistent_digit_grouping)]
|
||||
Self {
|
||||
_0sats: (GroupFilter::LowerThan(Sats::_1.into()), value._0sats),
|
||||
_0sats: (Filter::LowerThan(Sats::_1.into()), value._0sats).into(),
|
||||
_1sat_to_10sats: (
|
||||
GroupFilter::Range(Sats::_1.into()..Sats::_10.into()),
|
||||
Filter::Range(Sats::_1.into()..Sats::_10.into()),
|
||||
value._1sat_to_10sats,
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
_10sats_to_100sats: (
|
||||
GroupFilter::Range(Sats::_10.into()..Sats::_100.into()),
|
||||
Filter::Range(Sats::_10.into()..Sats::_100.into()),
|
||||
value._10sats_to_100sats,
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
_100sats_to_1k_sats: (
|
||||
GroupFilter::Range(Sats::_100.into()..Sats::_1K.into()),
|
||||
Filter::Range(Sats::_100.into()..Sats::_1K.into()),
|
||||
value._100sats_to_1k_sats,
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
_1k_sats_to_10k_sats: (
|
||||
GroupFilter::Range(Sats::_1K.into()..Sats::_10K.into()),
|
||||
Filter::Range(Sats::_1K.into()..Sats::_10K.into()),
|
||||
value._1k_sats_to_10k_sats,
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
_10k_sats_to_100k_sats: (
|
||||
GroupFilter::Range(Sats::_10K.into()..Sats::_100K.into()),
|
||||
Filter::Range(Sats::_10K.into()..Sats::_100K.into()),
|
||||
value._10k_sats_to_100k_sats,
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
_100k_sats_to_1m_sats: (
|
||||
GroupFilter::Range(Sats::_100K.into()..Sats::_1M.into()),
|
||||
Filter::Range(Sats::_100K.into()..Sats::_1M.into()),
|
||||
value._100k_sats_to_1m_sats,
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
_1m_sats_to_10m_sats: (
|
||||
GroupFilter::Range(Sats::_1M.into()..Sats::_10M.into()),
|
||||
Filter::Range(Sats::_1M.into()..Sats::_10M.into()),
|
||||
value._1m_sats_to_10m_sats,
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
_10m_sats_to_1btc: (
|
||||
GroupFilter::Range(Sats::_10M.into()..Sats::_1BTC.into()),
|
||||
Filter::Range(Sats::_10M.into()..Sats::_1BTC.into()),
|
||||
value._10m_sats_to_1btc,
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
_1btc_to_10btc: (
|
||||
GroupFilter::Range(Sats::_1BTC.into()..Sats::_10BTC.into()),
|
||||
Filter::Range(Sats::_1BTC.into()..Sats::_10BTC.into()),
|
||||
value._1btc_to_10btc,
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
_10btc_to_100btc: (
|
||||
GroupFilter::Range(Sats::_10BTC.into()..Sats::_100BTC.into()),
|
||||
Filter::Range(Sats::_10BTC.into()..Sats::_100BTC.into()),
|
||||
value._10btc_to_100btc,
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
_100btc_to_1k_btc: (
|
||||
GroupFilter::Range(Sats::_100BTC.into()..Sats::_1K_BTC.into()),
|
||||
Filter::Range(Sats::_100BTC.into()..Sats::_1K_BTC.into()),
|
||||
value._100btc_to_1k_btc,
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
_1k_btc_to_10k_btc: (
|
||||
GroupFilter::Range(Sats::_1K_BTC.into()..Sats::_10K_BTC.into()),
|
||||
Filter::Range(Sats::_1K_BTC.into()..Sats::_10K_BTC.into()),
|
||||
value._1k_btc_to_10k_btc,
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
_10k_btc_to_100k_btc: (
|
||||
GroupFilter::Range(Sats::_10K_BTC.into()..Sats::_100K_BTC.into()),
|
||||
Filter::Range(Sats::_10K_BTC.into()..Sats::_100K_BTC.into()),
|
||||
value._10k_btc_to_100k_btc,
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
_100k_btc_or_more: (
|
||||
GroupFilter::GreaterOrEqual(Sats::_100K_BTC.into()),
|
||||
Filter::GreaterOrEqual(Sats::_100K_BTC.into()),
|
||||
value._100k_btc_or_more,
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,7 +204,7 @@ impl<T> ByAmountRange<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByAmountRange<(GroupFilter, T)> {
|
||||
impl<T> ByAmountRange<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&self._0sats.1,
|
||||
@@ -262,50 +275,3 @@ where
|
||||
self._100k_btc_or_more += rhs._100k_btc_or_more;
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IVecs> IVecs for ByAmountRange<(GroupFilter, T)> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
[
|
||||
("0sats", &self._0sats),
|
||||
("1sat_to_10sats", &self._1sat_to_10sats),
|
||||
("10sats_to_100sats", &self._10sats_to_100sats),
|
||||
("100sats_to_1k_sats", &self._100sats_to_1k_sats),
|
||||
("1k_sats_to_10k_sats", &self._1k_sats_to_10k_sats),
|
||||
("10k_sats_to_100k_sats", &self._10k_sats_to_100k_sats),
|
||||
("100k_sats_to_1m_sats", &self._100k_sats_to_1m_sats),
|
||||
("1m_sats_to_10m_sats", &self._1m_sats_to_10m_sats),
|
||||
("10m_sats_to_1btc", &self._10m_sats_to_1btc),
|
||||
("1btc_to_10btc", &self._1btc_to_10btc),
|
||||
("10btc_to_100btc", &self._10btc_to_100btc),
|
||||
("100btc_to_1k_btc", &self._100btc_to_1k_btc),
|
||||
("1k_btc_to_10k_btc", &self._1k_btc_to_10k_btc),
|
||||
("10k_btc_to_100k_btc", &self._10k_btc_to_100k_btc),
|
||||
("100k_btc_or_more", &self._100k_btc_or_more),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(name, (_, field))| (name.to_string(), field.to_tree_node()))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
let mut iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
|
||||
Box::new(self._0sats.1.iter());
|
||||
iter = Box::new(iter.chain(self._1sat_to_10sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._10sats_to_100sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._100sats_to_1k_sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1k_sats_to_10k_sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._10k_sats_to_100k_sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._100k_sats_to_1m_sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1m_sats_to_10m_sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._10m_sats_to_1btc.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1btc_to_10btc.1.iter()));
|
||||
iter = Box::new(iter.chain(self._10btc_to_100btc.1.iter()));
|
||||
iter = Box::new(iter.chain(self._100btc_to_1k_btc.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1k_btc_to_10k_btc.1.iter()));
|
||||
iter = Box::new(iter.chain(self._10k_btc_to_100k_btc.1.iter()));
|
||||
iter = Box::new(iter.chain(self._100k_btc_or_more.1.iter()));
|
||||
iter
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use brk_vecs::{IVecs, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug, Default, Traversable)]
|
||||
pub struct ByAnyAddress<T> {
|
||||
pub loaded: T,
|
||||
pub empty: T,
|
||||
@@ -13,21 +12,3 @@ impl<T> ByAnyAddress<Option<T>> {
|
||||
self.empty.take();
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IVecs> IVecs for ByAnyAddress<T> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
[("loaded", &self.loaded), ("empty", &self.empty)]
|
||||
.into_iter()
|
||||
.map(|(name, field)| (name.to_string(), field.to_tree_node()))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
let mut iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
|
||||
Box::new(self.loaded.iter());
|
||||
iter = Box::new(iter.chain(self.empty.iter()));
|
||||
iter
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use brk_vecs::{IVecs, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use crate::{HalvingEpoch, Height};
|
||||
use crate::{Filtered, HalvingEpoch, Height};
|
||||
|
||||
use super::GroupFilter;
|
||||
use super::Filter;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
#[derive(Default, Clone, Traversable)]
|
||||
pub struct ByEpoch<T> {
|
||||
pub _0: T,
|
||||
pub _1: T,
|
||||
@@ -14,14 +13,14 @@ pub struct ByEpoch<T> {
|
||||
pub _4: T,
|
||||
}
|
||||
|
||||
impl<T> From<ByEpoch<T>> for ByEpoch<(GroupFilter, T)> {
|
||||
impl<T> From<ByEpoch<T>> for ByEpoch<Filtered<T>> {
|
||||
fn from(value: ByEpoch<T>) -> Self {
|
||||
Self {
|
||||
_0: (GroupFilter::Epoch(HalvingEpoch::new(0)), value._0),
|
||||
_1: (GroupFilter::Epoch(HalvingEpoch::new(1)), value._1),
|
||||
_2: (GroupFilter::Epoch(HalvingEpoch::new(2)), value._2),
|
||||
_3: (GroupFilter::Epoch(HalvingEpoch::new(3)), value._3),
|
||||
_4: (GroupFilter::Epoch(HalvingEpoch::new(4)), value._4),
|
||||
_0: (Filter::Epoch(HalvingEpoch::new(0)), value._0).into(),
|
||||
_1: (Filter::Epoch(HalvingEpoch::new(1)), value._1).into(),
|
||||
_2: (Filter::Epoch(HalvingEpoch::new(2)), value._2).into(),
|
||||
_3: (Filter::Epoch(HalvingEpoch::new(3)), value._3).into(),
|
||||
_4: (Filter::Epoch(HalvingEpoch::new(4)), value._4).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,34 +55,8 @@ impl<T> ByEpoch<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByEpoch<(GroupFilter, T)> {
|
||||
impl<T> ByEpoch<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[&self._0.1, &self._1.1, &self._2.1, &self._3.1, &self._4.1].into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IVecs> IVecs for ByEpoch<(GroupFilter, T)> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
[
|
||||
("0", &self._0),
|
||||
("1", &self._1),
|
||||
("2", &self._2),
|
||||
("3", &self._3),
|
||||
("4", &self._4),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(name, (_, field))| (name.to_string(), field.to_tree_node()))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
let mut iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> = Box::new(self._0.1.iter());
|
||||
iter = Box::new(iter.chain(self._1.1.iter()));
|
||||
iter = Box::new(iter.chain(self._2.1.iter()));
|
||||
iter = Box::new(iter.chain(self._3.1.iter()));
|
||||
iter = Box::new(iter.chain(self._4.1.iter()));
|
||||
iter
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use brk_vecs::{IVecs, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use crate::Sats;
|
||||
use crate::{Filtered, Sats};
|
||||
|
||||
use super::GroupFilter;
|
||||
use super::Filter;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
#[derive(Default, Clone, Traversable)]
|
||||
pub struct ByGreatEqualAmount<T> {
|
||||
pub _1sat: T,
|
||||
pub _10sats: T,
|
||||
@@ -43,7 +42,7 @@ impl<T> ByGreatEqualAmount<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByGreatEqualAmount<(GroupFilter, T)> {
|
||||
impl<T> ByGreatEqualAmount<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&self._1sat.1,
|
||||
@@ -64,95 +63,26 @@ impl<T> ByGreatEqualAmount<(GroupFilter, T)> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<ByGreatEqualAmount<T>> for ByGreatEqualAmount<(GroupFilter, T)> {
|
||||
impl<T> From<ByGreatEqualAmount<T>> for ByGreatEqualAmount<Filtered<T>> {
|
||||
fn from(value: ByGreatEqualAmount<T>) -> Self {
|
||||
Self {
|
||||
_1sat: (GroupFilter::GreaterOrEqual(Sats::_1.into()), value._1sat),
|
||||
_10sats: (GroupFilter::GreaterOrEqual(Sats::_10.into()), value._10sats),
|
||||
_100sats: (
|
||||
GroupFilter::GreaterOrEqual(Sats::_100.into()),
|
||||
value._100sats,
|
||||
),
|
||||
_1k_sats: (
|
||||
GroupFilter::GreaterOrEqual(Sats::_1K.into()),
|
||||
value._1k_sats,
|
||||
),
|
||||
_10k_sats: (
|
||||
GroupFilter::GreaterOrEqual(Sats::_10K.into()),
|
||||
value._10k_sats,
|
||||
),
|
||||
_100k_sats: (
|
||||
GroupFilter::GreaterOrEqual(Sats::_100K.into()),
|
||||
value._100k_sats,
|
||||
),
|
||||
_1m_sats: (
|
||||
GroupFilter::GreaterOrEqual(Sats::_1M.into()),
|
||||
value._1m_sats,
|
||||
),
|
||||
_10m_sats: (
|
||||
GroupFilter::GreaterOrEqual(Sats::_10M.into()),
|
||||
value._10m_sats,
|
||||
),
|
||||
_1btc: (GroupFilter::GreaterOrEqual(Sats::_1BTC.into()), value._1btc),
|
||||
_10btc: (
|
||||
GroupFilter::GreaterOrEqual(Sats::_10BTC.into()),
|
||||
value._10btc,
|
||||
),
|
||||
_100btc: (
|
||||
GroupFilter::GreaterOrEqual(Sats::_100BTC.into()),
|
||||
value._100btc,
|
||||
),
|
||||
_1k_btc: (
|
||||
GroupFilter::GreaterOrEqual(Sats::_1K_BTC.into()),
|
||||
value._1k_btc,
|
||||
),
|
||||
_1sat: (Filter::GreaterOrEqual(Sats::_1.into()), value._1sat).into(),
|
||||
_10sats: (Filter::GreaterOrEqual(Sats::_10.into()), value._10sats).into(),
|
||||
_100sats: (Filter::GreaterOrEqual(Sats::_100.into()), value._100sats).into(),
|
||||
_1k_sats: (Filter::GreaterOrEqual(Sats::_1K.into()), value._1k_sats).into(),
|
||||
_10k_sats: (Filter::GreaterOrEqual(Sats::_10K.into()), value._10k_sats).into(),
|
||||
_100k_sats: (Filter::GreaterOrEqual(Sats::_100K.into()), value._100k_sats).into(),
|
||||
_1m_sats: (Filter::GreaterOrEqual(Sats::_1M.into()), value._1m_sats).into(),
|
||||
_10m_sats: (Filter::GreaterOrEqual(Sats::_10M.into()), value._10m_sats).into(),
|
||||
_1btc: (Filter::GreaterOrEqual(Sats::_1BTC.into()), value._1btc).into(),
|
||||
_10btc: (Filter::GreaterOrEqual(Sats::_10BTC.into()), value._10btc).into(),
|
||||
_100btc: (Filter::GreaterOrEqual(Sats::_100BTC.into()), value._100btc).into(),
|
||||
_1k_btc: (Filter::GreaterOrEqual(Sats::_1K_BTC.into()), value._1k_btc).into(),
|
||||
_10k_btc: (
|
||||
GroupFilter::GreaterOrEqual(Sats::_10K_BTC.into()),
|
||||
Filter::GreaterOrEqual(Sats::_10K_BTC.into()),
|
||||
value._10k_btc,
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IVecs> IVecs for ByGreatEqualAmount<(GroupFilter, T)> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
[
|
||||
("_1sat", &self._1sat),
|
||||
("_10sats", &self._10sats),
|
||||
("_100sats", &self._100sats),
|
||||
("_1k_sats", &self._1k_sats),
|
||||
("_10k_sats", &self._10k_sats),
|
||||
("_100k_sats", &self._100k_sats),
|
||||
("_1m_sats", &self._1m_sats),
|
||||
("_10m_sats", &self._10m_sats),
|
||||
("_1btc", &self._1btc),
|
||||
("_10btc", &self._10btc),
|
||||
("_100btc", &self._100btc),
|
||||
("_1k_btc", &self._1k_btc),
|
||||
("_10k_btc", &self._10k_btc),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(name, (_, field))| (name.to_string(), field.to_tree_node()))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
let mut iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
|
||||
Box::new(self._1sat.1.iter());
|
||||
iter = Box::new(iter.chain(self._10sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._100sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1k_sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._10k_sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._100k_sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1m_sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._10m_sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1btc.1.iter()));
|
||||
iter = Box::new(iter.chain(self._10btc.1.iter()));
|
||||
iter = Box::new(iter.chain(self._100btc.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1k_btc.1.iter()));
|
||||
iter = Box::new(iter.chain(self._10k_btc.1.iter()));
|
||||
iter
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
use brk_vecs::{IVecs, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use crate::Sats;
|
||||
use crate::{Filtered, Sats};
|
||||
|
||||
use super::GroupFilter;
|
||||
use super::Filter;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
#[derive(Default, Clone, Traversable)]
|
||||
pub struct ByLowerThanAmount<T> {
|
||||
pub _10sats: T,
|
||||
pub _100sats: T,
|
||||
@@ -43,7 +42,7 @@ impl<T> ByLowerThanAmount<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByLowerThanAmount<(GroupFilter, T)> {
|
||||
impl<T> ByLowerThanAmount<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&self._10sats.1,
|
||||
@@ -64,71 +63,22 @@ impl<T> ByLowerThanAmount<(GroupFilter, T)> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<ByLowerThanAmount<T>> for ByLowerThanAmount<(GroupFilter, T)> {
|
||||
impl<T> From<ByLowerThanAmount<T>> for ByLowerThanAmount<Filtered<T>> {
|
||||
fn from(value: ByLowerThanAmount<T>) -> Self {
|
||||
Self {
|
||||
_10sats: (GroupFilter::LowerThan(Sats::_10.into()), value._10sats),
|
||||
_100sats: (GroupFilter::LowerThan(Sats::_100.into()), value._100sats),
|
||||
_1k_sats: (GroupFilter::LowerThan(Sats::_1K.into()), value._1k_sats),
|
||||
_10k_sats: (GroupFilter::LowerThan(Sats::_10K.into()), value._10k_sats),
|
||||
_100k_sats: (GroupFilter::LowerThan(Sats::_100K.into()), value._100k_sats),
|
||||
_1m_sats: (GroupFilter::LowerThan(Sats::_1M.into()), value._1m_sats),
|
||||
_10m_sats: (GroupFilter::LowerThan(Sats::_10M.into()), value._10m_sats),
|
||||
_1btc: (GroupFilter::LowerThan(Sats::_1BTC.into()), value._1btc),
|
||||
_10btc: (GroupFilter::LowerThan(Sats::_10BTC.into()), value._10btc),
|
||||
_100btc: (GroupFilter::LowerThan(Sats::_100BTC.into()), value._100btc),
|
||||
_1k_btc: (GroupFilter::LowerThan(Sats::_1K_BTC.into()), value._1k_btc),
|
||||
_10k_btc: (
|
||||
GroupFilter::LowerThan(Sats::_10K_BTC.into()),
|
||||
value._10k_btc,
|
||||
),
|
||||
_100k_btc: (
|
||||
GroupFilter::LowerThan(Sats::_100K_BTC.into()),
|
||||
value._100k_btc,
|
||||
),
|
||||
_10sats: (Filter::LowerThan(Sats::_10.into()), value._10sats).into(),
|
||||
_100sats: (Filter::LowerThan(Sats::_100.into()), value._100sats).into(),
|
||||
_1k_sats: (Filter::LowerThan(Sats::_1K.into()), value._1k_sats).into(),
|
||||
_10k_sats: (Filter::LowerThan(Sats::_10K.into()), value._10k_sats).into(),
|
||||
_100k_sats: (Filter::LowerThan(Sats::_100K.into()), value._100k_sats).into(),
|
||||
_1m_sats: (Filter::LowerThan(Sats::_1M.into()), value._1m_sats).into(),
|
||||
_10m_sats: (Filter::LowerThan(Sats::_10M.into()), value._10m_sats).into(),
|
||||
_1btc: (Filter::LowerThan(Sats::_1BTC.into()), value._1btc).into(),
|
||||
_10btc: (Filter::LowerThan(Sats::_10BTC.into()), value._10btc).into(),
|
||||
_100btc: (Filter::LowerThan(Sats::_100BTC.into()), value._100btc).into(),
|
||||
_1k_btc: (Filter::LowerThan(Sats::_1K_BTC.into()), value._1k_btc).into(),
|
||||
_10k_btc: (Filter::LowerThan(Sats::_10K_BTC.into()), value._10k_btc).into(),
|
||||
_100k_btc: (Filter::LowerThan(Sats::_100K_BTC.into()), value._100k_btc).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IVecs> IVecs for ByLowerThanAmount<(GroupFilter, T)> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
[
|
||||
("10sats", &self._10sats),
|
||||
("100sats", &self._100sats),
|
||||
("1k_sats", &self._1k_sats),
|
||||
("10k_sats", &self._10k_sats),
|
||||
("100k_sats", &self._100k_sats),
|
||||
("1m_sats", &self._1m_sats),
|
||||
("10m_sats", &self._10m_sats),
|
||||
("1btc", &self._1btc),
|
||||
("10btc", &self._10btc),
|
||||
("100btc", &self._100btc),
|
||||
("1k_btc", &self._1k_btc),
|
||||
("10k_btc", &self._10k_btc),
|
||||
("100k_btc", &self._100k_btc),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(name, (_, field))| (name.to_string(), field.to_tree_node()))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
let mut iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
|
||||
Box::new(self._10sats.1.iter());
|
||||
iter = Box::new(iter.chain(self._100sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1k_sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._10k_sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._100k_sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1m_sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._10m_sats.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1btc.1.iter()));
|
||||
iter = Box::new(iter.chain(self._10btc.1.iter()));
|
||||
iter = Box::new(iter.chain(self._100btc.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1k_btc.1.iter()));
|
||||
iter = Box::new(iter.chain(self._10k_btc.1.iter()));
|
||||
iter = Box::new(iter.chain(self._100k_btc.1.iter()));
|
||||
iter
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use brk_vecs::{IVecs, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
use crate::Filtered;
|
||||
|
||||
use super::GroupFilter;
|
||||
use super::Filter;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
#[derive(Default, Clone, Traversable)]
|
||||
pub struct ByMaxAge<T> {
|
||||
pub _1w: T,
|
||||
pub _1m: T,
|
||||
@@ -51,7 +51,7 @@ impl<T> ByMaxAge<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByMaxAge<(GroupFilter, T)> {
|
||||
impl<T> ByMaxAge<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&self._1w.1,
|
||||
@@ -77,80 +77,27 @@ impl<T> ByMaxAge<(GroupFilter, T)> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<ByMaxAge<T>> for ByMaxAge<(GroupFilter, T)> {
|
||||
impl<T> From<ByMaxAge<T>> for ByMaxAge<Filtered<T>> {
|
||||
fn from(value: ByMaxAge<T>) -> Self {
|
||||
Self {
|
||||
_1w: (GroupFilter::LowerThan(7), value._1w),
|
||||
_1m: (GroupFilter::LowerThan(30), value._1m),
|
||||
_2m: (GroupFilter::LowerThan(2 * 30), value._2m),
|
||||
_3m: (GroupFilter::LowerThan(3 * 30), value._3m),
|
||||
_4m: (GroupFilter::LowerThan(4 * 30), value._4m),
|
||||
_5m: (GroupFilter::LowerThan(5 * 30), value._5m),
|
||||
_6m: (GroupFilter::LowerThan(6 * 30), value._6m),
|
||||
_1y: (GroupFilter::LowerThan(365), value._1y),
|
||||
_2y: (GroupFilter::LowerThan(2 * 365), value._2y),
|
||||
_3y: (GroupFilter::LowerThan(3 * 365), value._3y),
|
||||
_4y: (GroupFilter::LowerThan(4 * 365), value._4y),
|
||||
_5y: (GroupFilter::LowerThan(5 * 365), value._5y),
|
||||
_6y: (GroupFilter::LowerThan(6 * 365), value._6y),
|
||||
_7y: (GroupFilter::LowerThan(7 * 365), value._7y),
|
||||
_8y: (GroupFilter::LowerThan(8 * 365), value._8y),
|
||||
_10y: (GroupFilter::LowerThan(10 * 365), value._10y),
|
||||
_12y: (GroupFilter::LowerThan(12 * 365), value._12y),
|
||||
_15y: (GroupFilter::LowerThan(15 * 365), value._15y),
|
||||
_1w: (Filter::LowerThan(7), value._1w).into(),
|
||||
_1m: (Filter::LowerThan(30), value._1m).into(),
|
||||
_2m: (Filter::LowerThan(2 * 30), value._2m).into(),
|
||||
_3m: (Filter::LowerThan(3 * 30), value._3m).into(),
|
||||
_4m: (Filter::LowerThan(4 * 30), value._4m).into(),
|
||||
_5m: (Filter::LowerThan(5 * 30), value._5m).into(),
|
||||
_6m: (Filter::LowerThan(6 * 30), value._6m).into(),
|
||||
_1y: (Filter::LowerThan(365), value._1y).into(),
|
||||
_2y: (Filter::LowerThan(2 * 365), value._2y).into(),
|
||||
_3y: (Filter::LowerThan(3 * 365), value._3y).into(),
|
||||
_4y: (Filter::LowerThan(4 * 365), value._4y).into(),
|
||||
_5y: (Filter::LowerThan(5 * 365), value._5y).into(),
|
||||
_6y: (Filter::LowerThan(6 * 365), value._6y).into(),
|
||||
_7y: (Filter::LowerThan(7 * 365), value._7y).into(),
|
||||
_8y: (Filter::LowerThan(8 * 365), value._8y).into(),
|
||||
_10y: (Filter::LowerThan(10 * 365), value._10y).into(),
|
||||
_12y: (Filter::LowerThan(12 * 365), value._12y).into(),
|
||||
_15y: (Filter::LowerThan(15 * 365), value._15y).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IVecs> IVecs for ByMaxAge<(GroupFilter, T)> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
[
|
||||
("1w", &self._1w),
|
||||
("1m", &self._1m),
|
||||
("2m", &self._2m),
|
||||
("3m", &self._3m),
|
||||
("4m", &self._4m),
|
||||
("5m", &self._5m),
|
||||
("6m", &self._6m),
|
||||
("1y", &self._1y),
|
||||
("2y", &self._2y),
|
||||
("3y", &self._3y),
|
||||
("4y", &self._4y),
|
||||
("5y", &self._5y),
|
||||
("6y", &self._6y),
|
||||
("7y", &self._7y),
|
||||
("8y", &self._8y),
|
||||
("10y", &self._10y),
|
||||
("12y", &self._12y),
|
||||
("15y", &self._15y),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(name, (_, field))| (name.to_string(), field.to_tree_node()))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
let mut iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
|
||||
Box::new(self._1w.1.iter());
|
||||
iter = Box::new(iter.chain(self._1m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._2m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._3m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._4m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._5m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._6m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._2y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._3y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._4y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._5y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._6y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._7y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._8y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._10y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._12y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._15y.1.iter()));
|
||||
iter
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use brk_vecs::{IVecs, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use super::GroupFilter;
|
||||
use crate::Filtered;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
use super::Filter;
|
||||
|
||||
#[derive(Default, Clone, Traversable)]
|
||||
pub struct ByMinAge<T> {
|
||||
pub _1d: T,
|
||||
pub _1w: T,
|
||||
@@ -51,7 +52,7 @@ impl<T> ByMinAge<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByMinAge<(GroupFilter, T)> {
|
||||
impl<T> ByMinAge<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&self._1d.1,
|
||||
@@ -77,80 +78,27 @@ impl<T> ByMinAge<(GroupFilter, T)> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<ByMinAge<T>> for ByMinAge<(GroupFilter, T)> {
|
||||
impl<T> From<ByMinAge<T>> for ByMinAge<Filtered<T>> {
|
||||
fn from(value: ByMinAge<T>) -> Self {
|
||||
Self {
|
||||
_1d: (GroupFilter::GreaterOrEqual(1), value._1d),
|
||||
_1w: (GroupFilter::GreaterOrEqual(7), value._1w),
|
||||
_1m: (GroupFilter::GreaterOrEqual(30), value._1m),
|
||||
_2m: (GroupFilter::GreaterOrEqual(2 * 30), value._2m),
|
||||
_3m: (GroupFilter::GreaterOrEqual(3 * 30), value._3m),
|
||||
_4m: (GroupFilter::GreaterOrEqual(4 * 30), value._4m),
|
||||
_5m: (GroupFilter::GreaterOrEqual(5 * 30), value._5m),
|
||||
_6m: (GroupFilter::GreaterOrEqual(6 * 30), value._6m),
|
||||
_1y: (GroupFilter::GreaterOrEqual(365), value._1y),
|
||||
_2y: (GroupFilter::GreaterOrEqual(2 * 365), value._2y),
|
||||
_3y: (GroupFilter::GreaterOrEqual(3 * 365), value._3y),
|
||||
_4y: (GroupFilter::GreaterOrEqual(4 * 365), value._4y),
|
||||
_5y: (GroupFilter::GreaterOrEqual(5 * 365), value._5y),
|
||||
_6y: (GroupFilter::GreaterOrEqual(6 * 365), value._6y),
|
||||
_7y: (GroupFilter::GreaterOrEqual(7 * 365), value._7y),
|
||||
_8y: (GroupFilter::GreaterOrEqual(8 * 365), value._8y),
|
||||
_10y: (GroupFilter::GreaterOrEqual(10 * 365), value._10y),
|
||||
_12y: (GroupFilter::GreaterOrEqual(12 * 365), value._12y),
|
||||
_1d: (Filter::GreaterOrEqual(1), value._1d).into(),
|
||||
_1w: (Filter::GreaterOrEqual(7), value._1w).into(),
|
||||
_1m: (Filter::GreaterOrEqual(30), value._1m).into(),
|
||||
_2m: (Filter::GreaterOrEqual(2 * 30), value._2m).into(),
|
||||
_3m: (Filter::GreaterOrEqual(3 * 30), value._3m).into(),
|
||||
_4m: (Filter::GreaterOrEqual(4 * 30), value._4m).into(),
|
||||
_5m: (Filter::GreaterOrEqual(5 * 30), value._5m).into(),
|
||||
_6m: (Filter::GreaterOrEqual(6 * 30), value._6m).into(),
|
||||
_1y: (Filter::GreaterOrEqual(365), value._1y).into(),
|
||||
_2y: (Filter::GreaterOrEqual(2 * 365), value._2y).into(),
|
||||
_3y: (Filter::GreaterOrEqual(3 * 365), value._3y).into(),
|
||||
_4y: (Filter::GreaterOrEqual(4 * 365), value._4y).into(),
|
||||
_5y: (Filter::GreaterOrEqual(5 * 365), value._5y).into(),
|
||||
_6y: (Filter::GreaterOrEqual(6 * 365), value._6y).into(),
|
||||
_7y: (Filter::GreaterOrEqual(7 * 365), value._7y).into(),
|
||||
_8y: (Filter::GreaterOrEqual(8 * 365), value._8y).into(),
|
||||
_10y: (Filter::GreaterOrEqual(10 * 365), value._10y).into(),
|
||||
_12y: (Filter::GreaterOrEqual(12 * 365), value._12y).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IVecs> IVecs for ByMinAge<(GroupFilter, T)> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
[
|
||||
("1d", &self._1d),
|
||||
("1w", &self._1w),
|
||||
("1m", &self._1m),
|
||||
("2m", &self._2m),
|
||||
("3m", &self._3m),
|
||||
("4m", &self._4m),
|
||||
("5m", &self._5m),
|
||||
("6m", &self._6m),
|
||||
("1y", &self._1y),
|
||||
("2y", &self._2y),
|
||||
("3y", &self._3y),
|
||||
("4y", &self._4y),
|
||||
("5y", &self._5y),
|
||||
("6y", &self._6y),
|
||||
("7y", &self._7y),
|
||||
("8y", &self._8y),
|
||||
("10y", &self._10y),
|
||||
("12y", &self._12y),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(name, (_, field))| (name.to_string(), field.to_tree_node()))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
let mut iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
|
||||
Box::new(self._1d.1.iter());
|
||||
iter = Box::new(iter.chain(self._1w.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._2m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._3m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._4m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._5m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._6m.1.iter()));
|
||||
iter = Box::new(iter.chain(self._1y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._2y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._3y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._4y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._5y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._6y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._7y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._8y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._10y.1.iter()));
|
||||
iter = Box::new(iter.chain(self._12y.1.iter()));
|
||||
iter
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
use std::ops::{Add, AddAssign};
|
||||
|
||||
use brk_vecs::{IVecs, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use crate::OutputType;
|
||||
use crate::{Filtered, OutputType};
|
||||
|
||||
use super::GroupFilter;
|
||||
use super::Filter;
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
#[derive(Default, Clone, Debug, Traversable)]
|
||||
pub struct BySpendableType<T> {
|
||||
pub p2pk65: T,
|
||||
pub p2pk33: T,
|
||||
@@ -75,7 +74,7 @@ impl<T> BySpendableType<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> BySpendableType<(GroupFilter, T)> {
|
||||
impl<T> BySpendableType<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[
|
||||
&self.p2pk65.1,
|
||||
@@ -94,20 +93,20 @@ impl<T> BySpendableType<(GroupFilter, T)> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<BySpendableType<T>> for BySpendableType<(GroupFilter, T)> {
|
||||
impl<T> From<BySpendableType<T>> for BySpendableType<Filtered<T>> {
|
||||
fn from(value: BySpendableType<T>) -> Self {
|
||||
Self {
|
||||
p2pk65: (GroupFilter::Type(OutputType::P2PK65), value.p2pk65),
|
||||
p2pk33: (GroupFilter::Type(OutputType::P2PK33), value.p2pk33),
|
||||
p2pkh: (GroupFilter::Type(OutputType::P2PKH), value.p2pkh),
|
||||
p2ms: (GroupFilter::Type(OutputType::P2MS), value.p2ms),
|
||||
p2sh: (GroupFilter::Type(OutputType::P2SH), value.p2sh),
|
||||
p2wpkh: (GroupFilter::Type(OutputType::P2WPKH), value.p2wpkh),
|
||||
p2wsh: (GroupFilter::Type(OutputType::P2WSH), value.p2wsh),
|
||||
p2tr: (GroupFilter::Type(OutputType::P2TR), value.p2tr),
|
||||
p2a: (GroupFilter::Type(OutputType::P2A), value.p2a),
|
||||
unknown: (GroupFilter::Type(OutputType::Unknown), value.unknown),
|
||||
empty: (GroupFilter::Type(OutputType::Empty), value.empty),
|
||||
p2pk65: (Filter::Type(OutputType::P2PK65), value.p2pk65).into(),
|
||||
p2pk33: (Filter::Type(OutputType::P2PK33), value.p2pk33).into(),
|
||||
p2pkh: (Filter::Type(OutputType::P2PKH), value.p2pkh).into(),
|
||||
p2ms: (Filter::Type(OutputType::P2MS), value.p2ms).into(),
|
||||
p2sh: (Filter::Type(OutputType::P2SH), value.p2sh).into(),
|
||||
p2wpkh: (Filter::Type(OutputType::P2WPKH), value.p2wpkh).into(),
|
||||
p2wsh: (Filter::Type(OutputType::P2WSH), value.p2wsh).into(),
|
||||
p2tr: (Filter::Type(OutputType::P2TR), value.p2tr).into(),
|
||||
p2a: (Filter::Type(OutputType::P2A), value.p2a).into(),
|
||||
unknown: (Filter::Type(OutputType::Unknown), value.unknown).into(),
|
||||
empty: (Filter::Type(OutputType::Empty), value.empty).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,42 +151,3 @@ where
|
||||
self.empty += rhs.empty;
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IVecs> IVecs for BySpendableType<(GroupFilter, T)> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
[
|
||||
("p2pk65", &self.p2pk65),
|
||||
("p2pk33", &self.p2pk33),
|
||||
("p2pkh", &self.p2pkh),
|
||||
("p2ms", &self.p2ms),
|
||||
("p2sh", &self.p2sh),
|
||||
("p2wpkh", &self.p2wpkh),
|
||||
("p2wsh", &self.p2wsh),
|
||||
("p2tr", &self.p2tr),
|
||||
("p2a", &self.p2a),
|
||||
("unknown", &self.unknown),
|
||||
("empty", &self.empty),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(name, (_, field))| (name.to_string(), field.to_tree_node()))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
let mut iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
|
||||
Box::new(self.p2pk65.1.iter());
|
||||
iter = Box::new(iter.chain(self.p2pk33.1.iter()));
|
||||
iter = Box::new(iter.chain(self.p2pkh.1.iter()));
|
||||
iter = Box::new(iter.chain(self.p2ms.1.iter()));
|
||||
iter = Box::new(iter.chain(self.p2sh.1.iter()));
|
||||
iter = Box::new(iter.chain(self.p2wpkh.1.iter()));
|
||||
iter = Box::new(iter.chain(self.p2wsh.1.iter()));
|
||||
iter = Box::new(iter.chain(self.p2tr.1.iter()));
|
||||
iter = Box::new(iter.chain(self.p2a.1.iter()));
|
||||
iter = Box::new(iter.chain(self.unknown.1.iter()));
|
||||
iter = Box::new(iter.chain(self.empty.1.iter()));
|
||||
iter
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
use brk_vecs::{IVecs, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use super::GroupFilter;
|
||||
use crate::Filtered;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
use super::Filter;
|
||||
|
||||
#[derive(Default, Clone, Traversable)]
|
||||
pub struct ByTerm<T> {
|
||||
pub short: T,
|
||||
pub long: T,
|
||||
@@ -15,35 +16,17 @@ impl<T> ByTerm<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ByTerm<(GroupFilter, T)> {
|
||||
impl<T> ByTerm<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[&self.short.1, &self.long.1].into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<ByTerm<T>> for ByTerm<(GroupFilter, T)> {
|
||||
impl<T> From<ByTerm<T>> for ByTerm<Filtered<T>> {
|
||||
fn from(value: ByTerm<T>) -> Self {
|
||||
Self {
|
||||
short: (GroupFilter::LowerThan(5 * 30), value.short),
|
||||
long: (GroupFilter::GreaterOrEqual(5 * 30), value.long),
|
||||
short: (Filter::LowerThan(5 * 30), value.short).into(),
|
||||
long: (Filter::GreaterOrEqual(5 * 30), value.long).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IVecs> IVecs for ByTerm<(GroupFilter, T)> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
[("short", &self.short), ("long", &self.long)]
|
||||
.into_iter()
|
||||
.map(|(name, (_, field))| (name.to_string(), field.to_tree_node()))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
let mut iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
|
||||
Box::new(self.short.1.iter());
|
||||
iter = Box::new(iter.chain(self.long.1.iter()));
|
||||
iter
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
use std::ops::{Add, AddAssign};
|
||||
|
||||
use brk_vecs::{IVecs, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
|
||||
use crate::{GroupFilter, OutputType};
|
||||
use crate::OutputType;
|
||||
|
||||
use super::{BySpendableType, ByUnspendableType};
|
||||
|
||||
@@ -73,24 +70,3 @@ where
|
||||
self.unspendable += rhs.unspendable;
|
||||
}
|
||||
}
|
||||
|
||||
// impl<T: IVecs> IVecs for GroupedByType<(GroupFilter, T)> {
|
||||
// fn to_tree_node(&self) -> TreeNode {
|
||||
// TreeNode::Branch(
|
||||
// [
|
||||
// ("spendable", self.spendable.to_tree_node()),
|
||||
// ("unspendable", self.unspendable.to_tree_node()),
|
||||
// ]
|
||||
// .into_iter()
|
||||
// .map(|(name, node)| (name.to_string(), node))
|
||||
// .collect(),
|
||||
// )
|
||||
// }
|
||||
|
||||
// fn iter(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
// let mut iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
|
||||
// Box::new(self.spendable.iter());
|
||||
// iter = Box::new(iter.chain(self.unspendable.iter()));
|
||||
// iter
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use std::ops::{Add, AddAssign};
|
||||
|
||||
use brk_vecs::{IVecs, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
#[derive(Default, Clone, Debug, Traversable)]
|
||||
pub struct ByUnspendableType<T> {
|
||||
pub opreturn: T,
|
||||
}
|
||||
@@ -34,18 +33,3 @@ where
|
||||
self.opreturn += rhs.opreturn;
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IVecs> IVecs for ByUnspendableType<T> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
[("opreturn", &self.opreturn)]
|
||||
.into_iter()
|
||||
.map(|(name, field)| (name.to_string(), field.to_tree_node()))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
self.opreturn.iter()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
use std::ops::Range;
|
||||
|
||||
use brk_traversable::{Traversable, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
|
||||
use crate::{HalvingEpoch, OutputType};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum GroupFilter {
|
||||
pub enum Filter {
|
||||
All,
|
||||
LowerThan(usize),
|
||||
Range(Range<usize>),
|
||||
@@ -12,37 +15,74 @@ pub enum GroupFilter {
|
||||
Type(OutputType),
|
||||
}
|
||||
|
||||
impl GroupFilter {
|
||||
impl Filter {
|
||||
pub fn contains(&self, value: usize) -> bool {
|
||||
match self {
|
||||
GroupFilter::Range(r) => r.contains(&value),
|
||||
GroupFilter::LowerThan(max) => *max > value,
|
||||
GroupFilter::GreaterOrEqual(min) => *min <= value,
|
||||
GroupFilter::All => true,
|
||||
GroupFilter::Epoch(_) | GroupFilter::Type(_) => false,
|
||||
Filter::Range(r) => r.contains(&value),
|
||||
Filter::LowerThan(max) => *max > value,
|
||||
Filter::GreaterOrEqual(min) => *min <= value,
|
||||
Filter::All => true,
|
||||
Filter::Epoch(_) | Filter::Type(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn includes(&self, other: &GroupFilter) -> bool {
|
||||
pub fn includes(&self, other: &Filter) -> bool {
|
||||
match self {
|
||||
GroupFilter::All => true,
|
||||
GroupFilter::LowerThan(max) => match other {
|
||||
GroupFilter::LowerThan(max2) => max >= max2,
|
||||
GroupFilter::Range(range) => range.end <= *max,
|
||||
GroupFilter::All
|
||||
| GroupFilter::GreaterOrEqual(_)
|
||||
| GroupFilter::Epoch(_)
|
||||
| GroupFilter::Type(_) => false,
|
||||
Filter::All => true,
|
||||
Filter::LowerThan(max) => match other {
|
||||
Filter::LowerThan(max2) => max >= max2,
|
||||
Filter::Range(range) => range.end <= *max,
|
||||
Filter::All | Filter::GreaterOrEqual(_) | Filter::Epoch(_) | Filter::Type(_) => {
|
||||
false
|
||||
}
|
||||
},
|
||||
GroupFilter::GreaterOrEqual(min) => match other {
|
||||
GroupFilter::Range(range) => range.start >= *min,
|
||||
GroupFilter::GreaterOrEqual(min2) => min <= min2,
|
||||
GroupFilter::All
|
||||
| GroupFilter::LowerThan(_)
|
||||
| GroupFilter::Epoch(_)
|
||||
| GroupFilter::Type(_) => false,
|
||||
Filter::GreaterOrEqual(min) => match other {
|
||||
Filter::Range(range) => range.start >= *min,
|
||||
Filter::GreaterOrEqual(min2) => min <= min2,
|
||||
Filter::All | Filter::LowerThan(_) | Filter::Epoch(_) | Filter::Type(_) => false,
|
||||
},
|
||||
GroupFilter::Range(_) | GroupFilter::Epoch(_) | GroupFilter::Type(_) => false,
|
||||
Filter::Range(_) | Filter::Epoch(_) | Filter::Type(_) => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Filtered<T>(pub Filter, pub T);
|
||||
|
||||
impl<T> Filtered<T> {
|
||||
pub fn includes(&self, other: &Filter) -> bool {
|
||||
self.0.includes(other)
|
||||
}
|
||||
|
||||
pub fn filter(&self) -> &Filter {
|
||||
&self.0
|
||||
}
|
||||
|
||||
pub fn unwrap(self) -> T {
|
||||
self.1
|
||||
}
|
||||
|
||||
pub fn t(&self) -> &T {
|
||||
&self.1
|
||||
}
|
||||
|
||||
pub fn mut_t(&mut self) -> &mut T {
|
||||
&mut self.1
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<(Filter, T)> for Filtered<T> {
|
||||
fn from(value: (Filter, T)) -> Self {
|
||||
Self(value.0, value.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Traversable> Traversable for Filtered<T> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
self.1.to_tree_node()
|
||||
}
|
||||
|
||||
fn iter_any_collectable(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
self.1.iter_any_collectable()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
use brk_vecs::{IVecs, TreeNode};
|
||||
use vecdb::AnyCollectableVec;
|
||||
use brk_traversable::Traversable;
|
||||
|
||||
use crate::{
|
||||
ByAgeRange, ByAmountRange, ByEpoch, ByGreatEqualAmount, ByLowerThanAmount, ByMaxAge, ByMinAge,
|
||||
BySpendableType, ByTerm, GroupFilter,
|
||||
BySpendableType, ByTerm, Filter, Filtered,
|
||||
};
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
#[derive(Default, Clone, Traversable)]
|
||||
pub struct UTXOGroups<T> {
|
||||
pub all: T,
|
||||
pub age_range: ByAgeRange<T>,
|
||||
@@ -54,7 +53,7 @@ impl<T> UTXOGroups<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> UTXOGroups<(GroupFilter, T)> {
|
||||
impl<T> UTXOGroups<Filtered<T>> {
|
||||
pub fn iter_right(&self) -> impl Iterator<Item = &T> {
|
||||
[&self.all.1]
|
||||
.into_iter()
|
||||
@@ -70,10 +69,10 @@ impl<T> UTXOGroups<(GroupFilter, T)> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> From<UTXOGroups<T>> for UTXOGroups<(GroupFilter, T)> {
|
||||
impl<T> From<UTXOGroups<T>> for UTXOGroups<Filtered<T>> {
|
||||
fn from(value: UTXOGroups<T>) -> Self {
|
||||
Self {
|
||||
all: (GroupFilter::All, value.all),
|
||||
all: (Filter::All, value.all).into(),
|
||||
term: ByTerm::from(value.term),
|
||||
max_age: ByMaxAge::from(value.max_age),
|
||||
min_age: ByMinAge::from(value.min_age),
|
||||
@@ -86,40 +85,3 @@ impl<T> From<UTXOGroups<T>> for UTXOGroups<(GroupFilter, T)> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IVecs> IVecs for UTXOGroups<(GroupFilter, T)> {
|
||||
fn to_tree_node(&self) -> TreeNode {
|
||||
TreeNode::Branch(
|
||||
[
|
||||
("all", self.all.1.to_tree_node()),
|
||||
("age_range", self.age_range.to_tree_node()),
|
||||
("epoch", self.epoch.to_tree_node()),
|
||||
("min_age", self.min_age.to_tree_node()),
|
||||
("ge_amount", self.ge_amount.to_tree_node()),
|
||||
("amount_range", self.amount_range.to_tree_node()),
|
||||
("term", self.term.to_tree_node()),
|
||||
("type", self._type.to_tree_node()),
|
||||
("max_age", self.max_age.to_tree_node()),
|
||||
("lt_amount", self.lt_amount.to_tree_node()),
|
||||
]
|
||||
.into_iter()
|
||||
.map(|(name, node)| (name.to_string(), node))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
fn iter(&self) -> impl Iterator<Item = &dyn AnyCollectableVec> {
|
||||
let mut iter: Box<dyn Iterator<Item = &dyn AnyCollectableVec>> =
|
||||
Box::new(self.all.1.iter());
|
||||
iter = Box::new(iter.chain(IVecs::iter(&self.age_range)));
|
||||
iter = Box::new(iter.chain(self.epoch.iter()));
|
||||
iter = Box::new(iter.chain(self.min_age.iter()));
|
||||
iter = Box::new(iter.chain(IVecs::iter(&self.ge_amount)));
|
||||
iter = Box::new(iter.chain(IVecs::iter(&self.amount_range)));
|
||||
iter = Box::new(iter.chain(self.term.iter()));
|
||||
iter = Box::new(iter.chain(self._type.iter()));
|
||||
iter = Box::new(iter.chain(self.max_age.iter()));
|
||||
iter = Box::new(iter.chain(self.lt_amount.iter()));
|
||||
iter
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user