[−][src]Struct hash_rings::maglev::Ring
A hashing ring implemented using maglev hashing.
Maglev hashing produces a lookup table that allows finding a node in constant time by generating random permutations.
Examples
use hash_rings::maglev::Ring; let ring = Ring::new(vec![&"node-1", &"node-2", &"node-3"]); assert_eq!(ring.get_node(&"point-1"), &"node-3"); assert_eq!(ring.nodes(), 3); assert_eq!(ring.capacity(), 307);
Methods
impl<'a, T> Ring<'a, T>
[src]
pub fn new(nodes: Vec<&'a T>) -> Self where
T: Hash,
[src]
T: Hash,
Constructs a new Ring<T>
with a specified list of nodes.
Examples
use hash_rings::maglev::Ring; let ring = Ring::new(vec![&"node-1", &"node-2", &"node-3"]);
pub fn with_capacity_hint(nodes: Vec<&'a T>, capacity_hint: usize) -> Self where
T: Hash,
[src]
T: Hash,
Constructs a new Ring<T>
with a specified list of nodes and a capacity hint. The actual
capacity of the ring will always be the next prime greater than or equal to
capacity_hint
. If nodes are removed and the ring is regenerated, the ring should be
rebuilt with the same capacity.
Examples
use hash_rings::maglev::Ring; let ring = Ring::with_capacity_hint(vec![&"node-1", &"node-2", &"node-3"], 100); assert_eq!(ring.capacity(), 101);
pub fn nodes(&self) -> usize
[src]
Returns the number of nodes in the ring.
Examples
use hash_rings::maglev::Ring; let ring = Ring::new(vec![&"node-1", &"node-2", &"node-3"]); assert_eq!(ring.nodes(), 3);
pub fn capacity(&self) -> usize
[src]
Returns the capacity of the ring. If nodes are removed and the ring is regenerated, the ring should be rebuilt with the same capacity.
Examples
use hash_rings::maglev::Ring; let ring = Ring::new(vec![&"node-1", &"node-2", &"node-3"]); assert_eq!(ring.capacity(), 307);
pub fn get_node<U>(&self, key: &U) -> &T where
U: Hash,
[src]
U: Hash,
Returns the node associated with a key.
Examples
use hash_rings::maglev::Ring; let ring = Ring::new(vec![&"node-1", &"node-2", &"node-3"]); assert_eq!(ring.get_node(&"point-1"), &"node-3");
pub fn iter(&'a self) -> impl Iterator<Item = &'a T>
[src]
Returns an iterator over the ring. The iterator will yield the nodes in the ring.
Examples
use hash_rings::maglev::Ring; let ring = Ring::new(vec![&"node-1", &"node-2", &"node-3"]); let mut iterator = ring.iter(); assert_eq!(iterator.next(), Some(&"node-1")); assert_eq!(iterator.next(), Some(&"node-2")); assert_eq!(iterator.next(), Some(&"node-3")); assert_eq!(iterator.next(), None);
Trait Implementations
impl<'a, T> IntoIterator for &'a Ring<'a, T> where
T: Hash + Eq,
[src]
T: Hash + Eq,
Auto Trait Implementations
impl<'a, T> Send for Ring<'a, T> where
T: Sync,
T: Sync,
impl<'a, T> Sync for Ring<'a, T> where
T: Sync,
T: Sync,
impl<'a, T> Unpin for Ring<'a, T>
impl<'a, T> UnwindSafe for Ring<'a, T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<'a, T> RefUnwindSafe for Ring<'a, T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,