public static void MoveRight(this IMerkleTreePruningCursor cursor) { if (!cursor.TryMoveRight()) { throw new InvalidOperationException(); } }
public static void MoveToIndex(this IMerkleTreePruningCursor cursor, int index) { if (!cursor.TryMoveToIndex(index)) { throw new InvalidOperationException(); } }
public static void MoveRight <T>(this IMerkleTreePruningCursor <T> cursor) where T : IMerkleTreeNode <T> { if (!cursor.TryMoveRight()) { throw new InvalidOperationException(); } }
public static void MoveToIndex <T>(this IMerkleTreePruningCursor <T> cursor, int index) where T : IMerkleTreeNode <T> { if (!cursor.TryMoveToIndex(index)) { throw new InvalidOperationException(); } }
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; }
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); }
public ParentCursor(IMerkleTreePruningCursor <T> pruningCursor) { this.pruningCursor = pruningCursor; currentIndex = -1; }