Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/canscale/LinkedList
Stable and mutable singly and doubly linked lists in Motoko
https://github.com/canscale/LinkedList
Last synced: 3 months ago
JSON representation
Stable and mutable singly and doubly linked lists in Motoko
- Host: GitHub
- URL: https://github.com/canscale/LinkedList
- Owner: canscale
- License: apache-2.0
- Created: 2022-04-07T23:17:51.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-04-08T00:17:57.000Z (over 2 years ago)
- Last Synced: 2024-04-19T01:33:33.314Z (7 months ago)
- Language: Motoko
- Homepage:
- Size: 13.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-motoko - Stable LinkedList - (Heap-based) Stable, mutable singly & doubly linked lists in Motoko. (Libraries / Data structures)
README
# LinkedList
Stable and mutable singly and doubly linked lists in Motoko
## Motivation
**Careful, these operations mutate the underlying linked lists involved!**
Sometimes you want both an efficient prepend and append, and the fact that your underlying data structure is mutating just isn't as important as the consistent performance of operations on that data.
## API Documentation
API documentation for this library can be found at https://canscale.github.io/LinkedList
## Usage
Install vessel and ensure this is included in your package-set.dhall and vessel.dhallSingly Linked List Example
```
import LL "mo:linkedlist/LinkedList";
import Nat "mo:base/Nat";
...// create, append, and prepend to a linked list
var l1 = LL.empty();
l1 := LL.append(l1, 5);
l1 := LL.prepend(l1, 3);// merge two linked lists
var l2 = LL.empty();
l2 := LL.append(l2, 8);
l2 := LL.append(l2, 10);// Careful! This mutates both l1 and l2
let l3 = LL.merge(l1, l2);
``````
import DLL "mo:linkedlist/DoublyLinkedList";
import Nat "mo:base/Nat";
...// create, append, and prepend to a doubly linked list
var l1 = DLL.empty();
l1 := DLL.append(l1, 5);
l1 := DLL.prepend(l1, 3);// merge two doubly linked lists
var l2 = DLL.empty();
l2 := DLL.append(l2, 8);
l2 := DLL.append(l2, 10);// Careful! This mutates both l1 and l2
let l3 = DLL.merge(l1, l2);// pop elements from the head and tail of a doubly linked list
let (l4, poppedHead) = DLL.popHead(l3);
let (l5, poppedTail) = DLL.popTail(l3);
```## License
StableRBTree is distributed under the terms of the Apache License (Version 2.0).See LICENSE for details.