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 1 month ago
JSON representation
A functional BTreeMap that can be used with a stable variable in heap memory
- Host: GitHub
- URL: https://github.com/canscale/StableHeapBTreeMap
- Owner: canscale
- License: apache-2.0
- Created: 2022-10-29T03:19:42.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-01T01:15:17.000Z (12 months ago)
- Last Synced: 2024-08-04T00:14:19.852Z (5 months ago)
- Language: Motoko
- Homepage:
- Size: 138 KB
- Stars: 5
- Watchers: 4
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-motoko - Stable BTree Map - Stable (Heap-based) BTreeMaps in Motoko. (Libraries / Data structures)
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.