|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.entityfs.support.lang.ObjectProxySupport<NodeRepository<K>>
org.helidb.util.bplus.LruCacheNodeRepository<K,V>
K
- The type of keys in the node repository.V
- The type of values in the node repository.public class LruCacheNodeRepository<K,V>
This node repository has a LRU cache for the nodes read from another, proxied node repository. LRU stands for Least Recently Used and means that the least recently used node is purged from the cache when inserting a new node if the cache is at its maximum size.
A LRU cache is a good way to speed up a B+ Tree for a low cost in extra memory overhead since the tree's root node and the nodes near the root node is usually accessed far more often than each of the leaf nodes.
LruCacheNodeRepositoryBuilder
Constructor Summary | |
---|---|
LruCacheNodeRepository(NodeRepository<K> nr,
int maxCacheSize)
Create a new LRU caching node repository. |
Method Summary | |
---|---|
long |
bookPositionForLeafNode()
Book a position for a future leaf node. |
long |
bookPositionForNonLeafNode()
Book a position for a future non-leaf node. |
void |
clear()
Remove all contents from the node repository. |
void |
close()
Close the node repository and release all its allocated resources. |
boolean |
compact()
Defragment the node repository to recover wasted disk space. |
void |
deleteNode(long pos,
boolean leafNode)
Delete the node at the supplied position. |
int |
getMaxNumberOfRecordsForLeafNode(long pos)
Get the maximum number of records for a leaf node in the tree at the supplied position. |
int |
getMaxNumberOfRecordsForNonLeafNode(long pos)
Get the maximum number of records for a non-leaf node in the tree at the supplied position. |
long |
getPositionOfRootNode()
Get the root node's position in the node repository. |
boolean |
leafNodeHasPointersToAdjacentLeafNodes()
Does leaf nodes have pointers to their adjacent leaf nodes? If so, the tree supports iteration. |
BPlusTreeNode<K,?> |
readNode(long pos,
K keyForFirstPointer)
Read the node at the supplied position. |
void |
replaceContentsWith(InputStream is,
long dataLen)
Replace the contents of the node repository with data read from the stream. |
void |
returnBookedLeafNodePosition(long p)
Return a previously booked position for a leaf node. |
void |
returnBookedNonLeafNodePosition(long p)
Return a previously booked position for a non-leaf node. |
void |
verifyRepositoryIntegrity()
Verify the node repository's integrity. |
long |
writeContentsTo(OutputStream os)
Write the contents of the node repository to the stream. |
K |
writeNode(BPlusTreeNode<K,?> node)
Write the node to the repository. |
Methods inherited from class org.entityfs.support.lang.ObjectProxySupport |
---|
equals, getProxied, hashCode, toString |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public LruCacheNodeRepository(NodeRepository<K> nr, int maxCacheSize) throws IllegalArgumentException
nr
- The proxied node repository.maxCacheSize
- The maximum size of the cache, in number of nodes.
IllegalArgumentException
- If the maximum cache size is less than
1.Method Detail |
---|
public long getPositionOfRootNode()
NodeRepository
getPositionOfRootNode
in interface NodeRepository<K>
public int getMaxNumberOfRecordsForLeafNode(long pos)
NodeRepository
NodeRepository
's NodeSizeStrategy
, and by what extra metadata
the NodeRepository
stores for each leaf nodes.
getMaxNumberOfRecordsForLeafNode
in interface NodeRepository<K>
pos
- The position of the leaf node.
public int getMaxNumberOfRecordsForNonLeafNode(long pos)
NodeRepository
NodeRepository
's NodeSizeStrategy
, and by what extra metadata
the NodeRepository
stores for each non-leaf nodes.
getMaxNumberOfRecordsForNonLeafNode
in interface NodeRepository<K>
pos
- The position of the non-leaf node.
public boolean leafNodeHasPointersToAdjacentLeafNodes()
NodeRepository
leafNodeHasPointersToAdjacentLeafNodes
in interface NodeRepository<K>
true
if leaf nodes have pointers to their adjacent leaf
nodes.public long bookPositionForLeafNode()
NodeRepository
NodeRepository.returnBookedLeafNodePosition(long)
.
bookPositionForLeafNode
in interface NodeRepository<K>
NodeRepository.bookPositionForNonLeafNode()
,
NodeRepository.returnBookedLeafNodePosition(long)
public void returnBookedLeafNodePosition(long p)
NodeRepository
returnBookedLeafNodePosition
in interface NodeRepository<K>
p
- The position to return.NodeRepository.bookPositionForLeafNode()
,
NodeRepository.returnBookedNonLeafNodePosition(long)
public long bookPositionForNonLeafNode()
NodeRepository
NodeRepository.returnBookedNonLeafNodePosition(long)
.
bookPositionForNonLeafNode
in interface NodeRepository<K>
NodeRepository.bookPositionForLeafNode()
,
NodeRepository.returnBookedNonLeafNodePosition(long)
public void returnBookedNonLeafNodePosition(long p)
NodeRepository
returnBookedNonLeafNodePosition
in interface NodeRepository<K>
p
- The position to return.NodeRepository.bookPositionForNonLeafNode()
,
NodeRepository.returnBookedLeafNodePosition(long)
public BPlusTreeNode<K,?> readNode(long pos, K keyForFirstPointer)
NodeRepository
readNode
in interface NodeRepository<K>
pos
- The position to read the node at. The root node has position
0
.keyForFirstPointer
- The key for the node's first pointer, if this
is a non-leaf node. The key for the root node's first pointer is null
.
null
if the node position is beyond the end
of the file.public K writeNode(BPlusTreeNode<K,?> node)
NodeRepository
writeNode
in interface NodeRepository<K>
node
- The node to write.
public void deleteNode(long pos, boolean leafNode)
NodeRepository
deleteNode
in interface NodeRepository<K>
pos
- The position of the node to delete.leafNode
- Is the node to delete a leaf node?public void clear()
NodeRepository
clear
in interface NodeRepository<K>
public boolean compact()
NodeRepository
compact
in interface NodeRepository<K>
true
if the node repository was defragmented, or false
if there was nothing to defragment right now.public long writeContentsTo(OutputStream os)
NodeRepository
writeContentsTo
in interface NodeRepository<K>
os
- The stream to write to. The stream is not closed after
writing.
public void replaceContentsWith(InputStream is, long dataLen)
NodeRepository
replaceContentsWith
in interface NodeRepository<K>
is
- The stream to read from. The stream is not closed after
reading.dataLen
- The total number of bytes to read from the stream.public void close()
NodeRepository
close
in interface NodeRepository<K>
public void verifyRepositoryIntegrity()
NodeRepository
verifyRepositoryIntegrity
in interface NodeRepository<K>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |