Ecosyste.ms: Awesome

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

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 2 months ago
JSON representation

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

Lists

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.