Sha256: 8ad53e4b9a4b62d70ce4a3cf8064b3c8114349c3443043e4016d8f1ee68bb8bc
Contents?: true
Size: 761 Bytes
Versions: 13
Compression:
Stored size: 761 Bytes
Contents
require File.join(File.dirname(__FILE__), 'tree') # A Trie[http://en.wikipedia.org/wiki/Trie] is an associative access tree structure. # # @example # trie = Trie.new # trie[:a, :b] = 1 # trie[:a, :b] #=> 1 # trie[:a, :c] #=> nil class Trie # Creates a new empty Trie. def initialize @tree = Tree.new end # @return the value at the given trie path def [](*path) tree = @tree[nil, *path] tree.value if tree end # @return the top_level Tree for this trie def to_tree @tree end # Sets the value for a node path. # # @example # trie = Trie.new # trie[:a, :b] = 1 # trie[:a, :b] #=> 1 def []=(*path_and_value) value = path_and_value.pop @tree.fill(nil, *path_and_value).value = value end end
Version data entries
13 entries across 13 versions & 1 rubygems