Skip to main content

Ring

Struct Ring 

Source
pub struct Ring<M: Ord + Clone> { /* private fields */ }
Expand description

a ring of tokens; M names a member (an address, a backend)

Implementations§

Source§

impl<M: Ord + Clone> Ring<M>

Source

pub fn new() -> Ring<M>

Source

pub fn add(&mut self, m: M, key: &str, vnodes: u32)

adds a member with vnodes tokens made from key (a member that is there already gets its tokens again)

Source

pub fn remove(&mut self, m: &M) -> bool

removes a member and its tokens

Source

pub fn members(&self) -> &[M]

the members, sorted

Source

pub fn tokens(&self) -> &[(u64, M)]

the tokens with their members, sorted by token

Source

pub fn is_empty(&self) -> bool

Source

pub fn owner(&self, h: u64) -> Option<&M>

the member a hash belongs to

Source

pub fn preference(&self, h: u64, n: usize) -> Vec<M>

the first n distinct members from h on, in ring order

Source

pub fn preference_by(&self, h: u64, n: usize, ok: impl Fn(&M) -> bool) -> Vec<M>

the first n distinct members from h on that ok accepts

Source

pub fn shares(&self) -> Vec<(M, u32)>

the part of the hash space each member owns, in parts per million (sorted by member)

Trait Implementations§

Source§

impl<M: Clone + Ord + Clone> Clone for Ring<M>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<M: Debug + Ord + Clone> Debug for Ring<M>

Source§

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

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

impl<M: Ord + Clone> Default for Ring<M>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<M: Eq + Ord + Clone> Eq for Ring<M>

Source§

impl<M: PartialEq + Ord + Clone> PartialEq for Ring<M>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<M: PartialEq + Ord + Clone> StructuralPartialEq for Ring<M>

Auto Trait Implementations§

§

impl<M> Forget for Ring<M>

§

impl<M> Freeze for Ring<M>
where Vec<(u64, M)>: Freeze, Vec<M>: Freeze,

§

impl<M> RefUnwindSafe for Ring<M>

§

impl<M> Send for Ring<M>
where Vec<(u64, M)>: Send, Vec<M>: Send,

§

impl<M> Sync for Ring<M>
where Vec<(u64, M)>: Sync, Vec<M>: Sync,

§

impl<M> Unpin for Ring<M>
where Vec<(u64, M)>: Unpin, Vec<M>: Unpin,

§

impl<M> UnsafeUnpin for Ring<M>
where Vec<(u64, M)>: UnsafeUnpin, Vec<M>: UnsafeUnpin,

§

impl<M> UnwindSafe for Ring<M>
where Vec<(u64, M)>: UnwindSafe, Vec<M>: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.