HighestRandomWeightHash<TKey, TBucket>
Namespace: SnowBank.IO.Hashing · class
Uses the the Highest Random Weight Hashing strategy (HRW, also called Rendezvous Hashing) to deterministically choose a TBucket for any TKey
Constructors
HighestRandomWeightHash<TKey, TBucket>
HighestRandomWeightHash<TKey, TBucket>(IEnumerable<(TBucket, ulong, double)> buckets, Func<ulong, TKey, ulong> kf)
Create a HRW Hasher using a list of weighted Buckets (with already computed Seed)
HighestRandomWeightHash<TKey, TBucket>(IEnumerable<TBucket> buckets, Func<ulong, TKey, ulong> kf, Func<TBucket, ulong> nf, ulong seed = 0)
Create a HRW Hasher using a list of Buckets
All nodes will use weight = 1.0
HighestRandomWeightHash<TKey, TBucket>(IEnumerable<(TBucket, double)> buckets, Func<ulong, TKey, ulong> kf, Func<TBucket, ulong> nf, ulong seed = 0)
Create a HRW Hasher using a list of weighted Buckets
Properties
Count
int Count { get; }
Return the number of buckets available
HashFunction
Func<ulong, TKey, ulong> HashFunction { get; }
Hash function used to compute the score
HF(BUCKET_SEED, KEY) => 0..ulong.MaxValue
Methods
Choose
TBucket Choose(TKey key)
Choose the best bucket for the given key
Returns: Bucket with the highest score for this key
ChooseMultiple
TBucket[] ChooseMultiple(TKey key, int n)
Choose the first n server responsible for a given key, in descending priority
n— Number of servers to select (>= 1)
Returns: Array of length up to n with the first server, then the second and so on. If n is larger than the number of buckets, then all the buckets will be returned.
(key, 1) is equivalent to calling (key), and (key, Buckets.Count) is equivalent to calling (key).ToArray()
RankBy
IEnumerable<TBucket> RankBy(TKey key)
Rank all buckets for a key, from the highest score to the lowest score
Returns the list of all buckets from the highest to the lowest
Top 3 server: List
Secondary server:BUCKET secondary = hrw.RankBy(KEY).Skip(1).FirstOrDefault();
Score
IEnumerable<(TBucket, double)> Score(TKey key)
Compute and return the score of all buckets for a given key
Returns: Unordered list of (Bucket, Score) for this key