Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Find edge ids by pairs or path

  • Loading branch information...
commit ae0c0fbdbb02e5636183a05f0fb5b1117a89e227 1 parent 5a182a6
@jamesdabbs authored
View
26 lib/steffi/edge_set.rb
@@ -36,18 +36,18 @@ def find pair, error=false
Igraph.get_eid @graph.pointer, id, pair.first, pair.last, @graph.directed?, error
end
- # def find_pairs *pairs
- # edges = Vector.new
- # error = false
- # Igraph.get_eids @graph.pointer, edges.pointer, Vector.from_a(pairs), nil, @graph.directed?, error
- # edges
- # end
-
- # def find_path *vertices
- # edges = Vector.new
- # error = false
- # Igraph.get_eids @graph.pointer, edges.pointer, nil, Vector.from_a(pairs), nil, @graph.directed?, error
- # edges
- # end
+ def find_pairs *pairs
+ edges = Vector.null
+ error = false
+ Igraph.get_eids @graph.pointer, edges.pointer, Vector.from_a(pairs.flatten).pointer, nil, @graph.directed?, error
+ edges.map &:to_i
+ end
+
+ def find_path *vertices
+ edges = Vector.null
+ error = false
+ Igraph.get_eids @graph.pointer, edges.pointer, nil, Vector.from_a(*vertices).pointer, @graph.directed?, error
+ edges.map &:to_i
+ end
end
end
View
10 lib/steffi/ffi.rb
@@ -41,12 +41,10 @@ def self.method_missing name, *args, &block
bind :destroy, [:pointer]
# 4.2.2 Basic query operations
- bind :vcount, [:pointer], :int
- bind :ecount, [:pointer], :int
- bind :edge, [:pointer, :int, :pointer, :pointer]
- bind :get_eid, [:pointer, :pointer, :int, :int, :bool, :bool]
-
- # graph, &[edge #], &[pairs], &[path], directed?, error?
+ bind :vcount, [:pointer], :int
+ bind :ecount, [:pointer], :int
+ bind :edge, [:pointer, :int, :pointer, :pointer]
+ bind :get_eid, [:pointer, :pointer, :int, :int, :bool, :bool]
bind :get_eids, [:pointer, :pointer, :pointer, :pointer, :bool, :bool]
# graph, &[edge #]. &[pairs], &[path], directed?, error?
View
2  lib/steffi/vector.rb
@@ -21,7 +21,7 @@ def self.null
def self.from_a ary
v = new { |v| Igraph.vector_init v.pointer, 0 }
- ary.each { |i| v << i}
+ ary.each { |i| v << i }
v
end
View
16 spec/steffi/graph_spec.rb
@@ -62,15 +62,15 @@
pending 'can lookup directed edges'
pending 'can handle errors when looking up edges (eid, eids, eids_multi)'
- # it 'can look up a list of edges by vertex' do
- # g = Steffi::Graph.full 3
- # g.edges.find_pairs([0,1], [1,2]).should == [0, 1]
- # end
+ it 'can look up a list of edges by vertex' do
+ g = Steffi::Graph.full 3
+ g.edges.find_pairs([0,1], [1,2]).should == [0, 2]
+ end
- # it 'can look up a list of edges in a path' do
- # g = Steffi::Graph.full 3
- # g.edges.find_path([0,1,2]).should == [0, 1]
- # end
+ it 'can look up a list of edges in a path' do
+ g = Steffi::Graph.full 3
+ g.edges.find_path([0,1,2]).should == [0, 2]
+ end
it 'can look up neighbors' do
g = Steffi::Graph.full 5
Please sign in to comment.
Something went wrong with that request. Please try again.