Class BPlusLeafRecords<KeyType,KeyBufferType>
java.lang.Object
com.semedy.reasoner.edb.persistentstore.bplustree.BPlusNode<KeyType,KeyBufferType>
com.semedy.reasoner.edb.persistentstore.bplustree.BPlusLeaf<KeyType,KeyBufferType>
com.semedy.reasoner.edb.persistentstore.bplustree.BPlusLeafRecords<KeyType,KeyBufferType>
- All Implemented Interfaces:
CacheUnit
- Direct Known Subclasses:
BPlusLeafIndex
A leaf is the node in a B+ tree containing records. Although we want them to
be generic,
most B+ trees are specialized. As a result, the only thing generic about the tree is the key
most B+ trees are specialized. As a result, the only thing generic about the tree is the key
- Author:
- angele
-
Nested Class Summary
Nested classes/interfaces inherited from class com.semedy.reasoner.edb.persistentstore.bplustree.BPlusNode
BPlusNode.BPlusStatus
-
Constructor Summary
ConstructorsConstructorDescriptionBPlusLeafRecords
(BPlusKeys<KeyType, KeyBufferType> keys, int maxSizeInBytes, BPlusTree<KeyType, KeyBufferType> bplustree) BPlusLeafRecords
(BPlusKeys<KeyType, KeyBufferType> keys, long[] records, int maxSizeInBytes, BPlusTree<KeyType, KeyBufferType> bplustree) Initializes leaf. -
Method Summary
Modifier and TypeMethodDescriptionboolean
append a key with a recordlong
Borrow the first recordlong
borrows the rightmost recordbyte[]
Map node to an array of bytesstatic BPlusLeafRecords<long[],
TupleBuffer> createLeaf
(byte[] bytes, KeysFactory<long[], TupleBuffer> keysFactory, BPlusTree<long[], TupleBuffer> bplustree) Method for creating a leaf from the given byte array.boolean
Deletes the key (and the associated record offset) from this node.void
destroy()
free up ressources at the end (CacheManager.clear)void
performs several cleaning up actions after borrowing from the right.void
performs several cleanign up actions after borrowing from the left.getIndexBuffer
(int index) get attached object at indexlong
getObjectSize
(int index) get size of attached object at indexlong
getRecord
(int index) get record at indexlong[]
boolean
Inserts a key and the record offset into the node.boolean
isLeaf()
A quick checker to see if the node is a leaf- if so, we have found the final result of the search.void
remove()
long
Searches for the given value.long
int
searchIndex
(KeyType key) Searches for index of the key Returns -1 it key is not containedint
Searches for hte (possible) index of the keyboolean
Sets the record of a given key
returns false if key is not therevoid
substitute
(BPlusKeys<KeyType, KeyBufferType> key, long[] record, long leftOffs) Methods inherited from class com.semedy.reasoner.edb.persistentstore.bplustree.BPlusLeaf
checkSanity, replace, searchIndexToInsert, searchIndexToInsertByBuffer
Methods inherited from class com.semedy.reasoner.edb.persistentstore.bplustree.BPlusNode
borrowFirstKey, borrowKey, canBeBorrowedFrom, clear, detach, getFather, getIndexInFather, getKeys, getLast, getNext, getNumKeys, getOffset, getStatus, isEmpty, isFull, isReleasable, release, setFather, setLast, setNext, setStatus, sizeInBytes, toString, touch, underflow
-
Constructor Details
-
BPlusLeafRecords
public BPlusLeafRecords(BPlusKeys<KeyType, KeyBufferType> keys, int maxSizeInBytes, BPlusTree<KeyType, KeyBufferType> bplustree) - Parameters:
keys
-maxSizeInBytes
-bplustree
-
-
BPlusLeafRecords
public BPlusLeafRecords(BPlusKeys<KeyType, KeyBufferType> keys, long[] records, int maxSizeInBytes, BPlusTree<KeyType, KeyBufferType> bplustree) Initializes leaf.- Parameters:
keys
-records
-maxSizeInBytes
-bplustree
-
-
-
Method Details
-
substitute
- Overrides:
substitute
in classBPlusLeaf<KeyType,
KeyBufferType>
-
delete
Deletes the key (and the associated record offset) from this node. First, we find the index of the key. Make a temp array containing keys[0, indexToSkip - 1] copy keys[indexToSkip + 1, keys.length - 1] over. Do the same with the records.- Overrides:
delete
in classBPlusLeaf<KeyType,
KeyBufferType> - Parameters:
keyToDelete
-
-
insert
Inserts a key and the record offset into the node. First, we find the index where these items need to be. Then copy all elements up to that point into a temp array. Shove the new key in, copy the rest of the elements. use the same index and do the same with the records.- Overrides:
insert
in classBPlusLeaf<KeyType,
KeyBufferType> - Parameters:
key
-record
-- Throws:
IOException
-
set
Sets the record of a given key
returns false if key is not there- Overrides:
set
in classBPlusLeaf<KeyType,
KeyBufferType> - Parameters:
key
-record
-
-
append
Description copied from class:BPlusLeaf
append a key with a record- Overrides:
append
in classBPlusLeaf<KeyType,
KeyBufferType> - Returns:
- Throws:
IOException
-
isLeaf
public boolean isLeaf()Description copied from class:BPlusNode
A quick checker to see if the node is a leaf- if so, we have found the final result of the search.- Overrides:
isLeaf
in classBPlusLeaf<KeyType,
KeyBufferType> - Returns:
- true if this is a leaf
-
search
Searches for the given value.- Overrides:
search
in classBPlusLeaf<KeyType,
KeyBufferType> - Parameters:
key
-- Returns:
- the value for the key, or -1 if not found.
-
searchIndex
Description copied from class:BPlusLeaf
Searches for index of the key Returns -1 it key is not contained- Overrides:
searchIndex
in classBPlusLeaf<KeyType,
KeyBufferType> - Returns:
-
searchIndexBuffer
Description copied from class:BPlusLeaf
Searches for hte (possible) index of the key- Overrides:
searchIndexBuffer
in classBPlusLeaf<KeyType,
KeyBufferType> - Returns:
-
searchBuffer
- Overrides:
searchBuffer
in classBPlusLeaf<KeyType,
KeyBufferType>
-
getRecords
public long[] getRecords()- Overrides:
getRecords
in classBPlusLeaf<KeyType,
KeyBufferType> - Returns:
- array of records
-
getRecord
public long getRecord(int index) get record at index- Overrides:
getRecord
in classBPlusLeaf<KeyType,
KeyBufferType> - Parameters:
index
-- Returns:
-
getIndexBuffer
get attached object at index- Overrides:
getIndexBuffer
in classBPlusLeaf<KeyType,
KeyBufferType> - Throws:
IOException
-
getObjectSize
get size of attached object at index- Overrides:
getObjectSize
in classBPlusLeaf<KeyType,
KeyBufferType> - Throws:
IOException
-
borrowRecord
public long borrowRecord()borrows the rightmost record- Overrides:
borrowRecord
in classBPlusLeaf<KeyType,
KeyBufferType> - Returns:
- the rightmost record
-
doneBorrowing
public void doneBorrowing()Description copied from class:BPlusNode
performs several cleaning up actions after borrowing from the right.- Overrides:
doneBorrowing
in classBPlusLeaf<KeyType,
KeyBufferType>
-
doneBorrowingFirst
public void doneBorrowingFirst()Description copied from class:BPlusNode
performs several cleanign up actions after borrowing from the left.- Overrides:
doneBorrowingFirst
in classBPlusLeaf<KeyType,
KeyBufferType>
-
borrowFirstRecord
public long borrowFirstRecord()Borrow the first record- Overrides:
borrowFirstRecord
in classBPlusLeaf<KeyType,
KeyBufferType> - Returns:
- the first record
-
remove
public void remove()- Overrides:
remove
in classBPlusLeaf<KeyType,
KeyBufferType>
-
destroy
public void destroy()Description copied from interface:CacheUnit
free up ressources at the end (CacheManager.clear) -
createBytes
public byte[] createBytes()Map node to an array of bytes- Overrides:
createBytes
in classBPlusLeaf<KeyType,
KeyBufferType> - Returns:
-
createLeaf
public static BPlusLeafRecords<long[],TupleBuffer> createLeaf(byte[] bytes, KeysFactory<long[], TupleBuffer> keysFactory, BPlusTree<long[], TupleBuffer> bplustree) Method for creating a leaf from the given byte array.- Parameters:
bytes
-- Returns:
-