Esempio n. 1
0
        /// <summary>
        /// Remove exist node
        /// </summary>
        /// <param name="node">Node</param>
        public void RemoveNode(Node node)
        {
            Nodes.Remove(node.NodeID);

            for (int i = 0; i < vNodes; i++)
            {
                int token = Hash(node.GetHashCode().ToString() + i);
                if (!ring.Remove(token))
                {
                    throw new Exception("can not remove a node that not added");
                }
            }
            ayKeys = ring.Keys.ToArray();
        }
Esempio n. 2
0
        private void AddNode(Node node, bool updateKeyArray = false)
        {
            List <Token> tokens = new List <Token>();

            for (int i = 0; i < vNodes; i++)
            {
                int token = Hash(node.GetHashCode().ToString() + i);
                tokens.Add(new Token(token, node.NodeID));
                ring[token] = node;
            }

            if (updateKeyArray)
            {
                ayKeys = ring.Keys.ToArray();
            }

            node.AssignToken(tokens);
            Nodes.Add(node.NodeID, node);
        }