321: def splice!(other, type)
322:
323:
324:
325:
326:
327:
328: containers = other.topsort.find_all { |v| v.is_a?(type) and vertex?(v) }
329: containers.each do |container|
330:
331: children = other.adjacent(container, :direction => :out)
332:
333:
334: if children.empty?
335: remove_vertex!(container)
336: next
337: end
338:
339:
340: [:in, :out].each do |dir|
341: edges = adjacent(container, :direction => dir, :type => :edges)
342: edges.each do |edge|
343: children.each do |child|
344: if dir == :in
345: s = edge.source
346: t = child
347: else
348: s = child
349: t = edge.target
350: end
351:
352: add_edge(s, t, edge.label)
353: end
354:
355:
356: remove_edge!(edge)
357: end
358: end
359: remove_vertex!(container)
360: end
361: end