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>
impl<S: ArqStart> Arq<S>
sourcepub fn new(power: u8, start: S, count: SpaceOffset) -> Self
pub fn new(power: u8, start: S, count: SpaceOffset) -> Self
Constructor from individual parts
sourcepub fn absolute_length(&self, topo: &Topology) -> u64
pub fn absolute_length(&self, topo: &Topology) -> u64
The absolute length of the entire arq.
sourcepub fn to_dht_arc_range(&self, topo: &Topology) -> DhtArcRange
pub fn to_dht_arc_range(&self, topo: &Topology) -> DhtArcRange
Convert to DhtArcRange
sourcepub fn to_edge_locs(&self, topo: &Topology) -> (Loc, Loc)
pub fn to_edge_locs(&self, topo: &Topology) -> (Loc, Loc)
Determine the edges of this Arq in absolute coordinates (Loc
)
sourcepub fn coverage(&self, topo: &Topology) -> f64
pub fn coverage(&self, topo: &Topology) -> f64
What portion of the whole circle does this arq cover?
sourcepub fn requantize(&self, new_power: u8) -> Option<Self>
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§impl Arq<Loc>
impl Arq<Loc>
sourcepub fn new_full(topo: &Topology, start: Loc, power: u8) -> Self
pub fn new_full(topo: &Topology, start: Loc, power: u8) -> Self
Construct a full arq at the given power.
The count
is calculated accordingly.
sourcepub fn upshift(&self, force: bool) -> Option<Self>
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.
sourcepub fn to_dht_arc(&self, topo: &Topology) -> DhtArc
pub fn to_dht_arc(&self, topo: &Topology) -> DhtArc
Convert to DhtArc
source§impl Arq<SpaceOffset>
impl Arq<SpaceOffset>
sourcepub fn equivalent(topo: &Topology, a: &Self, b: &Self) -> bool
pub fn equivalent(topo: &Topology, a: &Self, b: &Self) -> bool
The two arqs represent the same interval despite having potentially different terms
sourcepub fn from_interval_rounded(
topo: &Topology,
power: u8,
interval: DhtArcRange
) -> (Self, bool)
pub fn from_interval_rounded( topo: &Topology, power: u8, interval: DhtArcRange ) -> (Self, bool)
Return the ArqBounds which most closely matches the given DhtArcRange
sourcepub fn from_interval(
topo: &Topology,
power: u8,
interval: DhtArcRange
) -> Option<Self>
pub fn from_interval( topo: &Topology, power: u8, interval: DhtArcRange ) -> Option<Self>
Return the ArqBounds which is equivalent to the given DhtArcRange
if it exists.
sourcepub fn to_arq<F: FnOnce(Loc) -> Loc>(&self, topo: &Topology, f: F) -> Arq
pub fn to_arq<F: FnOnce(Loc) -> Loc>(&self, topo: &Topology, f: F) -> Arq
Upcast this ArqBounds to an Arq that has knowledge of its Loc
sourcepub fn segments(&self) -> impl Iterator<Item = SpaceSegment> + '_
pub fn segments(&self) -> impl Iterator<Item = SpaceSegment> + '_
Iterate over each segment (chunk) in the Arq
sourcepub fn offset(&self) -> SpaceOffset
pub fn offset(&self) -> SpaceOffset
Get a reference to the arq bounds’s offset.
Trait Implementations§
source§impl<'de, S> Deserialize<'de> for Arq<S>where
S: Deserialize<'de> + ArqStart,
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>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl<S: PartialEq + ArqStart> PartialEq<Arq<S>> for Arq<S>
impl<S: PartialEq + ArqStart> PartialEq<Arq<S>> for Arq<S>
impl<S: Copy + ArqStart> Copy for Arq<S>
impl<S: Eq + ArqStart> Eq for Arq<S>
impl<S: ArqStart> StructuralEq for Arq<S>
impl<S: ArqStart> StructuralPartialEq for Arq<S>
Auto Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.