对等B树
项目描述
Hyperbee
基于Hypercore构建的Peer-to-Peer只追加B树。与JavaScript版本兼容。
$ cargo add hyperbee
用法
来自示例
use hyperbee::Hyperbee;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let hb = Hyperbee::from_ram().await?;
    // Insert "world" with key "hello"
    hb.put(b"hello", Some(b"world")).await?;
    // Get the value for key "hello"
    let Some((_seq, Some(val))) = hb.get(b"hello").await? else {
        panic!("could not get value");
    };
    assert_eq!(val, b"world");
    // Trying to get a non-exsitant key returns `None`
    let res = hb.get(b"no key here").await?;
    assert_eq!(res, None);
    // Deleting a key returns `true` if it was present
    let res = hb.del(b"hello").await?;
    assert!(res.is_some());
    // Getting deleted key returns `None`
    let res = hb.get(b"hello").await?;
    assert_eq!(res, None);
    Ok(())
}
外语绑定
我们使用UniFFI为其他语言生成库。要为Python构建库,请运行
cargo build -F ffi && cargo run -F ffi --bin uniffi-bindgen generate --library target/debug/libhyperbee.so --language python --out-dir out
这会生成一个名为out/hyperbee.py的文件,可以使用该文件。此文件需要libhyperbee.so与.py文件一起存在。可分发Python软件包仍在开发中。目前仅测试了Python。请参阅测试以获取示例用法。
与JS Hyperbee的兼容性
- 与JS Hyperbee文件完全功能互操作
- 读取、写入和删除操作
- 顺序键流,类似于JS的createReadStream
- 支持键流的关键界限,如gt、lt等。
- 接受比较和交换的put和del。
- 支持类似于JS的sub的前缀键操作。
- 一对一的二进制输出
未来工作
- 构建FFI包装器
- 改进的线格式
- 可配置的树参数
开发
使用$ cargo test运行测试。
项目详情
    
       关闭
    
      
        
    
    
  
哈希值 for hyperbeepy-0.3.1-py3-none-manylinux_2_34_x86_64.whl
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 6cd141c333301391ee5a45cf83121b276c840ee8a09ac0b49b9d3fe0acc7548d | |
| MD5 | aab0608c189b86b538be56b3b0728496 | |
| BLAKE2b-256 | 8c851c69a4fe786a51121c3efa5edced17805555157330a07dd77137c4b3a63b |