Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
59427bf3
Commit
59427bf3
authored
Oct 14, 2015
by
Tiago Peixoto
Browse files
Improve performance of Graph.edge(s,t) when the degrees of the vertices are unbalanced
parent
8caa6fa4
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/graph/graph_python_interface.cc
View file @
59427bf3
...
...
@@ -250,13 +250,34 @@ struct get_edge_dispatch
bool
all_edges
,
boost
::
python
::
list
&
es
)
const
{
std
::
shared_ptr
<
Graph
>
gp
=
retrieve_graph_view
<
Graph
>
(
gi
,
g
);
for
(
auto
e
:
out_edges_range
(
vertex
(
s
,
g
),
g
))
size_t
k_t
=
is_directed
::
apply
<
Graph
>::
type
::
value
?
in_degreeS
()(
t
,
g
)
:
out_degree
(
t
,
g
);
if
(
out_degree
(
s
,
g
)
<=
k_t
)
{
if
(
target
(
e
,
g
)
==
vertex
(
t
,
g
))
for
(
auto
e
:
out_edges_range
(
vertex
(
s
,
g
)
,
g
))
{
es
.
append
(
PythonEdge
<
Graph
>
(
gp
,
e
));
if
(
!
all_edges
)
break
;
if
(
target
(
e
,
g
)
==
vertex
(
t
,
g
))
{
es
.
append
(
PythonEdge
<
Graph
>
(
gp
,
e
));
if
(
!
all_edges
)
break
;
}
}
}
else
{
for
(
auto
e
:
in_or_out_edges_range
(
vertex
(
t
,
g
),
g
))
{
auto
w
=
is_directed
::
apply
<
Graph
>::
type
::
value
?
source
(
e
,
g
)
:
target
(
e
,
g
);
if
(
w
==
vertex
(
s
,
g
))
{
if
(
!
is_directed
::
apply
<
Graph
>::
type
::
value
)
e
.
inv
^=
true
;
es
.
append
(
PythonEdge
<
Graph
>
(
gp
,
e
));
if
(
!
all_edges
)
break
;
}
}
}
}
...
...
src/graph_tool/__init__.py
View file @
59427bf3
...
...
@@ -1763,8 +1763,9 @@ class Graph(object):
If ``add_missing == True``, a new edge is created and returned, if none
currently exists.
This operation will take :math:`O(k(s))` time, where :math:`k(s)` is the
out-degree of vertex :math:`s`.
This operation will take :math:`O(min(k(s), k(t)))` time, where
:math:`k(s)` and :math:`k(t)` are the out-degree and in-degree (or
out-degree if undirected) of vertices :math:`s` and :math:`t`.
"""
s
=
self
.
vertex
(
int
(
s
))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment