use std::collections::BTreeMap;
use crate::NodeIdT;
#[derive(Clone, Debug)]
pub struct Batch<C, N> {
pub epoch: u64,
pub contributions: BTreeMap<N, C>,
}
impl<C, N: NodeIdT> Batch<C, N> {
pub fn iter<'a>(&'a self) -> impl Iterator<Item = <&'a C as IntoIterator>::Item>
where
&'a C: IntoIterator,
{
self.contributions.values().flat_map(|item| item)
}
pub fn into_tx_iter(self) -> impl Iterator<Item = <C as IntoIterator>::Item>
where
C: IntoIterator,
{
self.contributions.into_iter().flat_map(|(_, vec)| vec)
}
pub fn len<T>(&self) -> usize
where
C: AsRef<[T]>,
{
self.contributions
.values()
.map(C::as_ref)
.map(<[T]>::len)
.sum()
}
pub fn is_empty<T>(&self) -> bool
where
C: AsRef<[T]>,
{
self.contributions
.values()
.map(C::as_ref)
.all(<[T]>::is_empty)
}
}