infu / StableHeapBTreeMap

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

StableHeapBTreeMap

A functional, heap-based BTree 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<Text, Nat>(?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<Text, Nat>(32, Text.compare, array);
let t = BTree.fromBuffer<Text, Nat>(32, Text.compare, buffer);

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

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

// get min element
let minElement = BTree.min<Text, Nat>(t);

... and much more, head to the docs to see the full API.

License

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

See LICENSE for details.

About

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

License:Apache License 2.0


Languages

Language:Motoko 95.2%Language:Modelica 4.3%Language:JavaScript 0.2%Language:Dhall 0.2%Language:Makefile 0.2%