Ejemplo n.º 1
0
        // Return the delta from the point where the specified tree was created
        public IEnumerable <TItem> DeltaSince(ListTree <TItem> tree)
        {
            if (ReferenceEquals(tree, null))
            {
                return(null);
            }

            if (ReferenceEquals(tree, this))
            {
                return(Delta);
            }

            IEnumerable <TItem> delta = null;

            bool found       = false;
            int  branchPoint = SequenceNumber;

            for (var t = this; t != null && !found; t = t.Parent)
            {
                delta = delta != null?t.DeltaTo(branchPoint).Concat(delta) : t.DeltaTo(branchPoint);

                branchPoint = t.ParentBranchEntry;
                found       = t == tree;
            }
            return(found ? delta : null);
        }
Ejemplo n.º 2
0
        public ListTree <TItem> LowestCommonAncestor(ListTree <TItem> parent)
        {
            // Get all ancestors of each PowerHistory log
            var ancestorsA = new Stack <ListTree <TItem> >();
            var ancestorsB = new Stack <ListTree <TItem> >();

            for (var tree = this; tree != null; tree = tree.Parent)
            {
                ancestorsA.Push(tree);
            }
            for (var tree = parent; tree != null; tree = tree.Parent)
            {
                ancestorsB.Push(tree);
            }

            // Search from root game to find lowest common ancestor of each game
            // TODO: This also needs to work when there is no LCA
            ListTree <TItem> lca = null;

            foreach (var pair in ancestorsA.Zip(ancestorsB, (x, y) => new { A = x, B = y }))
            {
                if (pair.A != pair.B)
                {
                    break;
                }
                else
                {
                    lca = pair.A;
                }
            }
            return(lca);
        }
Ejemplo n.º 3
0
 public ListTree(ListTree <TItem> parent = null)
 {
     if (parent != null)
     {
         Parent            = parent;
         SequenceNumber    = Parent.SequenceNumber;
         ParentBranchEntry = SequenceNumber;
     }
     else
     {
         Parent            = null;
         SequenceNumber    = 0;
         ParentBranchEntry = 0;
     }
 }