Changes between Version 23 and Version 24 of IMMUTABLE_TREE_R0


Ignore:
Timestamp:
08/25/09 15:35:35 (16 years ago)
Author:
stefan
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • IMMUTABLE_TREE_R0

    v23 v24  
    5757{{{ 
    5858public static Hash getHash(ImmCollection<?> col, int begin, int end) { 
    59                 if(!(col instanceof ImmTreeCollection<?>)) { 
    60                         throw new IllegalArgumentException("Non Hashable Collection - cannot get Hash!"); 
    61                 } 
     59        if(!(col instanceof ImmTreeCollection<?>)) { 
     60                throw new IllegalArgumentException("Non Hashable Collection - cannot get Hash!"); 
     61        } 
    6262                 
    63                 ImmTreeCollection<?> treeCol = (ImmTreeCollection<?>)col; 
    64                  
    65                 if(!(treeCol.getTree().getRoot() instanceof HashingNode<?>)) { 
    66                         throw new IllegalArgumentException("Non Hashable Tree - cannot get Hash!"); 
    67                 } 
    68                  
    69                 HashingNode<?> node = (HashingNode<?>)treeCol.getTree().getRoot(); 
    70                  
    71                 Hasher res = new Hasher(); 
    72                 int count = end - begin; 
    73                  
    74                 node.getHash(res, begin + treeCol.getTreeBegin(), count); 
    75                 return res.toHash(); 
     63        ImmTreeCollection<?> treeCol = (ImmTreeCollection<?>)col; 
     64         
     65        if(!(treeCol.getTree().getRoot() instanceof HashingNode<?>)) { 
     66                throw new IllegalArgumentException("Non Hashable Tree - cannot get Hash!"); 
    7667        } 
     68         
     69        HashingNode<?> node = (HashingNode<?>)treeCol.getTree().getRoot(); 
     70         
     71        Hasher res = new Hasher(); 
     72        int count = end - begin; 
     73         
     74        node.getHash(res, begin + treeCol.getTreeBegin(), count); 
     75        return res.toHash(); 
     76} 
    7777}}} 
    7878 
     
    8181{{{ 
    8282public void getHash(Hasher res, int start, int count) { 
    83                         assert start >= 0; 
    84                         assert count <= getSize(); 
    85                          
    86                         int end = start + count; 
    87                         if(start == 0 && count == getSize()) { 
    88                                 res.addHashed(getHash()); 
    89                                 return; 
    90                         } if (count == 0) {  
    91                                 return; 
    92                         } 
    93                         if(start < getLeft().getSize()) { 
    94                                 int leftStart = start; 
    95                                 int leftCount = Math.min(getLeft().getSize() - leftStart, count); 
    96                                 getLeft().getHash(res, leftStart, leftCount); 
    97                         } 
    98                         if(start <= getLeft().getSize() && end > getLeft().getSize()) { 
    99                                 res.addObject(getData()); 
    100                         } 
    101                         if(end > getLeft().getSize() + 1) { 
    102                                 int rightStart = Math.max(0, start - getLeft().getSize() - 1); 
    103                                 int rightCount = (end - getLeft().getSize() - 1) - rightStart; 
    104                                 getRight().getHash(res, rightStart, rightCount); 
    105                         } 
    106                 } 
     83        assert start >= 0; 
     84        assert count <= getSize(); 
     85         
     86        int end = start + count; 
     87        if(start == 0 && count == getSize()) { 
     88                res.addHashed(getHash()); 
     89                return; 
     90        } if (count == 0) {  
     91                return; 
     92        } 
     93        if(start < getLeft().getSize()) { 
     94                int leftStart = start; 
     95                int leftCount = Math.min(getLeft().getSize() - leftStart, count); 
     96                getLeft().getHash(res, leftStart, leftCount); 
     97        } 
     98        if(start <= getLeft().getSize() && end > getLeft().getSize()) { 
     99                res.addObject(getData()); 
     100        } 
     101        if(end > getLeft().getSize() + 1) { 
     102                int rightStart = Math.max(0, start - getLeft().getSize() - 1); 
     103                int rightCount = (end - getLeft().getSize() - 1) - rightStart; 
     104                getRight().getHash(res, rightStart, rightCount); 
     105        } 
     106} 
    107107}}} 
    108108