File: igraph_adjlist.h

package info (click to toggle)
r-cran-igraph 0.7.1-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 14,280 kB
  • sloc: ansic: 150,105; cpp: 19,404; fortran: 3,777; yacc: 1,164; tcl: 931; lex: 484; makefile: 13; sh: 9
file content (238 lines) | stat: -rw-r--r-- 8,441 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/* -*- mode: C -*-  */
/* 
   IGraph library.
   Copyright (C) 2009-2012  Gabor Csardi <csardi.gabor@gmail.com>
   334 Harvard street, Cambridge, MA 02139 USA
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc.,  51 Franklin Street, Fifth Floor, Boston, MA 
   02110-1301 USA

*/

#ifndef IGRAPH_ADJLIST_H
#define IGRAPH_ADJLIST_H

#undef __BEGIN_DECLS
#undef __END_DECLS
#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
#else
# define __BEGIN_DECLS /* empty */
# define __END_DECLS /* empty */
#endif

#include "igraph_constants.h"
#include "igraph_types.h"
#include "igraph_datatype.h"

__BEGIN_DECLS

typedef struct igraph_adjlist_t { 
  igraph_integer_t length;
  igraph_vector_int_t *adjs;
} igraph_adjlist_t;

int igraph_adjlist_init(const igraph_t *graph, igraph_adjlist_t *al, 
			  igraph_neimode_t mode);
int igraph_adjlist_init_empty(igraph_adjlist_t *al, igraph_integer_t no_of_nodes);
igraph_integer_t igraph_adjlist_size(const igraph_adjlist_t *al); 
int igraph_adjlist_init_complementer(const igraph_t *graph,
				     igraph_adjlist_t *al, 
				     igraph_neimode_t mode,
				     igraph_bool_t loops);
void igraph_adjlist_destroy(igraph_adjlist_t *al);
void igraph_adjlist_clear(igraph_adjlist_t *al);
void igraph_adjlist_sort(igraph_adjlist_t *al);
int igraph_adjlist_simplify(igraph_adjlist_t *al);
int igraph_adjlist_remove_duplicate(const igraph_t *graph, 
				    igraph_adjlist_t *al);
int igraph_adjlist_print(const igraph_adjlist_t *al);
int igraph_adjlist_fprint(const igraph_adjlist_t *al, FILE *outfile);
/* igraph_vector_int_t *igraph_adjlist_get(const igraph_adjlist_t *al,  */
/* 			       igraph_integer_t no); */
/**
 * \define igraph_adjlist_get
 * Query a vector in an adjlist
 * 
 * Returns a pointer to an <type>igraph_vector_int_t</type> object from an
 * adjacency list. The vector can be modified as desired. 
 * \param al The adjacency list object.
 * \param no The vertex of which the vertex of adjacent vertices are
 *   returned.
 * \return Pointer to the <type>igraph_vector_int_t</type> object.
 * 
 * Time complexity: O(1).
 */
#define igraph_adjlist_get(al,no) (&(al)->adjs[(long int)(no)])

int igraph_adjlist(igraph_t *graph, const igraph_adjlist_t *adjlist,
		   igraph_neimode_t mode, igraph_bool_t duplicate);

typedef struct igraph_inclist_t {
  igraph_integer_t length;
  igraph_vector_t *incs;
} igraph_inclist_t;

int igraph_inclist_init(const igraph_t *graph, 
			    igraph_inclist_t *il, 
			    igraph_neimode_t mode);
int igraph_inclist_init_empty(igraph_inclist_t *il, igraph_integer_t n);
void igraph_inclist_destroy(igraph_inclist_t *il);
void igraph_inclist_clear(igraph_inclist_t *il);
int igraph_inclist_remove_duplicate(const igraph_t *graph,
					igraph_inclist_t *il);
int igraph_inclist_print(const igraph_inclist_t *il);
int igraph_inclist_fprint(const igraph_inclist_t *il, FILE *outfile);

/**
 * \define igraph_inclist_get
 * Query a vector in an incidence list
 *
 * Returns a pointer to an <type>igraph_vector_t</type> object from an
 * incidence list containing edge ids. The vector can be modified,
 * resized, etc. as desired. 
 * \param graph il The incidence list.
 * \param no The vertex for which the incident edges are returned.
 * \return Pointer to an <type>igraph_vector_t</type> object.
 * 
 * Time complexity: O(1).
 */
#define igraph_inclist_get(il,no) (&(il)->incs[(long int)(no)])

typedef struct igraph_lazy_adjlist_t {
  const igraph_t *graph;
  igraph_integer_t length;
  igraph_vector_t **adjs;
  igraph_neimode_t mode;
  igraph_lazy_adlist_simplify_t simplify;
} igraph_lazy_adjlist_t;

int igraph_lazy_adjlist_init(const igraph_t *graph,
			       igraph_lazy_adjlist_t *al,
			       igraph_neimode_t mode,
			       igraph_lazy_adlist_simplify_t simplify);
