Hazaar
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.

Summary
MethodsPropertiesConstants
Constants
HEADER
HEADER : type
Header that has to be at end of every file

Type

\type - desc
KPNODE
KPNODE : type
This is key-pointer node

Type

\type - desc
KVNODE
KVNODE : type
This is key-value node

Type

\type - desc
NODECHACHE_SIZE
NODECHACHE_SIZE : type
Size of node chache

Type

\type - desc
NODE_SLOTS
NODE_SLOTS : type
Maximum number of keys per node (do not even think about to change it)

Type

\type - desc
SIZEOF_HEADER
SIZEOF_HEADER : type
Size of header

Type

\type - desc
SIZEOF_INT
SIZEOF_INT : type
Size of integer (pack type N)

Type

\type - desc
Properties
$file
$file
The file resource
$nodecache
$nodecache
Methods
__construct()
__construct($file)
Use static method open() to get instance
compact()
compact() : bool
Remove old nodes from BTree file
copyto()
copyto($to, $node_type = null, $node = null) : int
Copy node from opened file to another
dropCache()
dropCache()
get()
get($key) : mixed
Get value by key
has()
has($key) : boolean
Check if a given key exists in the database
Static
header()
header($file, $root) : bool
Writes header to file
keys()
keys() : array
Get a list of all available keys in the database

Warning: Unlike a search this will hit almost every part of the database file and can be a bit slow.

leafhunt()
leafhunt($p) : array
Find positions of all leaves
leaves()
leaves() : array
Get positions of all leaves
lookup()
lookup($key, $node_type = null, $node = null) : array
Look up a key
node()
node($p)
Get node
open()
open($file = null) : boolean
Open the file for access
range()
range($startkey, $endkey) : array
Get all values where startkey <= key < endkey

To get all data, use:

$values = $btree->range("\x00", "\xff");

remove()
remove($key)
reset_btree_file()
reset_btree_file() : boolean
The the B-Tree source file.
root()
root() : array
Get root node
roothunt()
roothunt() : int
Try to get position of root
Static
serialize()
serialize($type, $node) : string
Serialize node
set()
set($key, $value) : boolean
Set value under given key
Static
unserialize()
unserialize($str) : array
Unserialize node