示例#1
0
        private bool Add(Node node, bool raiseNodeAdded)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            var bucket = Buckets.Find(b => b.CanContain(node));

            if (bucket.Nodes.Contains(node))
            {
                return(false);
            }

            var added = bucket.Add(node);

            if (added && raiseNodeAdded)
            {
                RaiseNodeAdded(node);
            }

            if (!added && bucket.CanContain(LocalNode))
            {
                if (Split(bucket))
                {
                    return(Add(node, raiseNodeAdded));
                }
            }

            return(added);
        }