ArcSet

Struct ArcSet 

Source
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

Source

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.

Source

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());
Source

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());
Source

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.

Source

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.

Source

pub fn includes_sector_index(&self, value: u32) -> bool

Check whether a given sector index is included in this arc set.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for ArcSet

Source§

fn clone(&self) -> ArcSet

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ArcSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ArcSet

Source§

fn eq(&self, other: &ArcSet) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for ArcSet

Auto Trait Implementations§

§

impl Freeze for ArcSet

§

impl RefUnwindSafe for ArcSet

§

impl Send for ArcSet

§

impl Sync for ArcSet

§

impl Unpin for ArcSet

§

impl UnwindSafe for ArcSet

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more