Node
Node
Constants
NODE_PTR_SIZE
public const NODE_PTR_SIZE = 4Properties
ptr
public int $ptrlength
public int $lengthslotSize
public int $slotSizekeySize
public int $keySizechildSize
public int $childSizecacheSize
public int $cacheSize = 128children
public array $childrennodeType
public NodeType $nodeTypefile
public mixed $filenodeCache
Cache for nodes to avoid excessive file reads.
private array $nodeCacherecordCache
Cache for records to avoid multiple reads from the file.
private array $recordCacheThis is a static property to allow sharing across instances.
parentNode
public self $parentNodeMethods
__construct
public __construct(mixed $file, ?int $ptr, int $slotSize = 16, int $keySize = 32): voidParameters
| Parameter | Type | Description |
|---|---|---|
$file | mixed | |
$ptr | int | |
$slotSize | int | |
$keySize | int |
resetCache
Resets the static caches for nodes and records.
public resetCache(): voidThis method clears both the node cache and the record cache by setting their respective static arrays to empty. Use this to ensure that cached data is discarded and fresh data will be loaded on subsequent accesses.
create
Create a new Node instance with initialized children slots.
public create(mixed $file, NodeType $type = 'NodeType::INTERNAL', int $slotSize = 16, int $keySize = 32): NodeParameters
| Parameter | Type | Description |
|---|---|---|
$file | mixed | The file resource where the BTree is stored |
$type | NodeType | |
$slotSize | int | |
$keySize | int |
read
Reads the node data from the file at the specified pointer.
public read(?int $ptr): boolParameters
| Parameter | Type | Description |
|---|---|---|
$ptr | int | The pointer to the node in the file. If null, uses the current node's pointer. |
write
Writes the node data to the file at the specified pointer.
public write(?int $ptr): boolParameters
| Parameter | Type | Description |
|---|---|---|
$ptr | int | The pointer to write the node in the file. If null, writes to the end of the file. |
add
Adds a new key-value pair to the B-tree node.
public add(string $key, mixed $value): boolThis method creates a new leaf node, sets the provided key and value, and adds the node as a child to the current node. Only internal nodes can have children; attempting to add a record to a non-leaf node will throw a RuntimeException.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key to add to the node |
$value | mixed | the value associated with the key |
set
Sets the value for the specified key in the node.
public set(string $key, mixed $value): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key to set |
$value | mixed | the value to associate with the key |
get
Gets the value for the specified key from the node.
public get(string $key): mixedParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key to get |
has
Checks if the specified key exists in the node.
public has(string $key): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key to check |
remove
Removes the specified key from the node.
public remove(string $key): boolParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key to remove |
addNode
Adds a child node to the current node.
public addNode(self $node): voidParameters
| Parameter | Type | Description |
|---|---|---|
$node | self | the node to add as a child |
addRecord
Adds a record to the current node.
public addRecord(Record $record): boolParameters
| Parameter | Type | Description |
|---|---|---|
$record | Record | the record to add |
verifyTree
Verifies the integrity of the B-Tree from this node downwards.
public verifyTree(?Node $node, ?string $minKey, ?string $maxKey): boolParameters
| Parameter | Type | Description |
|---|---|---|
$node | Node | The node to verify. If null, starts from the current node. |
$minKey | string | the minimum key value for the current node |
$maxKey | string | the maximum key value for the current node |
countRecords
Counts the total number of child nodes in the subtree rooted at this node.
public countRecords(): intIf the node is a leaf, returns the number of its children directly. Otherwise, recursively counts the children of all descendant nodes.
lookupLeafNode
Looks up the child node that should contain the specified key.
public lookupLeafNode(string $key): ?NodeParameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key to look up |
leaf
Returns a generator that yields all leaf nodes in the subtree rooted at this node.
public leaf(): voidThis method traverses the B-tree and yields each leaf node it encounters. It can be used to iterate over all leaf nodes in the B-tree.
split
Splits the current node into two nodes when it becomes full.
private split(): voidThis method is called when the number of children in the current node exceeds its slot size. It divides the children into two halves, creates a new node to store the first half, and keeps the second half in the current node. The median key is then promoted to the parent node. If the current node is the root, a new root is created.
cacheNode
Caches the specified node.
private cacheNode(self $node): voidParameters
| Parameter | Type | Description |
|---|---|---|
$node | self | the node to cache |
Generated by Hazaar API Doc Generator on Sun, 01 Mar 2026 09:22:26 +0000