/src/igraph/src/operators/add_edge.c
Line | Count | Source |
1 | | /* |
2 | | IGraph library. |
3 | | Copyright (C) 2005-2020 The igraph development team |
4 | | |
5 | | This program is free software; you can redistribute it and/or modify |
6 | | it under the terms of the GNU General Public License as published by |
7 | | the Free Software Foundation; either version 2 of the License, or |
8 | | (at your option) any later version. |
9 | | |
10 | | This program is distributed in the hope that it will be useful, |
11 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | GNU General Public License for more details. |
14 | | |
15 | | You should have received a copy of the GNU General Public License |
16 | | along with this program; if not, write to the Free Software |
17 | | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | | 02110-1301 USA |
19 | | |
20 | | */ |
21 | | |
22 | | #include "igraph_operators.h" |
23 | | |
24 | | #include "igraph_interface.h" |
25 | | |
26 | | /** |
27 | | * \function igraph_add_edge |
28 | | * \brief Adds a single edge to a graph. |
29 | | * |
30 | | * </para><para> |
31 | | * For directed graphs the edge points from \p from to \p to. |
32 | | * |
33 | | * </para><para> |
34 | | * Note that if you want to add many edges to a big graph, then it is |
35 | | * inefficient to add them one by one, it is better to collect them into |
36 | | * a vector and add all of them via a single \ref igraph_add_edges() call. |
37 | | * \param igraph The graph. |
38 | | * \param from The id of the first vertex of the edge. |
39 | | * \param to The id of the second vertex of the edge. |
40 | | * \return Error code. |
41 | | * |
42 | | * \sa \ref igraph_add_edges() to add many edges, \ref |
43 | | * igraph_delete_edges() to remove edges and \ref |
44 | | * igraph_add_vertices() to add vertices. |
45 | | * |
46 | | * Time complexity: O(|V|+|E|), the number of edges plus the number of |
47 | | * vertices. |
48 | | */ |
49 | 124k | igraph_error_t igraph_add_edge(igraph_t *graph, igraph_integer_t from, igraph_integer_t to) { |
50 | 124k | igraph_vector_int_t edges; |
51 | | |
52 | 124k | IGRAPH_VECTOR_INT_INIT_FINALLY(&edges, 2); |
53 | | |
54 | 124k | VECTOR(edges)[0] = from; |
55 | 124k | VECTOR(edges)[1] = to; |
56 | 124k | IGRAPH_CHECK(igraph_add_edges(graph, &edges, NULL)); |
57 | | |
58 | 124k | igraph_vector_int_destroy(&edges); |
59 | 124k | IGRAPH_FINALLY_CLEAN(1); |
60 | 124k | return IGRAPH_SUCCESS; |
61 | 124k | } |