module Sprockets::Utils
def dfs_paths(path)
node - Current node to get children of
block -
path - Initial Array node path
TODO: Rename function.
along the way.
Internal: Post-order Depth-First search algorithm that gathers all paths
def dfs_paths(path) paths = [] stack = [path] seen = Set.new while path = stack.pop seen.add(path.last) paths << path children = yield path.last children.reverse_each do |node| stack.push(path + [node]) unless seen.include?(node) end end paths end