class TernarySearch::Tree
- TernarySearch::Tree
- Reference
- Object
Overview
A Ternary Search Tree implementation https://en.wikipedia.org/wiki/Ternary_search_tree
tst = TernarySearch::Tree.new
tst.insert("polygon") # => nil
tst.insert("poly") # => nil
tst.search("polygon") # => true
tst.search("polygons") # => false
tst.search("poly") # => true
tst.search("gon") # => false
Defined in:
ternary_search/tree.crInstance Method Summary
-
#each_word(&)
Yields each word in the tree to the block, in alphabetical order.
-
#insert(string : String) : Nil
insert string into the tree
-
#max_word_size
Compute the size of the longest word in the tree.
-
#search(string : String) : Bool
search for string in the tree
- #value : Char | Nil
- #word_end? : Bool
-
#words
Returns an array of all the words in the tree, in alphabetical order.
Instance Method Detail
def each_word(&)
#
Yields each word in the tree to the block, in alphabetical order.
tst = TernarySearch::Tree.new
tst.insert("polygon") # => nil
tst.insert("triangle") # => nil
tst.words => ["polygon", "triangle"]
def insert(string : String) : Nil
#
insert string into the tree
tst = TernarySearch::Tree.new
tst.insert("polygon") # => nil
def search(string : String) : Bool
#
search for string in the tree
tst = TernarySearch::Tree.new
tst.insert("polygon") # => nil
tst.insert("triangle") # => nil
tst.search("polygon") # => true
tst.search("poly") # => false
tst.search("triangle") # => true
def words
#
Returns an array of all the words in the tree, in alphabetical order. It
is recommended that you do NOT use this on large trees because the memory
usage is large. Attempt to use #each_word
if possible instead.
tst = TernarySearch::Tree.new
tst.insert("polygon") # => nil
tst.insert("triangle") # => nil
tst.words => ["polygon", "triangle"]