Record
Record
Class Record.
class RecordRepresents a key-value record in a B-tree node, supporting file-backed storage and efficient access. Provides methods for reading, writing, and moving records between nodes.
Properties
key
The key of the record.
public string $keyvalue
The value associated with the key.
public mixed $valueptr
Pointer to the record's position in the file.
public int $ptrparentNode
Reference to the parent node containing this record.
public Node $parentNodefile
private mixed $fileMethods
create
Creates a new Record instance.
public create(Node $parentNode, string $key): selfParameters
| Parameter | Type | Description |
|---|---|---|
$parentNode | Node | the parent node of the record |
$key | string | the key of the record |
read
Reads the record's value from the file.
public read(?int $ptr): mixedIf the value is already in memory, it is returned directly. Otherwise, it seeks to the record's position in the file, reads its length and data, unserializes the data, and returns the value.
Parameters
| Parameter | Type | Description |
|---|---|---|
$ptr | int | the pointer to the record in the file. If null, uses the current record's pointer. |
write
Writes the record's key and value to the file.
public write(string $key, mixed $value): boolSerializes the value and writes it to the file. If the record already exists and the new data fits within the allocated space, it updates the record in-place. Otherwise, it appends the new record to the end of the file and updates the pointer.
Parameters
| Parameter | Type | Description |
|---|---|---|
$key | string | the key of the record |
$value | mixed | the value of the record |
moveTo
Moves the record to a new leaf node.
public moveTo(Node $leaf): boolThis method updates the record's parent node and file handle, resets its pointer, writes the record to the new location in the file, and adds the record to the new leaf node.
Parameters
| Parameter | Type | Description |
|---|---|---|
$leaf | Node | the new leaf node to move the record to |
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:24 +0000