def build
			fifo_q = Array.new
	
			# Set the failures for the nodes coming out of the root node.
			@root.get.each_pair do |item, node|
				node.failure = @root
				fifo_q.push node
			end

			# Set the failures in breadth-first search order
			# using a FIFO queue. A failure identifies the deepest node
			# that is a proper suffix of the current node. 
			while !fifo_q.empty?
				p_node = fifo_q.shift
				if p_node.get
					p_node.get.each_pair do |item, node|
						# Push the current node onto the queue, so any child
						# nodes can be processed later.
						fifo_q.push node 
					
						f_node = p_node.failure
						
						# Follow the failures until we find a goto transition
						# or arrive back at the root node
						while f_node.goto(item) == nil and !f_node.eql? @root
							f_node = f_node.failure
						end

						if f_node.eql? @root and f_node.goto(item) == nil
							node.failure = @root
						else
							node.failure = f_node.goto(item)
							if block_given?
								node.output = yield node.output, (node.failure).output
							else
								if node.output && (node.failure).output
									node.output = node.output + (node.failure).output
								elsif (node.failure).output
									node.output = (node.failure).output
								end
							end
						end
					end
				end
			end

			build_dfa if @type == :DFA

		end
def build
			fifo_q = Array.new
	
			# Set the failures for the nodes coming out of the root node.
			@root.get.each_pair do |item, node|
				node.failure = @root
				fifo_q.push node
			end

			# Set the failures in breadth-first search order
			# using a FIFO queue. A failure identifies the deepest node
			# that is a proper suffix of the current node. 
			while !fifo_q.empty?
				p_node = fifo_q.shift
				if p_node.get
					p_node.get.each_pair do |item, node|
						# Push the current node onto the queue, so any child
						# nodes can be processed later.
						fifo_q.push node 
					
						f_node = p_node.failure
						
						# Follow the failures until we find a goto transition
						# or arrive back at the root node
						while f_node.goto(item) == nil and !f_node.eql? @root
							f_node = f_node.failure
						end

						if f_node.eql? @root and f_node.goto(item) == nil
							node.failure = @root
						else
							node.failure = f_node.goto(item)
							if block_given?
								node.output = yield node.output, (node.failure).output
							else
								if node.output && (node.failure).output
									node.output = node.output + (node.failure).output
								elsif (node.failure).output
									node.output = (node.failure).output
								end
							end
						end
					end
				end
			end

			build_dfa if @type == :DFA

		end
Sets the failure transitions and output for each node.
 Call this method once all the patterns have been added to the Trie.

 Accepts an optional block that can be used to modify the output
 constructed from the node and its failure nodes.