Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 63 lines (57 sloc) 1.701 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
module Pacer::Core::Graph
  module PathRoute
    def transpose
      collect { |arraylist| arraylist.to_a }.transpose
    end

    def subgraph(target_graph = nil, opts = {})
      raise "Can't create a subgraph within itself." if target_graph == graph
      target_graph ||= Pacer.tg
      target_graph.vertex_name ||= graph.vertex_name
      missing_edges = Set[]
      bulk_job(nil, target_graph) do |path|
        path.select { |e| e.is_a? Pacer::Vertex }.each do |vertex|
          vertex.clone_into target_graph
        end
        path.select { |e| e.is_a? Pacer::Edge }.each do |edge|
          unless edge.clone_into target_graph, ignore_missing_vertices: true
            missing_edges << edge
          end
        end
      end
      if missing_edges.any?
        missing_edges.to_route(graph: graph, element_type: :edge).bulk_job nil, target_graph do |edge|
          edge.clone_into target_graph,
            ignore_missing_vertices: opts[:ignore_missing_vertices],
            show_missing_vertices: opts[:show_missing_vertices]
        end
      end
      target_graph
    end

    def payloads
      map element_type: :path do |path|
        path.map do |e|
          if e.is_a? Pacer::Payload::Element
            e.payload
          elsif e.is_a? Pacer::Wrappers::ElementWrapper
            e.element_payload
          end
        end
      end
    end

    def compact_paths
      map element_type: :path do |path|
        path.compact
      end
    end

    protected

    def configure_iterator(iter)
      if respond_to? :graph
        pipe = Pacer::Pipes::PathWrappingPipe.new(graph)
        pipe.setStarts iter
        pipe
      else
        iter
      end
    end
  end
end
Something went wrong with that request. Please try again.