LeafNode
Extends:
A Leaf Node in the B+Tree.
Constructor Summary
Public Constructor | ||
public |
constructor(keys: Array<*>, records: Array<*>) Creates a new leaf node. |
Method Summary
Public Methods | ||
public |
addKey(key: *, record: *): number Adds a key, record pair to this leaf node. |
|
public |
getItem(key: *, near: BTree.NEAR_MODE): number Searches the node for a specific key and returns its position if found. |
|
public |
isLeaf(): boolean Returns whether this is a leaf node. |
|
public |
Merges two leaf nodes together (this + frNod). |
|
public |
Splits the leaf node into two nodes (this + one new node). |
Public Constructors
public constructor(keys: Array<*>, records: Array<*>) source
Creates a new leaf node. Leaf nodes store key value pairs, hence the keys and records arrays are required to have the same length. In an index, the keys array usually stores the secondary key, while the records array stores the corresponding primary key. The B+Tree ensures that the items in the keys array are ordered ascending.
Params:
Name | Type | Attribute | Description |
keys | Array<*> |
|
Optional array of keys (default is empty). |
records | Array<*> |
|
Optional array of records (default is empty). |
Public Members
public nextLeaf: * source
public prevLeaf: * source
public get records: Array<*> source
Public Methods
public addKey(key: *, record: *): number source
Adds a key, record pair to this leaf node. By definition, the key is inserted into the keys of this leaf node, such that the ascending order of the keys is maintained.
Params:
Name | Type | Attribute | Description |
key | * | The key to insert. |
|
record | * | The corresponding record to insert. |
Return:
number | The position it was inserted at. |
public getItem(key: *, near: BTree.NEAR_MODE): number source
Searches the node for a specific key and returns its position if found. The near parameter allows to find either an exact match or the first key greater/less or equal than the specified key.
Since the B+tree limits the number of records per leaf node, the complexity of this method is in O([order/2, order-1]).
Params:
Name | Type | Attribute | Description |
key | * | The key to look for. |
|
near | BTree.NEAR_MODE |
Return:
number | The index of the match if found, -1 otherwise. |
public isLeaf(): boolean source
Returns whether this is a leaf node.
Return:
boolean | True, since it is a leaf node. |