Module trie
The trie (i.e., from "retrieval") data structure was invented by
Edward Fredkin (it is a form of radix sort). The implementation stores
string suffixes as a list because it is a PATRICIA trie
(PATRICIA - Practical Algorithm to Retrieve Information
Coded in Alphanumeric, D.R.Morrison (1968)).
This Erlang trie implementation uses string (list of integers) keys and
is able to get performance close to the process dictionary when doing key
lookups (find or fetch, see http://okeuday.livejournal.com/16941.html).
Copyright © 2010-2018 Michael Truog
Version: 1.7.5 Nov 28 2019 11:51:14
------------------------------------------------------------------------
Authors: Michael Truog (mjtruog at protonmail dot com).
The trie (i.e., from "retrieval") data structure was invented by
Edward Fredkin (it is a form of radix sort). The implementation stores
string suffixes as a list because it is a PATRICIA trie
(PATRICIA - Practical Algorithm to Retrieve Information
Coded in Alphanumeric, D.R.Morrison (1968)).
This Erlang trie implementation uses string (list of integers) keys and
is able to get performance close to the process dictionary when doing key
lookups (find or fetch, see http://okeuday.livejournal.com/16941.html).
Utilizing this trie, it is possible to avoid generating dynamic atoms
in various contexts. Also, an added benefit to using this trie is that
the traversals preserve alphabetical ordering.
empty_trie() = []
nonempty_trie() = {integer(), integer(), tuple()}
trie() = nonempty_trie() | empty_trie()
append/3 |
. |
append_list/3 |
. |
erase/2 |
. |
erase_similar/2 |
. |
fetch/2 |
. |
fetch_keys/1 |
. |
fetch_keys_similar/2 |
. |
filter/2 |
. |
find/2 |
. |
find_match/2 |
All patterns held within the trie use a wildcard character "*" to represent
a regex of ".+". |
find_match2/2 |
All patterns held within the trie use the wildcard character "*" or "?"
to represent a regex of ".+". |
find_prefix/2 |
The atom 'prefix' is returned if the string supplied is a prefix
for a key that has previously been stored within the trie, but no
value was found, since there was no exact match for the string supplied. |
find_prefix_longest/2 |
. |
find_prefixes/2 |
The entries are returned in alphabetical order. |
find_similar/2 |
The first match is found based on alphabetical order. |
fold/3 |
Traverses in alphabetical order. |
fold_match/4 |
Traverses in alphabetical order. |
fold_similar/4 |
Traverses in alphabetical order. |
foldl/3 |
Traverses in alphabetical order. |
foldl_similar/4 |
Traverses in alphabetical order. |
foldr/3 |
Traverses in reverse alphabetical order. |
foldr_similar/4 |
Traverses in reverse alphabetical order. |
foreach/2 |
Traverses in alphabetical order. |
from_list/1 |
. |
is_key/2 |
. |
is_pattern/1 |
"*" is the wildcard character (equivalent to the ".+" regex). |
is_pattern2/1 |
"*" and "?" are wildcard characters (equivalent to the ".+" regex). |
is_prefix/2 |
The function returns true if the string supplied is a prefix
for a key that has previously been stored within the trie. |
is_prefixed/2 |
. |
is_prefixed/3 |
The prefix within the trie must match at least 1 character that is not
within the excluded list of characters. |
iter/2 |
Traverses in alphabetical order. |
itera/3 |
Traverses in alphabetical order. |
map/2 |
Traverses in reverse alphabetical order. |
merge/3 |
Update the second trie parameter with all of the elements
found within the first trie parameter. |
new/0 |
. |
new/1 |
The list may contain either: strings, 2 element tuples with a string as the
first tuple element, or tuples with more than 2 elements (including records)
with a string as the first element (second element if it is a record). |
pattern2_fill/2 |
The "*" and "?" wildcard characters may be used consecutively by this
function to have parameters concatenated (both are processed the same
way by this function). |
pattern2_fill/4 |
The "*" and "?" wildcard characters may be used consecutively by this
function to have parameters concatenated (both are processed the same
way by this function). |
pattern2_parse/2 |
"*" and "?" are wildcard characters (equivalent to the ".+" regex). |
pattern2_parse/3 |
"*" and "?" are wildcard characters (equivalent to the ".+" regex). |
pattern2_suffix/2 |
"*" and "?" are wildcard characters (equivalent to the ".+" regex). |
pattern_fill/2 |
The "*" wildcard character may be used consecutively by this function
to have parameters concatenated. |
pattern_fill/4 |
The "*" wildcard character may be used consecutively by this function
to have parameters concatenated. |
pattern_parse/2 |
"*" is the wildcard character (equivalent to the ".+" regex). |
pattern_parse/3 |
"*" is the wildcard character (equivalent to the ".+" regex). |
pattern_suffix/2 |
"*" is the wildcard character (equivalent to the ".+" regex). |
prefix/3 |
The reverse of append/3. |
size/1 |
. |
store/2 |
. |
store/3 |
. |
take/2 |
. |
to_list/1 |
The list is in alphabetical order. |
to_list_similar/2 |
. |
update/3 |
. |
update/4 |
. |
update_counter/3 |
. |
erase_similar(Similar::string(), Node::trie()) -> [string()]
fetch_keys(Node::trie()) -> [string()]
fetch_keys_similar(Similar::string(), Node::trie()) -> [string()]
filter(F::fun((string(), any()) -> boolean()), Node::trie()) -> trie()
find(T::string(), Node::trie()) -> {ok, any()} | error
find_match(Match::string(), Node::trie()) -> {ok, any(), any()} | error
All patterns held within the trie use a wildcard character "*" to represent
a regex of ".+". "**" within the trie will result in undefined behavior
(the pattern is malformed). The function will search for the most specific
match possible, given the input string and the trie contents. The input
string must not contain wildcard characters, otherwise a badarg exit
exception will occur. If you instead want to supply a pattern string to
match the contents of the trie, see fold_match/4.
find_match2(Match::string(), Node::trie()) -> {ok, any(), any()} | error
All patterns held within the trie use the wildcard character "*" or "?"
to represent a regex of ".+". "**", "??", "*?", or "?*" within the
trie will result in undefined behavior (the pattern is malformed).
The function will search for the most specific match possible, given the
input string and the trie contents. The input string must not contain
wildcard characters, otherwise a badarg exit exception will occur.
The "?" wildcard character consumes the shortest match to the next
character and must not be the the last character in the string
(the pattern would be malformed).
find_prefix(T::string(), X2::trie()) -> {ok, any()} | prefix | error
The atom 'prefix' is returned if the string supplied is a prefix
for a key that has previously been stored within the trie, but no
value was found, since there was no exact match for the string supplied.
find_prefix_longest(Match::string(), Node::trie()) -> {ok, string(), any()} | error
find_prefixes(Match::string(), Node::trie()) -> [{string(), any()}]
The entries are returned in alphabetical order.
find_similar(Similar::string(), Node::trie()) -> {ok, string(), any()} | error
The first match is found based on alphabetical order.
fold(F::fun((string(), any(), any()) -> any()), A::any(), Node::trie()) -> any()
Traverses in alphabetical order.
fold_match(Match::string(), F::fun((string(), any(), any()) -> any()), A::any(), Node::trie()) -> any()
Traverses in alphabetical order. Uses "*" as a wildcard character
within the pattern (it acts like a ".+" regex, and "**" is forbidden).
The trie keys must not contain wildcard characters, otherwise a badarg
exit exception will occur. If you want to match a specific string
without wildcards on trie values that contain wildcard characters,
see find_match/2.
fold_similar(Similar::string(), F::fun((string(), any(), any()) -> any()), A::any(), Node::trie()) -> any()
Traverses in alphabetical order.
foldl(F::fun((string(), any(), any()) -> any()), A::any(), Node::trie()) -> any()
Traverses in alphabetical order.
foldl_similar(Similar::string(), F::fun((string(), any(), any()) -> any()), A::any(), Node::trie()) -> any()
Traverses in alphabetical order.
foldr(F::fun((string(), any(), any()) -> any()), A::any(), Node::trie()) -> any()
Traverses in reverse alphabetical order.
foldr_similar(Similar::string(), F::fun((string(), any(), any()) -> any()), A::any(), Node::trie()) -> any()
Traverses in reverse alphabetical order.
foreach(F::fun((string(), any()) -> any()), Node::trie()) -> any()
Traverses in alphabetical order.
from_list(L::list()) -> trie()
is_key(T::string(), Node::trie()) -> boolean()
is_pattern(Pattern::string()) -> true | false
"*" is the wildcard character (equivalent to the ".+" regex).
"**" is forbidden.
is_pattern2(Pattern::string()) -> true | false
"*" and "?" are wildcard characters (equivalent to the ".+" regex).
"**", "??", "*?" and "?*" are forbidden. "?" must not be the last
character in the pattern.
is_prefix(T::string(), X2::trie()) -> true | false
The function returns true if the string supplied is a prefix
for a key that has previously been stored within the trie.
If no values with the prefix matching key(s) were removed from the trie,
then the prefix currently exists within the trie.
is_prefixed(T::string(), X2::trie()) -> true | false
is_prefixed(Key::string(), Exclude::string(), Node::trie()) -> true | false
The prefix within the trie must match at least 1 character that is not
within the excluded list of characters.
iter(F::fun((string(), any(), fun(() -> any())) -> any()), Node::trie()) -> ok
Traverses in alphabetical order.
itera(F::fun((string(), any(), any(), fun((any()) -> any())) -> any()), A::any(), Node::trie()) -> any()
Traverses in alphabetical order.
map(F::fun((string(), any()) -> any()), Node::trie()) -> trie()
Traverses in reverse alphabetical order.
Update the second trie parameter with all of the elements
found within the first trie parameter.
The list may contain either: strings, 2 element tuples with a string as the
first tuple element, or tuples with more than 2 elements (including records)
with a string as the first element (second element if it is a record).
If a list of records (or tuples larger than 2 elements) is provided,
the whole record/tuple is stored as the value.
pattern2_fill(FillPattern::string(), Parameters::[string()]) -> {ok, string()} | {error, parameters_ignored | parameter_missing}
The "*" and "?" wildcard characters may be used consecutively by this
function to have parameters concatenated (both are processed the same
way by this function).
pattern2_fill(FillPattern::string(), Parameters::[string()], ParametersSelected::[pos_integer()], ParametersStrictMatching::boolean()) -> {ok, string()} | {error, parameters_ignored | parameter_missing | parameters_selected_empty | {parameters_selected_ignored, [pos_integer()]} | {parameters_selected_missing, pos_integer()}}
The "*" and "?" wildcard characters may be used consecutively by this
function to have parameters concatenated (both are processed the same
way by this function).
pattern2_parse(Pattern::string(), L::string()) -> [string()] | error
"*" and "?" are wildcard characters (equivalent to the ".+" regex).
"**", "??", "*?" and "?*" are forbidden. "?" must not be the last
character in the pattern.
pattern2_parse(Pattern::string(), L::string(), Option::default | with_suffix | expanded) -> [string()] | {[string()], string()} | [string() | {exact, string()}] | error
"*" and "?" are wildcard characters (equivalent to the ".+" regex).
"**", "??", "*?" and "?*" are forbidden. "?" must not be the last
character in the pattern.
pattern2_suffix(Pattern::string(), L::string()) -> string() | error
"*" and "?" are wildcard characters (equivalent to the ".+" regex).
"**", "??", "*?" and "?*" are forbidden. "?" must not be the last
character in the pattern.
pattern_fill(FillPattern::string(), Parameters::[string()]) -> {ok, string()} | {error, parameters_ignored | parameter_missing}
The "*" wildcard character may be used consecutively by this function
to have parameters concatenated.
pattern_fill(FillPattern::string(), Parameters::[string()], ParametersSelected::[pos_integer()], ParametersStrictMatching::boolean()) -> {ok, string()} | {error, parameters_ignored | parameter_missing | parameters_selected_empty | {parameters_selected_ignored, [pos_integer()]} | {parameters_selected_missing, pos_integer()}}
The "*" wildcard character may be used consecutively by this function
to have parameters concatenated.
pattern_parse(Pattern::string(), L::string()) -> [string()] | error
"*" is the wildcard character (equivalent to the ".+" regex).
"**" is forbidden.
pattern_parse(Pattern::string(), L::string(), Option::default | with_suffix | expanded) -> [string()] | {[string()], string()} | [string() | {exact, string()}] | error
"*" is the wildcard character (equivalent to the ".+" regex).
"**" is forbidden.
pattern_suffix(Pattern::string(), L::string()) -> string() | error
"*" is the wildcard character (equivalent to the ".+" regex).
"**" is forbidden.
The reverse of append/3.
size(Node::trie()) -> non_neg_integer()
take(Key::string(), Node::trie()) -> {any(), trie()} | error
to_list(Node::trie()) -> [{string(), any()}]
The list is in alphabetical order.
to_list_similar(Similar::string(), Node::trie()) -> [{string(), any()}]
Generated by EDoc