Exemple #1
0
        public bool RemoveNode(TNode node)
        {
            var nodeHash = GetHash(node.ToString());

            if (!_nodes.ContainsKey(nodeHash))
            {
                return(false);
            }

            var replicasHashes = GetReplicasHashes(node);

            foreach (var replicas in replicasHashes)
            {
                if (!_nodesMap.ContainsKey(replicas))
                {
                    continue;
                }

                _nodesMap.Remove(replicas);
                RingHashes.Remove(replicas);
            }

            _nodes.Remove(nodeHash);
            _ringHashArray = RingHashes.OrderBy(i => i).ToArray();

            return(true);
        }
Exemple #2
0
        public bool AddNode(TNode node)
        {
            var nodeHash = GetHash(node.ToString());

            if (_nodes.ContainsKey(nodeHash))
            {
                return(false);
            }

            var replicasHashes = GetReplicasHashes(node);

            _nodes.Add(nodeHash, node);

            foreach (var replicas in replicasHashes)
            {
                _nodesMap.Add(replicas, nodeHash);
                RingHashes.Add(replicas);
            }

            _ringHashArray = RingHashes.OrderBy(i => i).ToArray();

            return(true);
        }