Struct kitsune_p2p_dht::arq::Arq

source ·
pub struct Arq<S: ArqStart = Loc> {
    pub start: S,
    pub power: u8,
    pub count: SpaceOffset,
}
Expand description

A quantized DHT arc.

§Coordinates

Arq coordinates are expressed in terms of powers-of-two, representing the “chunk” or “segment” size to work with. The chunk size is determined by the Topology of the space it is in, as well as the power of the Arq. The actual chunk size is given by:

chunk size = topology.space.quantum * 2^power

So, the power represents the amount of quantization on top of the quantum size set by the Topology, not the total quantization level.

The start is generic, because there are actually two flavors of Arq:

  • one which has a definite starting DhtLocation associated with it,
  • and one which does not.

The first flavor is used to represent Arqs which belong to Agents. It’s important to record the actual absolute Location of the Arq, because the exact location determines the starting Chunk when requantizing to higher and lower levels.

The second flavor is mainly used to represent the intersections and unions of Arqs. In this case, there is no definite location associated, so we want to forget about the original Location data associated with each Arq.

Fields§

§start: S

The “start” defines the left edge of the arq

§power: u8

The level of quantization. Total length is 2^power * count. The power must be between 0 and 31, inclusive (power of 32 causes overflow)

§count: SpaceOffset

The number of unit lengths. We never expect the count to be less than 4 or so, and not much larger than 32.

Implementations§

source§

impl<S: ArqStart> Arq<S>

source

pub fn new(power: u8, start: S, count: SpaceOffset) -> Self

Constructor from individual parts

source

pub fn absolute_length(&self, dim: impl SpaceDim) -> u64

The absolute length of the entire arq.

source

pub fn to_dht_arc_range_std(&self) -> DhtArcRange

Convert to DhtArcRange using standard topology

source

pub fn to_dht_arc_range(&self, dim: impl SpaceDim) -> DhtArcRange

Convert to DhtArcRange

source

pub fn to_edge_locs(&self, dim: impl SpaceDim) -> (Loc, Loc)

Determine the edges of this Arq in absolute coordinates (Loc)

source

pub fn power(&self) -> u8

Accessor

source

pub fn count(&self) -> u32

Accessor

source

pub fn coverage(&self, dim: impl SpaceDim) -> f64

What portion of the whole circle does this arq cover?

source

pub fn requantize(&self, new_power: u8) -> Option<Self>

Requantize to a different power. If requantizing to a higher power, only requantize if there is no information loss due to rounding. Otherwise, return None.

source

pub fn new_full(dim: impl SpaceDim, start: S, power: u8) -> Self

Construct a full arq at the given power. The count is calculated accordingly.

source

pub fn new_full_max(dim: impl SpaceDim, strat: &ArqStrat, start: S) -> Self

Construct a full arq at the maximum power.

source

pub fn is_full(&self, dim: impl SpaceDim) -> bool

This arq has full coverage

source

pub fn is_empty(&self) -> bool

This arq has zero coverage

source§

impl Arq<Loc>

source

pub fn new_empty(dim: impl SpaceDim, start: Loc) -> Self

Construct an empty arq (count = 0) at the minimum power.

source

pub fn downshift(&self) -> Self

Reduce the power by 1

source

pub fn upshift(&self, force: bool) -> Option<Self>

Increase the power by 1. If this results in rounding, return None, unless force is true, in which case always return Some.

source

pub fn to_bounds_std(&self) -> ArqBounds

Convert to the ArqBounds representation, which forgets about the Loc associated with this arq. Uses standard topology.

source

pub fn to_bounds(&self, dim: impl SpaceDim) -> ArqBounds

Convert to the ArqBounds representation, which forgets about the Loc associated with this arq.

source

pub fn start_loc(&self) -> Loc

Get a reference to the arq’s left edge in absolute coordinates.

source

pub fn count_mut(&mut self) -> &mut u32

Get a mutable reference to the arq’s count.

source

pub fn to_dht_arc(&self, dim: impl SpaceDim) -> DhtArc

Convert to DhtArc

source

pub fn to_dht_arc_std(&self) -> DhtArc

Convert to DhtArc using the standard SpaceDimension

source

pub fn from_dht_arc_approximate( dim: impl SpaceDim, strat: &ArqStrat, dht_arc: &DhtArc ) -> Self

Computes the Arq which most closely matches the given DhtArc

source

pub fn equivalent(dim: impl SpaceDim, a: &Self, b: &Self) -> bool

The two arqs represent the same interval despite having potentially different terms

source

pub fn from_start_and_half_len_approximate( dim: impl SpaceDim, strat: &ArqStrat, start: Loc, half_len: u32 ) -> Self

Computes the Arq which most closely matches the given params

source§

impl Arq<SpaceOffset>

source

pub fn equivalent(dim: impl SpaceDim, a: &Self, b: &Self) -> bool

The two arqs represent the same interval despite having potentially different terms

source

pub fn from_interval_rounded( dim: impl SpaceDim, power: u8, interval: DhtArcRange ) -> (Self, bool)

Return the ArqBounds which most closely matches the given DhtArcRange

source

pub fn from_interval( dim: impl SpaceDim, power: u8, interval: DhtArcRange ) -> Option<Self>

Return the ArqBounds which is equivalent to the given DhtArcRange if it exists.

source

pub fn empty(dim: impl SpaceDim, power: u8) -> Self

An arbitrary zero-coverage arq.

source

pub fn segments(&self) -> impl Iterator<Item = SpaceSegment> + '_

Iterate over each segment (chunk) in the Arq

source

pub fn offset(&self) -> SpaceOffset

Get a reference to the arq bounds’s offset.

Trait Implementations§

source§

impl<S: Clone + ArqStart> Clone for Arq<S>

source§

fn clone(&self) -> Arq<S>

Returns a copy 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<S: Debug + ArqStart> Debug for Arq<S>

source§

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

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

impl<'de, S> Deserialize<'de> for Arq<S>
where S: Deserialize<'de> + ArqStart,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<&Arq<SpaceOffset>> for ArqBounds

source§

fn from(a: &ArqBounds) -> Self

Converts to this type from the input type.
source§

impl From<Arq> for ArqSize

source§

fn from(arq: Arq) -> Self

Converts to this type from the input type.
source§

impl<S: Hash + ArqStart> Hash for Arq<S>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<S: PartialEq + ArqStart> PartialEq for Arq<S>

source§

fn eq(&self, other: &Arq<S>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<S> Serialize for Arq<S>
where S: Serialize + ArqStart,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<S: Copy + ArqStart> Copy for Arq<S>

source§

impl<S: Eq + ArqStart> Eq for Arq<S>

source§

impl<S: ArqStart> StructuralPartialEq for Arq<S>

Auto Trait Implementations§

§

impl<S> Freeze for Arq<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for Arq<S>
where S: RefUnwindSafe,

§

impl<S> Send for Arq<S>
where S: Send,

§

impl<S> Sync for Arq<S>
where S: Sync,

§

impl<S> Unpin for Arq<S>
where S: Unpin,

§

impl<S> UnwindSafe for Arq<S>
where S: UnwindSafe,

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> 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> Same for T

§

type Output = T

Should always be Self
source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

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

§

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>,

§

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>,

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

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
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,