[][src]Struct hash_rings::maglev::Ring

pub struct Ring<'a, T> { /* fields omitted */ }

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]

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]

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]

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]

type IntoIter = Box<dyn Iterator<Item = &'a T> + 'a>

Which kind of iterator are we turning this into?

type Item = &'a T

The type of the elements being iterated over.

Auto Trait Implementations

impl<'a, T> Send for Ring<'a, T> where
    T: Sync

impl<'a, T> Sync for Ring<'a, T> where
    T: Sync

impl<'a, T> Unpin for Ring<'a, T>

impl<'a, T> UnwindSafe for Ring<'a, T> where
    T: RefUnwindSafe

impl<'a, T> RefUnwindSafe for Ring<'a, T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]