void igraph_lazy_adjlist_destroy(igraph_lazy_adjlist_t *al);
void igraph_lazy_adjlist_clear(igraph_lazy_adjlist_t *al);
/* igraph_vector_t *igraph_lazy_adjlist_get(igraph_lazy_adjlist_t *al, */
/* 					   igraph_integer_t no); */
/**
 * \define igraph_lazy_adjlist_get
 * Query neighbor vertices
 * 
 * If the function is called for the first time for a vertex then the
 * result is stored in the adjacency list and no further query
 * operations are needed when the neighbors of the same vertex are
 * queried again.
 * \param al The lazy adjacency list.
 * \param no The vertex id to query.
 * \return Pointer to a vector. It is allowed to modify it and
 *   modification does not affect the original graph.
 * 
 * Time complexity: O(d), the number of neighbor vertices for the
 * first time, O(1) for subsequent calls.
 */
#define igraph_lazy_adjlist_get(al,no) \
  ((al)->adjs[(long int)(no)] != 0 ? ((al)->adjs[(long int)(no)]) : \
   (igraph_lazy_adjlist_get_real(al, no)))
igraph_vector_t *igraph_lazy_adjlist_get_real(igraph_lazy_adjlist_t *al,
						igraph_integer_t no);

typedef struct igraph_lazy_inclist_t {
  const igraph_t *graph;
  igraph_integer_t length;
  igraph_vector_t **incs;
  igraph_neimode_t mode;
} igraph_lazy_inclist_t;

int igraph_lazy_inclist_init(const igraph_t *graph,
				   igraph_lazy_inclist_t *il,
				   igraph_neimode_t mode);
void igraph_lazy_inclist_destroy(igraph_lazy_inclist_t *il);
void igraph_lazy_inclist_clear(igraph_lazy_inclist_t *il);

/**
 * \define igraph_lazy_inclist_get
 * Query incident edges
 * 
 * If the function is called for the first time for a vertex, then the
 * result is stored in the incidence list and no further query
 * operations are needed when the incident edges of the same vertex are
 * queried again.
 * \param al The lazy incidence list object.
 * \param no The vertex id to query.
 * \return Pointer to a vector. It is allowed to modify it and
 *   modification does not affect the original graph.
 * 
 * Time complexity: O(d), the number of incident edges for the first
 * time, O(1) for subsequent calls with the same \p no argument.
 */
#define igraph_lazy_inclist_get(al,no) \
  ((al)->incs[(long int)(no)] != 0 ? ((al)->incs[(long int)(no)]) : \
   (igraph_lazy_inclist_get_real(al, no)))
igraph_vector_t *igraph_lazy_inclist_get_real(igraph_lazy_inclist_t *al,
						    igraph_integer_t no);

/************************************************************************* 
 * DEPRECATED TYPES AND FUNCTIONS
 */

typedef igraph_inclist_t igraph_adjedgelist_t;

int igraph_adjedgelist_init(const igraph_t *graph, 
			    igraph_inclist_t *il, 
			    igraph_neimode_t mode);
void igraph_adjedgelist_destroy(igraph_inclist_t *il);
int igraph_adjedgelist_remove_duplicate(const igraph_t *graph,
					igraph_inclist_t *il);
int igraph_adjedgelist_print(const igraph_inclist_t *il, FILE *outfile);

/**
 * \define igraph_adjedgelist_get
 * Query a vector in an incidence list
 *
 * This macro was superseded by \ref igraph_inclist_get() in igraph 0.6.
 * Please use \ref igraph_inclist_get() instead of this macro.
 *
 * </para><para>
 * Deprecated in version 0.6.
 */
#define igraph_adjedgelist_get(ael,no) (&(ael)->incs[(long int)(no)])

typedef igraph_lazy_inclist_t igraph_lazy_adjedgelist_t;

int igraph_lazy_adjedgelist_init(const igraph_t *graph,
				   igraph_lazy_inclist_t *il,
				   igraph_neimode_t mode);
void igraph_lazy_adjedgelist_destroy(igraph_lazy_inclist_t *il);

/**
 * \define igraph_lazy_adjedgelist_get
 * Query a vector in a lazy incidence list
 *
 * This macro was superseded by \ref igraph_lazy_inclist_get() in igraph 0.6.
 * Please use \ref igraph_lazy_inclist_get() instead of this macro.
 *
 * </para><para>
 * Deprecated in version 0.6.
 */
#define igraph_lazy_adjedgelist_get(al,no) \
  ((al)->incs[(long int)(no)] != 0 ? ((al)->incs[(long int)(no)]) : \
   (igraph_lazy_adjedgelist_get_real(al, no)))
igraph_vector_t *igraph_lazy_adjedgelist_get_real(igraph_lazy_inclist_t *al,
						    igraph_integer_t no);
__END_DECLS

#endif