Struct conflictdb::CKey [−][src]
pub struct CKey { /* fields omitted */ }
Expand description
CKey implements a consistent hask key. Theory here: https://en.wikipedia.org/wiki/Consistent_hashing
Examples
use conflictdb::CKey;
let k1 = CKey::new_rand();
let k2 = k1.next();
print!("k1:{} k2:{}\n", k1, k2);
Implementations
Make a digest from data and returns a new key from it. Typical usage is to create a a CKey from a string or an object content.
Examples
use conflictdb::CKey;
let k = CKey::new_digest("/a/unique/path");
assert_eq!("3b818742b0f27cfc10f4de1e5ba5594c975d580c412a31011ad58d36a2b17cdc", format!("{}",k));
Generate a random key. This can be time consuming as it is using the OS random generation, which is better from a cryptographic point of view, but possibly slower than a standard prng.
Examples
use conflictdb::CKey;
let k = CKey::new_rand();
print!("k: {}", k);
Generate a key with the value 0.
Examples
use conflictdb::CKey;
let k = CKey::new_zero();
assert_eq!("0000000000000000000000000000000000000000000000000000000000000000", format!("{}", k));
Generate a key with the value 1, the smallest key possible just after zero.
Examples
use conflictdb::CKey;
let k = CKey::new_unit();
assert_eq!("0000000000000000000000000000000000000000000000000000000000000001", format!("{}", k));
Generate a key with the last, highest possible value.
Examples
use conflictdb::CKey;
let k = CKey::new_last();
assert_eq!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", format!("{}", k));
Generate a key which is exactly in the middle of the ring.
Examples
use conflictdb::CKey;
let k = CKey::new_half();
assert_eq!("8000000000000000000000000000000000000000000000000000000000000000", format!("{}", k));
Returns true if self is inside lower and upper. Lower limit is excluded, upper is included. This is typically used in a ring to know if a given key is handled by a node. You would ask if key is inside previous node (lower) and this node (upper) and if true -> yes, this is the right node to handle it.
Examples
use conflictdb::CKey;
let k1 = CKey::from(0.1);
let k2 = CKey::from(0.3);
let k3 = CKey::from(0.9);
assert!(k2.inside(k1, k3));
Increment current key by one.
Examples
use conflictdb::CKey;
let mut k = CKey::new_zero();
k.incr();
assert_eq!(CKey::new_unit(), k);
Decrement current key by one.
Examples
use conflictdb::CKey;
let mut k = CKey::new_zero();
k.decr();
assert_eq!(CKey::new_last(), k);
Return current key plus one.
Examples
use conflictdb::CKey;
let k = CKey::new_zero();
assert_eq!(CKey::new_unit(), k.next());
Return current key minus one.
Examples
use conflictdb::CKey;
let k = CKey::new_zero();
assert_eq!(CKey::new_last(), k.prev());
Return a short ID in an u64. Only the lower 60 bits are used.
Examples
use conflictdb::CKey;
let k = CKey::from(0.03);
assert_eq!("007ae147ae147ae0", format!("{:016x}", k.short_id_u64()));
Return a short ID in an u32. Only the lower 28 bits are used.
Examples
use conflictdb::CKey;
let k = CKey::from(0.03);
assert_eq!("007ae147", format!("{:08x}", k.short_id_u32()));
Return a short ID in a string. Only 7 chars (28 bits).
Examples
use conflictdb::CKey;
let k = CKey::from(0.03);
assert_eq!("07ae147", k.short_id_str());
Trait Implementations
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
impl RefUnwindSafe for CKey
impl UnwindSafe for CKey
Blanket Implementations
Mutably borrows from an owned value. Read more