/
IConsistentHashRing.cs
45 lines (40 loc) · 1.59 KB
/
IConsistentHashRing.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
namespace ConsistentHashing
{
using System;
using System.Collections.Generic;
/// <summary>
/// Represents a consistent hash ring.
/// </summary>
/// <typeparam name="TNode">The type of node to store in the ring.</typeparam>
public interface IConsistentHashRing<TNode> : IEnumerable<(TNode, uint)>
where TNode : IComparable<TNode>
{
/// <summary>
/// Gets all partitions where a partition is a hash range and the owner node.
/// </summary>
/// <value>An enumeration of all the partitions defined by the hash ring.</value>
IEnumerable<Partition<TNode>> Partitions { get; }
/// <summary>
/// Gets whether the consistent hash ring is empty or not.
/// </summary>
/// <value>True if the ring is empty and false otherwise.</value>
bool IsEmpty { get; }
/// <summary>
/// Adds the specified node to the hash ring at the specified point.
/// </summary>
/// <param name="node">The node to add.</param>
/// <param name="point">The point at which to add the node to.</param>
void AddNode(TNode node, uint point);
/// <summary>
/// Removes all instances of the node from the hash ring.
/// </summary>
/// <param name="node">The node to remove.</param>
void RemoveNode(TNode node);
/// <summary>
/// Gets the node that owns the hash.
/// </summary>
/// <param name="hash">The hash.</param>
/// <returns>The node that owns the hash.</returns>
TNode GetNode(uint hash);
}
}