Documentation ¶
Index ¶
- func AddOne(key string) string
- func SubOne(key string) string
- type Ring
- func (ring *Ring) AddAsync(addChan <-chan *node.Node, complete chan<- *node.Node)
- func (ring *Ring) AddSync(node *node.Node)
- func (ring *Ring) Empty() bool
- func (ring *Ring) Get(key string) (*node.Node, bool)
- func (ring *Ring) Keys() []string
- func (ring *Ring) LookUp(key string) (*node.Node, error)
- func (ring *Ring) Predecessor(key string) (*node.Node, error)
- func (ring *Ring) RemoveAsync(removeChan <-chan *node.Node, complete chan<- *node.Node)
- func (ring *Ring) RemoveSync(node *node.Node)
- func (ring *Ring) Successor(key string) (*node.Node, error)
- func (ring *Ring) Values() []*node.Node
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Ring ¶
type Ring struct {
// contains filtered or unexported fields
}
The abstruct structure of consistent hash ring. It consists of a Red-Black-Tree serve as the ring.
func NewRing ¶
func NewRing() (ring *Ring)
Create a new consistent hashing ring with default value setting.
@return: pointer to new created consistent hashing ring
func (*Ring) AddAsync ¶
Add a new Node to consistent hashing ring.
@param addChan: incoming channel of Node pointer @param complete: outgoing channel of Node pointer, indicating
which Node has been added
func (*Ring) AddSync ¶
Add a new Node to consistent hashing ring. This function block the running routine until the Node is successfully added.
@param node: Node to be added
func (*Ring) Empty ¶
Check if the ring is empty/no node alive
@return: true if ring is empty otherwise false
func (*Ring) Get ¶
Get a Node given a specific key.
@param key: string of key @return: if key exists in tree, return the node and true, otherwise return
return nil and false
func (*Ring) Keys ¶
Get all keys in the ring in ascending order
@return: all keys in ascending order
func (*Ring) LookUp ¶
Lookup for a Node in consistent hashing ring given a key. If the input key is the same as some Node's key, then the result is that exact Node.
@param key: string of key @return: return the node if such successor founded, otherwise an error is
given
func (*Ring) Predecessor ¶
Get predecessor of a given key(this key is supposed to belong to a Node)
@param key: string of key @return: return the node if such predecessor founded, otherwise an error is
given
func (*Ring) RemoveAsync ¶
Remove a Node from consistent hashing ring.
@param removeChan: incoming channel of Node pointer @param complete: outgoing channel of Node pointer, indicating
which Node has been removed
func (*Ring) RemoveSync ¶
Remove a new Node to consistent hashing ring. This function block the running routine until the Node is successfully removed.
@param node: Node to be removed