Beispiel #1
0
 private RootwardNode()
 {
     this.Parent         = this;
     this.SiblingOfChild = LeafwardNode.Nil;
     this.Data           = null;
     this.IsRed          = false;
 }
Beispiel #2
0
 public LeafwardNode(KeyVal data, bool isRed, LeafwardNode left, LeafwardNode right, Func <TAggregate, TKey, TVal, TAggregate, TAggregate> aggregator)
 {
     this.Data      = data;
     this.Left      = left;
     this.Right     = right;
     this.IsRed     = isRed;
     this.Aggregate = data == null ? default(TAggregate) : aggregator(left.Aggregate, data.Key, data.Val, right.Aggregate);
     this.Count     = data == null ? 0 : left.Count + 1 + right.Count;
 }
Beispiel #3
0
 public ZipperNode(KeyVal content, bool isRed, LeafwardNode left, LeafwardNode right, RootwardNode parent, Func <TAggregate, TKey, TVal, TAggregate, TAggregate> aggregator)
 {
     this.Data       = content;
     this.IsRed      = isRed;
     this.Left       = left;
     this.Right      = right;
     this.Parent     = parent;
     this.Aggregator = aggregator;
 }
Beispiel #4
0
 public ZipperNode(Func <TAggregate, TKey, TVal, TAggregate, TAggregate> aggregator)
 {
     this.Left       = LeafwardNode.Nil;
     this.Right      = LeafwardNode.Nil;
     this.Parent     = RootwardNode.Nil;
     this.Data       = null;
     this.IsRed      = false;
     this.Aggregator = aggregator;
 }
Beispiel #5
0
 public PersistentAggregatingRedBlackTree(Func <TAggregate, TKey, TVal, TAggregate, TAggregate> aggregator, IComparer <TKey> comparer = null)
 {
     if (aggregator == null)
     {
         throw new ArgumentNullException("aggregator");
     }
     this._root       = LeafwardNode.Nil;
     this._aggregator = aggregator;
     this._comparer   = comparer ?? Comparer <TKey> .Default;
 }
Beispiel #6
0
 public RootwardNode(KeyVal data, bool isRed, RootwardNode parent, LeafwardNode siblingOfChild, bool isLeft)
 {
     if (data == null)
     {
         throw new ArgumentNullException("data");
     }
     if (parent == null)
     {
         throw new ArgumentNullException("parent");
     }
     if (siblingOfChild == null)
     {
         throw new ArgumentNullException("siblingOfChild");
     }
     this.Data           = data;
     this.Parent         = parent;
     this.SiblingOfChild = siblingOfChild;
     this.IsChildOnLeft  = isLeft;
     this.IsRed          = isRed;
 }
Beispiel #7
0
        /// <summary>
        /// Rotates the tree, maintaining sorted order, such that the node p becomes the child of its child in the specified direction.
        /// The node p's direction from its new parent (former child) will be the opposite of the specified direction.
        /// The return value is the former child.
        /// </summary>
        public ZipperNode Rotate(bool toLeft)
        {
            // before
            //  -> v1
            //p=v2
            //     -> v3
            //  -> v4
            //     -> v5
            var p  = this;
            var n1 = p.Child(toLeft);
            var n2 = p;
            var n3 = p.Child(!toLeft).Child(toLeft);
            var n4 = p.Child(!toLeft);
            var n5 = p.Child(!toLeft).Child(!toLeft);

            // after
            //     -> v1
            //  -> v2
            //     -> v3
            //r=v4
            //  -> v5
            return(From(p.Parent, n4.Data, n4.IsRed, LeafwardNode.From(n2.Data, n2.IsRed, n1, n3, toLeft, Aggregator), n5, toLeft, Aggregator));
        }
Beispiel #8
0
 public static LeafwardNode From(KeyVal data, bool isRed, LeafwardNode c1, LeafwardNode c2, bool c1IsLeft, Func <TAggregate, TKey, TVal, TAggregate, TAggregate> aggregator)
 {
     return(new LeafwardNode(data, isRed, c1IsLeft ? c1 : c2, c1IsLeft ? c2 : c1, aggregator));
 }
Beispiel #9
0
 private PersistentAggregatingRedBlackTree(LeafwardNode root, Func <TAggregate, TKey, TVal, TAggregate, TAggregate> aggregator, IComparer <TKey> comparer)
 {
     this._root       = root;
     this._aggregator = aggregator;
     this._comparer   = comparer;
 }
Beispiel #10
0
 private LeafwardNode()
 {
     this.Left = this.Right = this;
 }
Beispiel #11
0
 public static ZipperNode From(RootwardNode parent, KeyVal content, bool isRed, LeafwardNode c1, LeafwardNode c2, bool c1IsLeft, Func <TAggregate, TKey, TVal, TAggregate, TAggregate> aggregator)
 {
     return(new ZipperNode(content, isRed, c1IsLeft ? c1 : c2, c1IsLeft ? c2 : c1, parent, aggregator));
 }