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());

Return the position of the key within the ring.

Examples

use conflictdb::CKey;

let k = CKey::new_half();
assert_eq!(0.5, k.ring_pos());

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.