Decode SourceDecodeTrieNode

class Node

A single node in the trie.

Definitions

attr_accessor :values

A mutable array of all values that terminate at this node.

Signature

attribute Array

attr :children

A hash table of all children nodes, indexed by name.

Signature

attribute Hash(String, Node)

def lookup(path, index = 0)

Look up a lexical path starting at this node.

Signature

parameter path Array(String)

The path to resolve.

returns Node | Nil

Implementation

def lookup(path, index = 0)
	if index < path.size
		if child = @children[path[index]]
			return child.lookup(path, index+1)
		end
	else
		return self
	end
end

def traverse(path = [], &block)

Traverse the trie from this node. Invoke descend.call to traverse the children of the current node.

Signature

parameter path Array(String)

The current lexical path.

Implementation

def traverse(path = [], &block)
	yield(path, self, ->{
		@children.each do |name, node|
			node.traverse([*path, name], &block)
		end
	})
end