mod consistent;
pub mod hashes;
mod rendezvous;
pub use consistent::ConsistentRing;
use hashes::DefaultHasher;
pub use rendezvous::RendezvousRing;
pub type LightCycle<H = DefaultHasher> = ConsistentRing<H>;
pub type Recognizer<H = DefaultHasher> = RendezvousRing<H>;
pub type EndOfLine = LightCycleError;
pub trait HasId: std::fmt::Debug + Send + Sync {
fn id(&self) -> &str;
}
pub trait HashRing {
type Resource;
fn add(&mut self, resource: Self::Resource);
fn remove(&mut self, resource: &Self::Resource);
fn locate(&self, id: &str) -> Option<&Self::Resource>;
fn resource_count(&self) -> usize;
fn len(&self) -> usize;
fn is_empty(&self) -> bool;
fn add_weighted(&mut self, resource: Self::Resource, _weight: f64) {
self.add(resource);
}
fn update_weight(&mut self, _resource: &Self::Resource, _weight: f64) -> Result<(), EndOfLine> {
Err(EndOfLine::WeightsUnsupported)
}
}
#[derive(Debug, Clone, thiserror::Error)]
pub enum LightCycleError {
#[error("Resource {id} not found")]
NotFound { id: String },
#[error("Weight updates not supported by this hash ring implementation")]
WeightsUnsupported,
}