Ejemplo n.º 1
0
 public static void MoveRight(this IMerkleTreePruningCursor cursor)
 {
     if (!cursor.TryMoveRight())
     {
         throw new InvalidOperationException();
     }
 }
Ejemplo n.º 2
0
 public static void MoveToIndex(this IMerkleTreePruningCursor cursor, int index)
 {
     if (!cursor.TryMoveToIndex(index))
     {
         throw new InvalidOperationException();
     }
 }
Ejemplo n.º 3
0
 public static void MoveRight <T>(this IMerkleTreePruningCursor <T> cursor)
     where T : IMerkleTreeNode <T>
 {
     if (!cursor.TryMoveRight())
     {
         throw new InvalidOperationException();
     }
 }
Ejemplo n.º 4
0
 public static void MoveToIndex <T>(this IMerkleTreePruningCursor <T> cursor, int index)
     where T : IMerkleTreeNode <T>
 {
     if (!cursor.TryMoveToIndex(index))
     {
         throw new InvalidOperationException();
     }
 }
Ejemplo n.º 5
0
        public CachedMerkleTreePruningCursor(IMerkleTreePruningCursor <T> parentCursor)
        {
            this.parentCursor = new ParentCursor(parentCursor);

            cachedNodes    = new Dictionary <int, T>();
            indicesToLeft  = new Dictionary <int, int?>();
            indicesToRight = new Dictionary <int, int?>();

            currentIndex = -1;
        }
        public CachedMerkleTreePruningCursor(IMerkleTreePruningCursor parentCursor)
        {
            this.parentCursor = parentCursor;

            this.cachedNodes    = new Dictionary <int, MerkleTreeNode>();
            this.indicesToLeft  = new Dictionary <int, int?>();
            this.indicesToRight = new Dictionary <int, int?>();

            this.parentCurrentIndex = -1;
            this.currentIndex       = -1;
        }
Ejemplo n.º 7
0
        public static void PruneNode <T>(IMerkleTreePruningCursor <T> cursor, int index)
            where T : IMerkleTreeNode <T>
        {
            if (!cursor.TryMoveToIndex(index))
            {
                return;
            }

            var node = cursor.ReadNode();

            if (node.Depth != 0)
            {
                return;
            }

            if (!node.Pruned)
            {
                node = node.AsPruned();
                cursor.WriteNode(node);
            }

            bool didWork;

            do
            {
                didWork = false;

                if (node.IsLeft())
                {
                    if (cursor.TryMoveRight())
                    {
                        var rightNode = cursor.ReadNode();
                        if (node.Pruned && rightNode.Pruned && node.Depth == rightNode.Depth)
                        {
                            var newNode = node.PairWith(rightNode);

                            cursor.DeleteNode();
                            //TODO cursor.MoveLeft();
                            cursor.WriteNode(newNode);

                            node    = newNode;
                            didWork = true;
                        }
                    }
                    else
                    {
                        if (node.Index != 0 && node.Pruned)
                        {
                            var newNode = node.PairWithSelf();
                            //cursor.MoveLeft();
                            cursor.WriteNode(newNode);

                            node    = newNode;
                            didWork = true;
                        }
                    }
                }
                else
                {
                    if (cursor.TryMoveLeft())
                    {
                        var leftNode = cursor.ReadNode();
                        if (node.Pruned && leftNode.Pruned && node.Depth == leftNode.Depth)
                        {
                            var newNode = leftNode.PairWith(node);
                            cursor.WriteNode(newNode);
                            cursor.MoveRight();
                            cursor.DeleteNode();
                            //TODO cursor.MoveLeft();

                            node    = newNode;
                            didWork = true;
                        }
                    }
                }
            }while (didWork);
        }
Ejemplo n.º 8
0
 public ParentCursor(IMerkleTreePruningCursor <T> pruningCursor)
 {
     this.pruningCursor = pruningCursor;
     currentIndex       = -1;
 }