BTree
BTree
B-Tree key/value database file access class.
This class provides a high performance key/value storage mechanism that stores data to file. A B-tree is a self-balancing tree data structure that keeps data sorted and allows searches, sequential access, insertions, and deletions in logarithmic time.
Constants
SIZEOF_HEADER
const SIZEOF_HEADER = 6
HEADER
const HEADER = "\xffbtree"
NODE_SLOTS
const NODE_SLOTS = 16
SIZEOF_INT
const SIZEOF_INT = 4
KVNODE
const KVNODE = kv
KPNODE
const KPNODE = kp
NODECHACHE_SIZE
const NODECHACHE_SIZE = 64
Properties
file
public File $file
nodecache
private array $nodecache
readOnly
private bool $readOnly
Methods
__construct
Use static method open() to get instance.
public __construct({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$file | string | |
$readOnly | bool |
open
Open the file for access.
public open({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$file | string | |
$readOnly | bool |
close
Close the file.
public close({Array})
resetBTreeFile
The the B-Tree source file.
public resetBTreeFile({Array})
get
Get value by key.
public get({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | The key to return data for |
range
Get all values where startkey <= key < endkey.
public range({Array})
To get all data, use:
$values = $btree->range("\x00", "\xff");
Parameters
Parameter | Type | Description |
---|---|---|
$startkey | string | |
$endkey | string |
set
Set value under given key.
public set({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | the key to store the value under |
$value | mixed | The value to store. A NULL value deletes given key. |
remove
public remove({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string |
has
Check if a given key exists in the database.
public has({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string |
keys
Get a list of all available keys in the database.
public keys({Array})
Warning: Unlike a search this will hit almost every part of the database file and can be a bit slow.
leaves
Get positions of all leaves.
public leaves({Array})
compact
Remove old nodes from BTree file.
public compact({Array})
dropCache
public dropCache({Array})
toArray
public toArray({Array})
lookup
Look up a key.
private lookup({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$key | string | |
$nodeType | string | |
$node | array | |
$ | bool |
leafHunt
Find positions of all leaves.
private leafHunt({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$p | int | pointer to node |
copyTo
Copy node from opened file to another.
private copyTo({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$to | File | The file to copy everything to |
$nodeType | string | |
$node | array |
root
Get root node.
private root({Array})
rootHunt
Try to get position of root.
private rootHunt({Array})
node
Get node.
private node({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$p | int | Pointer to node (offset in file) |
serialize
private serialize({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$type | string | |
$node | array |
unserialize
private unserialize({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$str | string |
header
private header({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$file | File | |
$root | `````` |
Generated by Hazaar API Doc Generator