The convention is to name the module alias after the file name it is defined in:
import RBTree "mo:base/RBTree";
Type RBTree.Color
Type RBTree.Tree<K, V>
Class RBTree.RBtree<K, V>
Class methods
Method share
Method unShare
Method get
Method replace
Method put
Method delete
Method remove
Method entries
Method entriesRev
Module public functions
Function iter
Function size
import RBTree "mo:base/RBTree";
type Color = RBTree.Color;
type RedBlue = Color;
import RBTree "mo:base/RBTree";
type Tree<Text, Int> = RBTree.Tree<Text, Int>;
type MyTree = Tree<Text, Int>;
class RBTree<K, V>(compare : (K, K) -> O.Order)
To construct a rbtree object, we use the RBTree
class:
import RBTree "mo:base/RBTree";
import Text "mo:base/Text";
let textIntTree = RBTree.RBTree<Text, Int>(Text.compare);
func share() : Tree<K, V>
The function share
takes no argument and returns an value of type Tree<K, V>
.
import RBTree "mo:base/RBTree";
import Text "mo:base/Text";
let textIntTree = RBTree.RBTree<Text, Int>(Text.compare);
textIntTree.put("bitcoin", 1);
textIntTree.put("ETH", 2);
let share : RBTree.Tree<Text, Int> = textIntTree.share();
let treeSize : Nat = RBTree.size(share)
func unShare(t : Tree<K, V>) : ()
Parameters | |
Variable argument | t : Tree<K, V> |
Return type | () |
import RBTree "mo:base/RBTree";
import Text "mo:base/Text";
import Iter "mo:base/Iter";
let textIntTree = RBTree.RBTree<Text, Int>(Text.compare);
textIntTree.put("bitcoin", 1);
textIntTree.put("ETH", 2);
let share : RBTree.Tree<Text, Int> = textIntTree.share();
let unshare : () = textIntTree.unshare(share);
let iter : Iter.Iter<(Text, Int)> = textIntTree.entries();
let array : [(Text, Int)] = Iter.toArray(iter)
func get(key : K) : ?V
Parameters | |
Variable argument | key : K |
Return type | ?V |
import RBTree "mo:base/RBTree";
import Text "mo:base/Text";
let textIntTree = RBTree.RBTree<Text, Int>(Text.compare);
textIntTree.put("bitcoin", 1);
textIntTree.put("ETH", 2);
let get : ?Int = textIntTree.get("bitcoin");
func replace(key : K, value : V) : ?V
Parameters | |
Variable argument1 | key : K |
Variable argument2 | value : V |
Return type | ?V |
import RBTree "mo:base/RBTree";
import Text "mo:base/Text";
let textIntTree = RBTree.RBTree<Text, Int>(Text.compare);
textIntTree.put("bitcoin", 1);
textIntTree.put("ETH", 2);
let replace : ?Int = textIntTree.replace("bitcoin", 2);
func put(key : K, value : V) : ()
Parameters | |
Variable argument1 | key : K |
Variable argument2 | value : V |
Return type | () |
import RBTree "mo:base/RBTree";
import Text "mo:base/Text";
import Iter "mo:base/Iter";
let textIntTree = RBTree.RBTree<Text, Int>(Text.compare);
textIntTree.put("bitcoin", 1);
textIntTree.put("ETH", 2);
textIntTree.put("ICP", 3);
let iter : Iter.Iter<(Text, Int)> = textIntTree.entries();
let array : [(Text, Int)] = Iter.toArray(iter)
func delete(key : K) : ()
Parameters | |
Variable argument | key : K |
Return type | () |
import RBTree "mo:base/RBTree";
import Text "mo:base/Text";
import Iter "mo:base/Iter";
let textIntTree = RBTree.RBTree<Text, Int>(Text.compare);
textIntTree.put("bitcoin", 1);
textIntTree.put("ETH", 2);
textIntTree.put("ICP", 3);
let delete : () = textIntTree.delete("bitcoin");
let iter : Iter.Iter<(Text, Int)> = textIntTree.entries();
let array : [(Text, Int)] = Iter.toArray(iter)
func remove(key : K) : ?V
Parameters | |
Variable argument | key : K |
Return type | ?V |
import RBTree "mo:base/RBTree";
import Text "mo:base/Text";
import Iter "mo:base/Iter";
let textIntTree = RBTree.RBTree<Text, Int>(Text.compare);
textIntTree.put("bitcoin", 1);
textIntTree.put("ETH", 2);
textIntTree.put("ICP", 3);
let remove : ?Int = textIntTree.remove("bitcoin");
let iter : Iter.Iter<(Text, Int)> = textIntTree.entries();
let array : [(Text, Int)] = Iter.toArray(iter)
func entries() : I.Iter<(K, V)>
The function entries
takes no argument and returns an value of type I.Iter<(K, V)>
.
import RBTree "mo:base/RBTree";
import Text "mo:base/Text";
import Iter "mo:base/Iter";
let textIntTree = RBTree.RBTree<Text, Int>(Text.compare);
textIntTree.put("bitcoin", 1);
textIntTree.put("ETH", 2);
textIntTree.put("ICP", 3);
let entries : Iter.Iter<(Text, Int)> = textIntTree.entries();
let array : [(Text, Int)] = Iter.toArray(entries)
func entriesRev() : I.Iter<(K, V)>
Parameters | |
Variable argument | () |
Return type | I.Iter<(K, V)> |
import RBTree "mo:base/RBTree";
import Text "mo:base/Text";
import Iter "mo:base/Iter";
let textIntTree = RBTree.RBTree<Text, Int>(Text.compare);
textIntTree.put("bitcoin", 1);
textIntTree.put("ETH", 2);
textIntTree.put("ICP", 3);
let entriesRev : Iter.Iter<(Text, Int)> = textIntTree.entriesRev();
let array : [(Text, Int)] = Iter.toArray(entriesRev)
func iter<X, Y>(
tree : Tree<X, Y>,
direction : {#fwd; #bwd}
) : I.Iter<(X, Y)>
Parameters | |
Generic parameters | X, Y |
Variable argument1 | tree : Tree<X< Y> |
Variable argument2 | direction : {#fwd; #bwd} |
Return type | I.Iter<(X, Y)> |
import RBTree "mo:base/RBTree";
import Text "mo:base/Text";
import Iter "mo:base/Iter";
let textIntTree = RBTree.RBTree<Text, Int>(Text.compare);
textIntTree.put("bitcoin", 1);
textIntTree.put("ETH", 2);
textIntTree.put("ICP", 3);
let share : RBTree.Tree<Text, Int> = textIntTree.share();
let iter : Iter.Iter<(Text, Int)> = RBTree.iter<Text, Int>(share, #bwd);
let array : [(Text, Int)] = Iter.toArray(iter)
func size<X, Y>(
t : Tree<X, Y>
) : Nat
Parameters | |
Generic parameters | X, Y |
Variable argument | t : Tree<X< Y> |
Return type | Nat |
import RBTree "mo:base/RBTree";
import Text "mo:base/Text";
let textIntTree = RBTree.RBTree<Text, Int>(Text.compare);
textIntTree.put("bitcoin", 1);
textIntTree.put("ETH", 2);
let share : RBTree.Tree<Text, Int> = textIntTree.share();
let treeSize : Nat = RBTree.size(share)