pub struct ArcSet { /* private fields */ }Expand description
Represents a set of DhtArcs.
A set of DhtArcs is combined as a set union into an ArcSet.
To restrict crate::dht::Dht operations to a specific set of sectors, the ArcSets of two DHTs can be intersected to find the common sectors, using ArcSet::intersection.
Implementations§
Source§impl ArcSet
impl ArcSet
Sourcepub fn new(arcs: Vec<DhtArc>) -> K2Result<Self>
pub fn new(arcs: Vec<DhtArc>) -> K2Result<Self>
Create a new arc set from a list of arcs.
The resulting arc set represents the union of the input arcs.
Sourcepub fn intersection(&self, other: &Self) -> Self
pub fn intersection(&self, other: &Self) -> Self
Get the intersection of two arc sets as a new ArcSet.
§Example
use kitsune2_api::DhtArc;
use kitsune2_dht::{ArcSet, SECTOR_SIZE};
let arc_1 = DhtArc::Arc(0, 2 * SECTOR_SIZE - 1);
let arc_set_1 = ArcSet::new(vec![arc_1])?;
let arc_2 = DhtArc::Arc(SECTOR_SIZE, 4 * SECTOR_SIZE - 1);
let arc_set_2 = ArcSet::new(vec![arc_2])?;
assert_eq!(1, arc_set_1.intersection(&arc_set_2).covered_sector_count());Sourcepub fn covered_sector_count(&self) -> usize
pub fn covered_sector_count(&self) -> usize
The number of sectors covered by this arc set.
§Example
use kitsune2_api::DhtArc;
use kitsune2_dht::{ArcSet, SECTOR_SIZE};
let arc_1 = DhtArc::Arc(0, 2 * SECTOR_SIZE - 1);
let arc_2 = DhtArc::Arc(2 * SECTOR_SIZE, 4 * SECTOR_SIZE - 1);
let arc_set = ArcSet::new(vec![arc_1, arc_2])?;
assert_eq!(4, arc_set.covered_sector_count());Sourcepub fn encode(&self) -> Vec<u32>
pub fn encode(&self) -> Vec<u32>
Encode this arc set into a compressed format for transmission.
The encoding is a simple bitset where each bit represents a sector.
Sourcepub fn decode(input: &[u32]) -> K2Result<Self>
pub fn decode(input: &[u32]) -> K2Result<Self>
Decode an arc set from a compressed format.
See the ArcSet::encode method for details on the encoding format.
Sourcepub fn includes_sector_index(&self, value: u32) -> bool
pub fn includes_sector_index(&self, value: u32) -> bool
Check whether a given sector index is included in this arc set.
Sourcepub fn without_sector_indices(
self,
remove: impl IntoIterator<Item = u32>,
) -> Self
pub fn without_sector_indices( self, remove: impl IntoIterator<Item = u32>, ) -> Self
Remove the given sector indices from this arc set.
Note that this is a mutable operation, which is normally not needed for arc sets. This function therefore consumes the provided arc set to make it harder to accidentally modify an arc set that wasn’t intended to be updated.
Sourcepub fn as_arcs(&self) -> Vec<DhtArc>
pub fn as_arcs(&self) -> Vec<DhtArc>
Convert an arc set to a list of arcs.
Note that an ArcSet is created from a Vec<DhtArc>, so if you have just created an
ArcSet then this should return an equivalent list of arcs to what you provided, though
not necessarily the same list. E.g. ArcSet::new(vec![DhtArc::FULL, DhtArc::FULL]) will
return vec![DhtArc::FULL].
This method is intended to be used after taking an intersection with ArcSet::intersection. In that case, the list of arcs is not known and converting to a list of arcs is useful.