longest_match: Find the longest match in a trie

View source: R/match.R

longest_matchR Documentation

Find the longest match in a trie

Description

longest_match accepts a trie and a character vector and returns the value associated with whichever key had the longest match to each entry in the character vector. A trie of "binary" and "bind", for example, with an entry-to-compare of "binder", will match to "bind".

Usage

longest_match(trie, to_match, include_keys = FALSE)

Arguments

trie

a trie object, created with trie

to_match

a character vector containing the strings to match against the trie's keys.

include_keys

a logical value indicating whether to include the keys in the returned results or not. If TRUE (not the default) the returned object will be a data.frame, rather than a vector.

See Also

prefix_match and greedy_match for prefix and greedy matching, respectively.

Examples

trie <- trie(keys = c("afford", "affair", "available", "binary", "bind", "blind"),
                   values = c("afford", "affair", "available", "binary", "bind", "blind"))
longest_match(trie, "binder")


triebeard documentation built on March 7, 2023, 6:55 p.m.