Coverage Report

Created: 2025-11-24 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/igraph/src/graph/basic_query.c
Line
Count
Source
1
/*
2
   igraph library.
3
   Copyright (C) 2005-2012  Gabor Csardi <csardi.gabor@gmail.com>
4
   334 Harvard street, Cambridge, MA 02139 USA
5
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 2 of the License, or
9
   (at your option) any later version.
10
11
   This program is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
   02110-1301 USA
20
21
*/
22
23
#include "igraph_datatype.h"
24
#include "igraph_types.h"
25
#include "igraph_interface.h"
26
#include "igraph_structural.h"
27
28
/**
29
 * \ingroup structural
30
 * \function igraph_are_adjacent
31
 * \brief Decides whether two vertices are adjacent.
32
 *
33
 * Decides whether there are any edges that have \p v1 and \p v2
34
 * as endpoints. This function is of course symmetric for undirected
35
 * graphs.
36
 *
37
 * \param graph The graph object.
38
 * \param v1 The first vertex.
39
 * \param v2 The second vertex.
40
 * \param res Boolean, \c true if there is an edge from
41
 *         \p v1 to \p v2, \c false otherwise.
42
 * \return The error code \c IGRAPH_EINVVID is returned if an invalid
43
 *         vertex ID is given.
44
 *
45
 * Time complexity: O( min(log(d1), log(d2)) ),
46
 * d1 is the (out-)degree of \p v1 and d2 is the (in-)degree of \p v2.
47
 */
48
igraph_error_t igraph_are_adjacent(const igraph_t *graph,
49
                         igraph_int_t v1, igraph_int_t v2,
50
0
                         igraph_bool_t *res) {
51
52
0
    igraph_int_t nov = igraph_vcount(graph);
53
0
    igraph_int_t eid = -1;
54
55
0
    if (v1 < 0 || v2 < 0 || v1 > nov - 1 || v2 > nov - 1) {
56
0
        IGRAPH_ERROR("Invalid vertex ID when checking if two vertices are connected.", IGRAPH_EINVVID);
57
0
    }
58
59
0
    igraph_get_eid(graph, &eid, v1, v2, IGRAPH_DIRECTED, /*error=*/ false);
60
0
    *res = (eid >= 0);
61
62
0
    return IGRAPH_SUCCESS;
63
0
}