bst: Create a new binary search tree

Description Usage Arguments Details Examples

Description

Creates a new, empty, binary search tree. A bst stores keys and values. You can insert new key-value pairs in, and you can retrieve values out by providing a key.

Usage

1
bst(keys = NULL, values = NULL, compare = compare_default)

Arguments

keys

(optional) keys to initially insert into the tree

values

(optional) values should be the same length as keys

compare

The comparator that the tree should use for ordering

Details

The default comparator will use <, so is defined for any types with which you can use <.

Note that there is no checking for consistency of keys.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
mytree <- bst()
mytree
# add ("a": 3) to the tree
mytree2 <- insert(mytree, "a", 3)

# no side-effects
mytree
mytree2
retrieve(mytree, "a") ## returns NULL
retrieve(mytree2, "a") ## 3

tarakc02/rbst documentation built on May 31, 2019, 3:55 a.m.