dev-master
9999999-dev https://github.com/jakubkulhan/btreeAppend-only B+Tree implemented purely in PHP.
MIT
The Requires
- php >=5.2.0
by Jakub Kulhan
filesystem persistence btree
Wallogit.com
2017 © Pedro Peláez
Append-only B+Tree implemented purely in PHP.
Append-only B+Tree implemented purely in PHP. Intended to be an efficient key-value storage. B+Tree is a very popular in storage systems (databases) because of its fast retrieval even with millions of records., (*1)
Get the instance:, (*2)
$btree = btree::open('my.tree');
btree::open() takes one argument – path to file with B+Tree. If file does not exists, it is created for you. btree::open() returns FALSE in case that anything went wrong, newly created otherwise., (*3)
Set (insert, update) a value for some key:, (*4)
$btree->set('key', 'value');
set() returns FALSE on failure, TRUE otherwise., (*5)
Get the value:, (*6)
$btree->get('key');
If key does not exist or anything goes wrong, get() returns NULL. Value under the key is returned otherwise., (*7)
Delete key:, (*8)
$btree->set('key', NULL);
NULLs (deletes) the key. Same return values as in case of inserting/updating value., (*9)
That is all you need., (*10)
$btree->range("startkey", "endkey");
And you'll get array of values whose key is greater than or equal to "startkey" and less than "endkey"., (*11)
range() (assuming you do not have keys like "\xff\xff...") should do it:, (*12)
$values = $btree->range("\x00", "\xff");
Or get pointers to all leaf nodes:, (*13)
$leaves = $btree->leaves();
And then process nodes:, (*14)
$values = array();
foreach ($leaves as $p) {
list(,$leaf) = $btree->node($leaf);
$values += $leaf;
}
Using leaves() is depracted., (*15)
Does your B+Tree consume a lot of space? Then compact it:, (*16)
$btree->compact();
The MIT license:, (*17)
Copyright (c) 2009-2010 Jakub Kulhan <jakub.kulhan@gmail.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Append-only B+Tree implemented purely in PHP.
MIT
filesystem persistence btree