Пример #1
0
 public void updateLeafData(int index, Indexable b) {
   // Check to see if we need to grow tree
   if (index <= root.max) {
     // node already exists, simply update
     store.set(index, b);
     MerkleTreeNode node = nodeMap.get(index);
     MerkleTreeNode newNode = new MerkleTreeNode(b.getBytes(), index);
     newNode.parent = node.parent;
     if (newNode.parent.leftChild == node) {
       newNode.parent.leftChild = newNode;
     } else {
       newNode.parent.rightChild = newNode;
     }
     markChainDirty(newNode);
   } else {
     // node is beyond our scope, grow tree
     while (index > root.max) {
       Vector<Indexable> vec = new Vector<Indexable>();
       int origSize = store.size();
       for (int i = origSize; i < 2 * origSize; i++) {
         if (i == index) {
           vec.add(i - origSize, b);
         } else {
           vec.add(i - origSize, null);
         }
       }
       MerkleTree newtree = new MerkleTree(vec);
       root = MerkleTreeNode.combineDigestFactory(root, newtree.root);
       for (int i = origSize; i < 2 * origSize; i++) {
         MerkleTreeNode tempNode = newtree.nodeMap.get(i - origSize);
         tempNode.max += origSize;
         tempNode.min += origSize;
         nodeMap.put(i, tempNode);
         store.add(i, newtree.store.get(i - origSize));
       }
     }
   }
 }
Пример #2
0
 public MerkleTreeNode getNode(int index) {
   return nodeMap.get(index);
 }