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
be9f0a3e
Commit
be9f0a3e
authored
Nov 25, 2012
by
Tiago Peixoto
Browse files
Implement faster addition of many vertices
parent
254721ac
Changes
3
Show whitespace changes
Inline
Side-by-side
doc/quickstart.rst
View file @
be9f0a3e
...
...
@@ -122,12 +122,13 @@ vertex of an edge, respectively.
The :meth:`~graph_tool.Graph.add_vertex` method also accepts an optional
parameter which specifies the number of vertices to create. If this
value is greater than 1, it returns a list of vertex descriptors:
value is greater than 1, it returns an iterator on the added vertex
descriptors:
.. doctest::
>>> vlist = g.add_vertex(10)
>>> print(len(vlist))
>>> print(len(
list(
vlist))
)
10
Edges and vertices can also be removed at any time with the
...
...
src/graph/graph_python_interface.cc
View file @
be9f0a3e
...
...
@@ -126,9 +126,16 @@ python::object get_edges(python::object g)
return
iter
;
}
python
::
object
add_vertex
(
python
::
object
g
)
python
::
object
add_vertex
(
python
::
object
g
,
size_t
n
)
{
GraphInterface
&
gi
=
python
::
extract
<
GraphInterface
&>
(
g
().
attr
(
"_Graph__graph"
));
if
(
n
>
1
)
{
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
add_vertex
(
gi
.
GetGraph
());
return
python
::
object
();
}
return
python
::
object
(
PythonVertex
(
g
,
add_vertex
(
gi
.
GetGraph
())));
}
...
...
src/graph_tool/__init__.py
View file @
be9f0a3e
...
...
@@ -1091,18 +1091,15 @@ class Graph(object):
def
add_vertex
(
self
,
n
=
1
):
"""Add a vertex to the graph, and return it. If ``n > 1``, ``n``
vertices are inserted and a
list
is returned."""
vertices are inserted and a
n iterator over the new vertices
is returned."""
self
.
__check_perms
(
"add_vertex"
)
vlist
=
[]
vfilt
=
self
.
get_vertex_filter
()
for
i
in
range
(
n
):
v
=
libcore
.
add_vertex
(
weakref
.
ref
(
self
))
if
vfilt
[
0
]
is
not
None
:
vfilt
[
0
][
v
]
=
not
vfilt
[
1
]
vlist
.
append
(
v
)
if
n
==
1
:
return
vlist
[
0
]
return
vlist
v
=
libcore
.
add_vertex
(
weakref
.
ref
(
self
),
n
)
if
n
<=
1
:
return
v
else
:
pos
=
self
.
num_vertices
()
-
n
return
(
self
.
vertex
(
i
)
for
i
in
xrange
(
pos
,
pos
+
n
))
def
remove_vertex
(
self
,
vertex
):
"""Remove a vertex from the graph."""
...
...
Tiago Peixoto
@count0
mentioned in issue
#90 (closed)
·
Aug 06, 2014
mentioned in issue
#90 (closed)
mentioned in issue #90
Toggle commit list
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