org.limewire.collection
Class TreeStorage
java.lang.Object
org.limewire.collection.TreeStorage
public class TreeStorage
- extends Object
Structure that contains only the necessary nodes of a hash tree, automatically
verifies new nodes against the root and compacts the tree as nodes are used.
For the numbering of the nodes check
http://www.limewire.org/wiki/index.php?title=HashTreeRangeEncoding
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
setAllowUnverifiedUse
public void setAllowUnverifiedUse(boolean allow)
add
public boolean add(int id,
byte[] data)
- Parameters:
id - the id of the tree nodedata - the hash in the node
- Returns:
- true if the node was added and verified ok
get
public byte[] get(int id)
- Returns:
- the contents of the node with the given id
used
public void used(int id)
- notification that the node id has been used to verify
data from the file. This will compact the tree.
getUsedNodes
public Collection<Integer> getUsedNodes()
- Returns:
- the reprsentation as defined on the wiki page
getVerifiedNodes
public Collection<Integer> getVerifiedNodes()
log2Ceil
public static int log2Ceil(long number)
fileToNodeId
public int fileToNodeId(int fileId)
- Parameters:
fileId - id of a chunk in a file starting from 0
- Returns:
- id of a node on the bottom row of the tree
nodeToFileId
public int[] nodeToFileId(int nodeId)
- Parameters:
nodeId - node from the tree
- Returns:
- the start and end index of the chunks from the file
the node maps to or null if id is invalid.
Copyright © 2008 Lime Wire LLC. All Rights Reserved.