Commit 2867d7b0 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Add conversion from Vertex and Edge to int and tuple

The following conversions are now possible: int(v) and tuple(e), where v
and e are Vertex and Edge instances, respectively.
parent ca4c120f
......@@ -402,6 +402,7 @@ void GraphInterface::ExportPythonInterface() const
.def(python::self == python::self)
.def(python::self != python::self)
.def("__str__", &PythonVertex::GetString)
.def("__int__", &PythonVertex::GetIndex)
.def("__hash__", &PythonVertex::GetHash);
set<string> v_iterators;
......
......@@ -198,6 +198,11 @@ public:
return hash<size_t>()(_gi._vertex_index[_v]);
}
size_t GetIndex() const
{
return _gi._vertex_index[_v];
}
bool operator==(const PythonVertex& other) const
{
CheckValid();
......
......@@ -865,4 +865,8 @@ def _all_neighbours(self):
yield v
Vertex.all_neighbours = _all_neighbours
def _iter(self):
"""Iterate over the source and target"""
for v in [self.source(), self.target()]:
yield v
Edge.__iter__ = _iter
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment