pub struct Continuum { /* private fields */ }Expand description
Sorted-by-server-order continuum.
§Examples
use dynomite::hashkit::modula::{Continuum, ServerSpec};
let c = Continuum::build(&[ServerSpec { name: "a".into(), weight: 2 }]).unwrap();
assert_eq!(c.len(), 2);Implementations§
Source§impl Continuum
impl Continuum
Sourcepub fn build(servers: &[ServerSpec]) -> Result<Self, DynError>
pub fn build(servers: &[ServerSpec]) -> Result<Self, DynError>
Build the continuum from servers. Every server contributes
weight consecutive slots in declaration order.
§Errors
Currently never fails; the signature returns Result so the
distribution interface stays consistent with ketama.
§Examples
use dynomite::hashkit::modula::{Continuum, ServerSpec};
let c = Continuum::build(&[
ServerSpec { name: "a".into(), weight: 3 },
ServerSpec { name: "b".into(), weight: 1 },
]).unwrap();
assert_eq!(c.len(), 4);Sourcepub fn slots(&self) -> &[Slot]
pub fn slots(&self) -> &[Slot]
Read-only view of the slots in their canonical order.
§Examples
use dynomite::hashkit::modula::{Continuum, ServerSpec};
let c = Continuum::build(&[ServerSpec { name: "a".into(), weight: 2 }]).unwrap();
assert_eq!(c.slots().len(), 2);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of slots.
§Examples
use dynomite::hashkit::modula::Continuum;
assert_eq!(Continuum::default().len(), 0);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the continuum is empty.
§Examples
use dynomite::hashkit::modula::Continuum;
assert!(Continuum::default().is_empty());Sourcepub fn dispatch(&self, hash: u32) -> Result<usize, DynError>
pub fn dispatch(&self, hash: u32) -> Result<usize, DynError>
Map a 32-bit hash to a server index using hash % len.
§Errors
Returns an error when the continuum is empty.
§Examples
use dynomite::hashkit::modula::{Continuum, ServerSpec};
let c = Continuum::build(&[
ServerSpec { name: "a".into(), weight: 1 },
ServerSpec { name: "b".into(), weight: 1 },
]).unwrap();
assert_eq!(c.dispatch(2).unwrap(), 0);
assert_eq!(c.dispatch(3).unwrap(), 1);Trait Implementations§
Auto Trait Implementations§
impl Freeze for Continuum
impl RefUnwindSafe for Continuum
impl Send for Continuum
impl Sync for Continuum
impl Unpin for Continuum
impl UnsafeUnpin for Continuum
impl UnwindSafe for Continuum
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
Mutably borrows from an owned value. Read more