TST (Elixir Algorithms and Data Structures (eads) v0.1.0) View Source
This module supports the Ternary Search Trie data structure.
Link to this section Summary
Functions
Query the TST to see if a key is a valid key
Insert a key-value pair into a TST. It is acceptable to pass nil as the first argument - a new TST will then be created.
Creates an empty ternary search trie data structure
Link to this section Functions
Specs
exists?( nil | %TST{ item: term(), left: term(), middle: term(), right: term(), value: term() }, String.t() ) :: boolean()
Query the TST to see if a key is a valid key
Parameters
- tst: The Ternary Search Trie if you have saved one, or nil (although this doesn't make much sense to look for valid keys in)
- key: The key which you are querying whether is valid or not
Examples
iex> TST.new() |> TST.insert("key", "value") |> TST.exists?("key")
true
iex> TST.new() |> TST.insert("key", "value") |> TST.exists?("a whole other key")
false
Specs
insert( %TST{ item: term(), left: term(), middle: term(), right: term(), value: term() }, String.t(), any() ) :: %TST{ item: term(), left: term(), middle: term(), right: term(), value: term() }
Insert a key-value pair into a TST. It is acceptable to pass nil as the first argument - a new TST will then be created.
Parameters
- tst: A Ternary Search Trie map or nil (no tree yet created)
- key: A String key in which to associate a value with
- value: The value that you want to have stored. Can be of any type
Examples
iex> TST.new() |> TST.insert("key", "value")
%TST{
item: nil,
left: nil,
middle: %TST{
item: nil,
left: nil,
middle: %TST{item: "value", left: nil, middle: nil, right: nil, value: "y"},
right: nil,
value: "e"
},
right: nil,
value: "k"
}
Specs
Creates an empty ternary search trie data structure
Returns %TST{}
Examples
iex> TST.new()
%TST{item: nil, left: nil, middle: nil, right: nil, value: nil}