willow_data_model/grouping/area_of_interest.rs
1use crate::{grouping::area::Area, parameters::SubspaceId};
2
3/// A grouping of [`crate::Entry`]s that are among the newest in some [store](https://willowprotocol.org/specs/data-model/index.html#store).
4///
5/// [Definition](https://willowprotocol.org/specs/grouping-entries/index.html#aois).
6pub struct AreaOfInterest<const MCL: usize, const MCC: usize, const MPL: usize, S: SubspaceId> {
7 /// To be included in this [`AreaOfInterest`], an [`crate::Entry`] must be included in the [`Area`].
8 pub area: Area<MCL, MCC, MPL, S>,
9 /// To be included in this AreaOfInterest, an Entry’s timestamp must be among the max_count greatest Timestamps, unless max_count is zero.
10 pub max_count: u64,
11 /// The total payload_lengths of all included Entries is at most max_size, unless max_size is zero.
12 pub max_size: u64,
13}
14
15impl<const MCL: usize, const MCC: usize, const MPL: usize, S: SubspaceId>
16 AreaOfInterest<MCL, MCC, MPL, S>
17{
18 /// Return the intersection of this [`AreaOfInterest`] with another.
19 /// [Definition](https://willowprotocol.org/specs/grouping-entries/index.html#aoi_intersection).
20 pub fn intersection(
21 &self,
22 other: AreaOfInterest<MCL, MCC, MPL, S>,
23 ) -> Option<AreaOfInterest<MCL, MCC, MPL, S>> {
24 match self.area.intersection(&other.area) {
25 None => None,
26 Some(area_intersection) => Some(Self {
27 area: area_intersection,
28 max_count: core::cmp::min(self.max_count, other.max_count),
29 max_size: self.max_size.min(other.max_size),
30 }),
31 }
32 }
33}