floor_of: Get the largest key less than or equal to a given key

Description Usage Arguments Details Examples

Description

Get the largest key less than or equal to a given key

Usage

1
floor_of(tree, key, ...)

Arguments

tree

A bst

key

The key to use in comparisons

...

Other arguments (not used)

Details

If the key exists in the tree, then it is returned. If the key is smaller than the smallest key in the tree, then NULL is returned. Otherwise, the largest key that is smaller than the given key is returned.

Examples

1
2
3
4
5
mytree <- bst()
mytree <- insert(mytree, 1, "val1")
mytree <- insert(mytree, 3, "val2")
retrieve(mytree, floor_of(mytree, 2))
retrieve(mytree, floor_of(mytree, 4))

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