module Elasticsearch::Model::Extensions::AssociationPathFinding::ShortestPath::ClassMethods
Public Instance Methods
breadth_first_search(node, &block)
click to toggle source
# File lib/elasticsearch/model/extensions/association_path_finding/shortest_path.rb, line 64 def breadth_first_search(node, &block) original_paths = node.each.map { |e| [e] } paths = original_paths depth = 0 loop { a = paths.select { |p| if block.call(p.last) p end } return a if a.size != 0 raise RuntimeError, 'Maximum depth exceeded while calculating the shortest path' if depth >= Elasticsearch::Model::Extensions::ShortestPath::MAX_DEPTH paths = paths.flat_map { |p| p.last.destination.each.map { |e| p + [e] } } depth += 1 } end
depth_first_search(node, &block)
click to toggle source
# File lib/elasticsearch/model/extensions/association_path_finding/shortest_path.rb, line 90 def depth_first_search(node, &block) node.each.select do |edge| if block.call(edge) [[edge]] else depth_first_search(edge.destination, &block).map do |path| [edge] + path end end end end