Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sardariuss/MotokoStableBTree
https://forum.dfinity.org/t/icdevs-org-bounty-24-stablebtree-mokoko-up-to-10k/14867
https://github.com/sardariuss/MotokoStableBTree
Last synced: 3 months ago
JSON representation
https://forum.dfinity.org/t/icdevs-org-bounty-24-stablebtree-mokoko-up-to-10k/14867
- Host: GitHub
- URL: https://github.com/sardariuss/MotokoStableBTree
- Owner: sardariuss
- License: mit
- Created: 2022-09-16T12:52:10.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-06T02:14:21.000Z (over 1 year ago)
- Last Synced: 2024-08-04T00:14:19.692Z (6 months ago)
- Language: Motoko
- Size: 208 KB
- Stars: 10
- Watchers: 3
- Forks: 8
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-motoko - MotokoStableBTree
- awesome-motoko - MotokoStableBTree
README
# MotokoStableBTree
https://forum.dfinity.org/t/icdevs-org-bounty-24-stablebtree-mokoko-up-to-10k/14867## Usage
```
import BTree "mo:StableBTree/BTree"// Arbitrary use of (Nat32, Text) for (key, value) types
let n32conv = BTree.n32conv;
let tconv = BTree.tconv(64); // Max 16 characters
stable let _btree = BTree.new(n32conv, tconv);let old = BTree.put(_btree, n32conv, 0, tconv, "hello");
let new = BTree.get(_btree, n32conv, 0, tconv);
let size = BTree.size(_btree);assert Option.isNull(old);
assert Option.isSome(new);
assert size == 1;
```For further examples see singleBTree.mo and multipleBTrees.mo in the test/integration directory.
## Limitations
- At the moment there is no way to test that a function successfully traps, so these tests are commented out.
- The generation of documentation fails with Fatal error: exception (Invalid_argument "index out of bounds").
- The current implementation uses the Big Endian byte order for all the serialization/deserialization. At the time of writing (2022/11/24), the Rust BTree implementation still uses some little endian (to convert size of keys/values in the node, and possibly for other structs via the use of core::slice::from_raw_parts). Hence the memory representations of the BTree in Motoko and Rust are NOT the same, i.e. it is not possible to load a BTree in Motoko that has been saved in Rust and vice-versa.## Funding
This library was initially incentivized by [ICDevs](https://icdevs.org/). You can view more about the bounty on the [forum](https://forum.dfinity.org/t/completed-icdevs-org-bounty-24-stablebtree-mokoko-up-to-10k/14867/23) or [website](https://icdevs.org/bounties/2022/08/14/Motoko-StableBTree.html). The bounty was funded by The ICDevs.org community and the DFINITY Foundation and the award was paid to @sardariuss. If you use this library and gain value from it, please consider a [donation](https://icdevs.org/donations.html) to ICDevs