retrieval v0.9.1 Retrieval
Provides an interface for creating and collecting data from the trie data structure.
Summary
Functions
Returns whether or not a trie contains a given binary key
Inserts a binary or list of binaries into an existing trie
Returns a new trie. Providing no arguments creates an empty trie. Optionally a binary or
list of binaries can be passed to new/1
Collects all binaries match a given pattern. Returns either a list of matches
or an error in the form {:error, reason}
Collects all binaries that begin with a given prefix
Functions
Returns whether or not a trie contains a given binary key.
Examples
Retrieval.new(~w/apple apply ape ample/) |> Retrieval.contains?("apple")
true
Retrieval.new(~w/apple apply ape ample/) |> Retrieval.contains?("zebra")
false
Inserts a binary or list of binaries into an existing trie.
Examples
Retrieval.new |> Retrieval.insert("apple")
%Retrieval.Trie{...}
Retrieval.new(~w/apple apply ape ample/) |> Retrieval.insert(~w/zebra corgi/)
%Retrieval.Trie{...}
Returns a new trie. Providing no arguments creates an empty trie. Optionally a binary or
list of binaries can be passed to new/1
.
Examples
Retrieval.new
%Retrieval.Trie{...}
Retrieval.new("apple")
%Retrieval.Trie{...}
Retrieval.new(~w/apple apply ape ample/)
%Retrieval.Trie{...}
Collects all binaries match a given pattern. Returns either a list of matches
or an error in the form {:error, reason}
.
Patterns
`*` - Wildcard, matches any character.
`[...]` - Inclusion group, matches any character between brackets.
`[^...]` - Exclusion group, matches any character not between brackets.
`{...}` - Capture group, must be named and can be combined with an
inclusion or exclusion group, otherwise treated as a wildcard.
All future instances of same name captures are swapped with
the value of the initial capture.
Examples
Retrieval.new(~w/apple apply ape ample/) |> Retrieval.pattern("a{1}{1}**")
["apple", "apply"]
Retrieval.new(~w/apple apply ape ample/) |> Retrieval.pattern("*{1[^p]}{1}**")
[]
Retrieval.new(~w/apple apply zebra house/) |> Retrieval.pattern("[hz]****")
["house", "zebra"]
Retrieval.new(~w/apple apply zebra house/) |> Retrieval.pattern("[hz]***[^ea]")
[]
Retrieval.new(~w/apple apply zebra house/) |> Retrieval.pattern("[hz]***[^ea")
{:error, "Dangling group (exclusion) starting at column 8, expecting ]"}