Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add edge lookup by vertices

  • Loading branch information...
commit 7c09ddcc72f91902adcb2b0762734a51fcc89845 1 parent 2f97b26
@jamesdabbs authored
View
5 lib/steffi/edge_set.rb
@@ -30,5 +30,10 @@ def each
yield self[i]
end
end
+
+ def find pair, error=false
+ id = FFI::MemoryPointer.new :int
+ Igraph.get_eid @graph.pointer, id, pair.first, pair.last, @graph.directed?, error
+ end
end
end
View
10 lib/steffi/ffi.rb
@@ -41,11 +41,9 @@ def self.method_missing name, *args, &block
bind :destroy, [:pointer]
# 2.2 Basic query operations
- bind :vcount, [:pointer], :int
- bind :ecount, [:pointer], :int
- bind :edge, [:pointer, :int, :pointer, :pointer] # graph, edge #, &from, &to
-
- # graph, &edge #, from, to, 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]
# graph, &[edge #], &[pairs], &[path], directed?, error?
@@ -56,7 +54,7 @@ def self.method_missing name, *args, &block
bind :neighbors, [:pointer, :pointer, :int, :int] # graph, &[result], node, mode
bind :incident, [:pointer, :pointer, :int, :int] # graph, &[result], node, mode
- bind :is_directed, [:pointer], :bool # graph => directed?
+ bind :is_directed, [:pointer], :bool
# graph, &[results], vids, mode, loops?
bind :degree, [:pointer, :pointer, :int, :bool]
View
4 lib/steffi/graph.rb
@@ -36,6 +36,10 @@ def destroy
Igraph.destroy pointer
end
+ def directed?
+ Igraph.is_directed pointer
+ end
+
def vertices
VertexSet.new self
end
View
17 spec/steffi/graph_spec.rb
@@ -15,6 +15,8 @@
# expect { Steffi::Graph.famous 'non-existent' }.to raise_error(Steffi::Igraph::Error)
# end
+ # -- 2 -----
+
it 'can create empty graphs' do
g = Steffi::Graph.empty 5
g.vertices.should have(5).members
@@ -25,6 +27,11 @@
pending
end
+ it 'can create a directed graph' do
+ g = Steffi::Graph.empty 5, true
+ g.should be_directed
+ end
+
it 'can copy a graph' do
g = Steffi::Graph.empty 7
c = Steffi::Graph.copy g
@@ -42,8 +49,16 @@
g.edges.should have(1).member
end
- it 'can look up edges' do
+ it 'can look up edges by id' do
g = Steffi::Graph.full 5
g.edges.first.should == [0, 1]
end
+
+ it 'can look up edges by vertex' do
+ g = Steffi::Graph.full 5
+ g.edges.find([0, 1]).should == 0
+ end
+
+ pending 'can lookup directed edges'
+ pending 'can handle errors when looking up edges'
end
Please sign in to comment.
Something went wrong with that request. Please try again.