Skip to main content

Peer to Peer B-tree

Project description

Hyperbee

A peer-to-peer append-only B-tree built on Hypercore. Compatible with the JavaScript version.

$ cargo add hyperbee

Usage

From the examples:

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(())
}

Foreign Language Bindings

We use UniFFI to generate libraries for other languages. To build the library for python run:

cargo build -F ffi && cargo run -F ffi --bin uniffi-bindgen generate --library target/debug/libhyperbee.so --language python --out-dir out

This generates a file out/hyperbee.py, which an be used. This file requires that libhyperbee.so be present alongside the .py file. Distributable python packages are still a work-in-progress. Currently only Python is tested. See the tests for example usage.

Parity with JS Hyperbee

  • full functional interoperability with JS Hyperbee files
  • read, write, and delete operations
  • in-order key streaming like JS's createReadStream
  • support gt, lt, etc bounds for key streaming
  • accept compare-and-swap for put and del.
  • support prefixed key operations like JS's sub
  • one-to-one binary output

Future work

  • Build FFI wrappers
  • improved wire format
  • configurable tree parameters

Development

Run the tests with $ cargo test.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

hypercore-0.0.1-py3-none-manylinux_2_34_x86_64.whl (1.4 MB view details)

Uploaded Python 3 manylinux: glibc 2.34+ x86-64

File details

Details for the file hypercore-0.0.1-py3-none-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for hypercore-0.0.1-py3-none-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1ecfad0b3060f496e60dbcb177095713467efb41545ef9f7ed5c38f134f3488c
MD5 b3b5f96271d8c25358deac2a6fbff54b
BLAKE2b-256 89301492be4433b2e5baa0a13b761c8f59ee88a67a0db62a8ce0b668baef996d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page