module Sprockets::Utils

def dfs(initial)

Returns a Set of nodes.

node - Current node to get children of
block -
initial - Initial Array of nodes to traverse.

Used for resolving asset dependencies.

Internal: Post-order Depth-First search algorithm.
def dfs(initial)
  nodes, seen = Set.new, Set.new
  stack = Array(initial).reverse
  while node = stack.pop
    if seen.include?(node)
      nodes.add(node)
    else
      seen.add(node)
      stack.push(node)
      stack.concat(Array(yield node).reverse)
    end
  end
  nodes
end