Skip to content

Commit

Permalink
More docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cowlicks committed Feb 22, 2024
1 parent e9e091c commit 504e308
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ fn min_keys(max_keys: usize) -> usize {
max_keys >> 1
}

// TODO make not pub
#[derive(Clone, Debug)]
/// Pointer used within a [`Node`] to point to the block where a (key, value) pair is stored.
/// A key can be inserted without a value, so it's value is optional.
/// Reference used within a [`Node`] of the [Hypercore](hypercore::Hypercore) block where a
/// key-value pair is stored.
pub struct KeyValue {
/// Index of key value pair within the [`hypercore::Hypercore`].
seq: u64,
Expand All @@ -64,6 +65,7 @@ pub struct KeyValueData {
pub value: Option<Vec<u8>>,
}

// TODO make not pub
#[derive(Debug)]
/// Pointer used within a [`Node`] to reference to it's child nodes.
pub struct Child<M: CoreMem> {
Expand All @@ -75,8 +77,10 @@ pub struct Child<M: CoreMem> {
cached_node: Option<SharedNode<M>>,
}

//TODO make not pub
#[derive(Clone, Debug)]
/// A block off the hypercore deserialized into the form we use in the BTree
/// A "block" from a [`Hypercore`](hypercore::Hypercore) deserialized into the form used in
/// Hyperbee
pub struct BlockEntry<M: CoreMem> {
/// Pointers::new(NodeSchema::new(hypercore.get(seq)).index))
nodes: Vec<SharedNode<M>>,
Expand All @@ -96,14 +100,19 @@ struct Children<M: CoreMem> {
children: RwLock<Vec<Child<M>>>,
}

/// A node in the tree
// TODO make not pub
/// A node of the B-Tree within the [`Hyperbee`]
#[derive(Debug)]
pub struct Node<M: CoreMem> {
pub keys: Vec<KeyValue>,
children: Children<M>,
blocks: Shared<Blocks<M>>,
}

/// An append only B-Tree built on [`Hypercore`](hypercore::Hypercore). It provides a key-value
/// store API, with methods for [inserting](Hyperbee::put), [getting](Hyperbee::get), and
/// [deleting](Hyperbee::del) key-value pair. As well as creating [sorted
/// iterators](Hyperbee::traverse), and ["sub" B-Trees](Hyperbee::sub) for grouping related data.
#[derive(Debug, Builder)]
#[builder(pattern = "owned", derive(Debug))]
pub struct Hyperbee<M: CoreMem> {
Expand Down
5 changes: 4 additions & 1 deletion src/prefixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ use crate::{
CoreMem, KeyValueData, Shared, Tree,
};

/// A "sub" [`Hyperbee`](crate::Hyperbee), which can be used for grouping data. When inserted keyss are automatically prefixed
/// with [`Prefixed::prefix`].
pub struct Prefixed<M: CoreMem> {
prefix: Vec<u8>,
/// All keys inserted with [`Prefixed::put`] are prefixed with this value
pub prefix: Vec<u8>,
tree: Shared<Tree<M>>,
}

Expand Down
3 changes: 3 additions & 0 deletions src/traverse.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Implementation of the [`Stream`] trait for [`Hyperbee`](crate::Hyperbee). Which allows
//! iterating over data in key-order, between a range, or in reverse asynchronously.
use std::{
fmt::Debug,
future::Future,
Expand Down Expand Up @@ -447,6 +449,7 @@ impl<'a, M: CoreMem + 'a> Stream for Traverse<'a, M> {

static LEADER: &str = "\t";

/// Print the keys of the provided node and it's descendents as a tree
pub async fn print<M: CoreMem>(node: SharedNode<M>) -> Result<String, HyperbeeError> {
let starting_height = node.read().await.height().await?;
let mut out = "".to_string();
Expand Down

0 comments on commit 504e308

Please sign in to comment.