jakubkulhan / btree
此包已被废弃,不再维护。没有建议的替代包。
纯PHP实现的只增B+树。
dev-master
2016-03-29 17:48 UTC
Requires
- php: >=5.2.0
This package is auto-updated.
Last update: 2024-05-31 09:51:09 UTC
README
纯PHP实现的只增B+树。旨在成为一个高效的关键字值存储。B+树因其即使有数百万条记录也能快速检索而非常流行于存储系统(数据库)。
API
获取实例
$btree = btree::open('my.tree');
btree::open()
接受一个参数——B+树文件的路径。如果文件不存在,将为您创建。如果出现错误,btree::open()
返回 FALSE
,否则返回新创建的文件。
设置(插入、更新)某个键的值
$btree->set('key', 'value');
set()
在失败时返回 FALSE
,否则返回 TRUE
。
获取值
$btree->get('key');
如果键不存在或出现任何错误,get()
返回 NULL
。否则返回该键下的值。
删除键
$btree->set('key', NULL);
NULL
(删除)键。返回值与插入/更新值的情况相同。
这就是你所需要的。
高级
范围搜索
$btree->range("startkey", "endkey");
您将得到一个数组,其中包含键大于或等于 "startkey" 且小于 "endkey" 的值。
获取所有值
range()
(假设您没有像 "\xff\xff..." 这样的键)应该可以完成
$values = $btree->range("\x00", "\xff");
或获取所有叶节点的指针
$leaves = $btree->leaves();
然后处理节点
$values = array();
foreach ($leaves as $p) {
list(,$leaf) = $btree->node($leaf);
$values += $leaf;
}
使用 leaves()
已弃用。
压缩
如果您的B+树消耗了太多空间,那么对其进行压缩
$btree->compact();
许可协议
MIT许可协议
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.