Пример #1
0
        public void Insert(IRbNode newNode)
        {
            newNode.Color = Color.Red;

            var insertedNode = newNode;

            if (Root == null)
            {
                Root = insertedNode;
            }
            else
            {
                var n = Root;

                while (true)
                {
                    var compResult = newNode.CompareTo(n);

                    if (compResult == 0)
                    {
                        throw new RbTreeDuplicatedItemException(
                            "RBNode " + newNode + " already present in tree");
                    }

                    if (compResult < 0)
                    {
                        if (n.Left == null)
                        {
                            n.Left = insertedNode;

                            break;
                        }
                        n = n.Left;
                    }
                    else
                    {
                        //assert compResult > 0;
                        if (n.Right == null)
                        {
                            n.Right = insertedNode;

                            break;
                        }
                        n = n.Right;
                    }
                }

                insertedNode.Parent = n;
            }

            InsertCase1(insertedNode);
            NodeInserted?.Invoke(insertedNode);
        }
Пример #2
0
 void IEventSink.NotifyNodeAdded(DataNode node, int index)
 {
     NodeInserted?.Invoke(this, new TreeNodeEventArgs(node, index));
 }
Пример #3
0
 protected void ReportInsert(TKey key, TValue value)
 {
     Interlocked.CompareExchange(ref _inserts, 0, int.MaxValue);
     Interlocked.Increment(ref _inserts);
     NodeInserted?.Invoke(key, value);
 }