pub enum DhtArc {
Empty,
Arc(u32, u32),
}Expand description
The definition of a storage arc compatible with the concept of storage and querying of items in a store that fall within that arc.
Variants§
Empty
No DHT locations are contained within this arc.
Arc(u32, u32)
A specific range of DHT locations are contained within this arc.
The lower and upper bounds are inclusive.
Implementations§
Source§impl DhtArc
impl DhtArc
Sourcepub fn dist(&self, loc: u32) -> u32
pub fn dist(&self, loc: u32) -> u32
Get the min distance from a location to an arc in a wrapping u32 space. This function will only return 0 if the location is covered by the arc. This function will return u32::MAX if the arc is empty.
All possible cases:
s = arc_start
e = arc_end
l = location
Arc wraps around, loc >= arc_start
|----e-----------s--l--|
0 u32::MAX
Arc wraps around, loc <= arc_end
|-l--e-----------s-----|
0 u32::MAX
Arc wraps around, loc outside of arc
|----e----l------s-----|
0 u32::MAX
Arc does not wrap around, loc inside of arc
|---------s--l---e-----|
0 u32::MAX
Arc does not wrap around, loc < arc_start
|-----l---s------e-----|
0 u32::MAX
Arc does not wrap around, loc > arc_end
|---------s------e--l--|
0 u32::MAXSourcepub fn contains(&self, loc: u32) -> bool
pub fn contains(&self, loc: u32) -> bool
Convenience function to determine if a location is contained within the arc.
Simply checks whether the distance from the location to the arc is 0.
Sourcepub fn overlaps(&self, other: &DhtArc) -> bool
pub fn overlaps(&self, other: &DhtArc) -> bool
Determine if any part of two arcs overlap.
All possible cases (though note the arcs can also wrap around u32::MAX):
a = a_start
A = a_end
b = b_start
B = b_end
The tail of a..A overlaps the head of b..B
|---a--b-A--B---|
The tail of b..B overlaps the head of a..A
|---b--a-B--A---|
b..B is fully contained by a..A
|---a--b-B--A---|
a..A is fully contained by b..B
|---b--a-A--B---|