Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/canscale/StableHeapBTreeMap

A functional BTreeMap that can be used with a stable variable in heap memory
https://github.com/canscale/StableHeapBTreeMap

Last synced: about 1 month ago
JSON representation

A functional BTreeMap that can be used with a stable variable in heap memory

Awesome Lists containing this project

README

        

# StableHeapBTreeMap

A functional, heap-based [BTree](https://en.wikipedia.org/wiki/B-tree) data structure written in Motoko

## API Documentation

Full API documentation for this library can be found at https://canscale.github.io/StableHeapBTreeMap/BTree.html

## Usage
Install vessel and ensure this is included in your package-set.dhall and vessel.dhall
```
import BTree "mo:btree/BTree";
...
// initialize
let t = BTree.init(?32); // 32 is the order, or the size of each BTree node

// initialize from an array or buffer (similar methods for toArray/toBuffer)
let t = BTree.fromArray(32, Text.compare, array);
let t = BTree.fromBuffer(32, Text.compare, buffer);

// insert (write)
let originalValue = BTree.insert(t, Text.compare, "John", 52);

// paginate through a collection in ascending order grab first 10 and the next key
let { results; nextKey } = BTree.scanLimit(t, Text.compare, "A", "Z", #fwd, 10);

// get min element
let minElement = BTree.min(t);
```
... and much more, head to the [docs](https://canscale.github.io/StableHeapBTreeMap/BTree.html) to see the full API.

## License

StableHeapBTreeMap is distributed under the terms of the Apache License (Version 2.0).

See LICENSE for details.