This file is indexed.

/usr/lib/grass74/include/grass/dgl/graph.h is in grass-dev 7.4.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
/*
 * Copyright (C) 2002 Roberto Micarelli
 *
 * 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
 */

/*
 * best view tabstop=4
 */

#ifndef _DGL_dglGraph_s_H_
#define _DGL_dglGraph_s_H_

#ifdef DGL_STATS
#include <time.h>
#endif

#include "heap.h"
#include "tree.h"

/*
 * Graph State bitmask - returned by dglGet_State() function
 */
#define DGL_GS_FLAT			0x1	/* otherwise is TREE */

/*
 * Graph Family
 */
#define DGL_GF_COMPLETE		0x1
#define DGL_GF_BIPARTITE	0x2
#define DGL_GF_REGULAR		0x4
#define DGL_GF_BOUQUET		0x8
#define DGL_GF_DIPOLE		0x10
#define DGL_GF_PATH			0x20
#define DGL_GF_CYCLE		0x40

/*
 * Graph Options
 */
#define DGL_GO_EdgePrioritize_COST	0x10
#define DGL_GO_EdgePrioritize_ATTR	0x20
#define DGL_GO_NodePrioritize_ATTR	0x40


/*
 * Node Status bitmask - returned by dglNodeGet_Status()
 */
#define DGL_NS_HEAD			0x1	/* node exists as at least one edge's head (static) */
#define DGL_NS_TAIL			0x2	/* node exists as at least one edge's tail (static) */
#define DGL_NS_ALONE		0x4	/* node is a component */


/*
 * Edge Status bitmask - returned by dglEdgeGet_Status()
 */
#define DGL_ES_DIRECTED		0x1	/* force edge to be directed */


/*
 * Endianess Values - returned by dglGet_Endianess() function
 */
#define DGL_ENDIAN_BIG		1
#define DGL_ENDIAN_LITTLE	2


/*
 * miscellaneous
 */
/* add-edge/add-node flags */
#define DGL_STRONGCONNECT	0x1
#define DGL_ALONE			0x2
#define DGL_MERGE_EDGE		0x4
/* */



/*
 * Shortest Path clip definitions
 */
typedef struct _dglSPClipInput
{
    dglInt32_t *pnPrevEdge;
    dglInt32_t *pnNodeFrom;
    dglInt32_t *pnEdge;
    dglInt32_t *pnNodeTo;
    dglInt32_t nFromDistance;

} dglSPClipInput_s;

typedef struct _dglSPClipOutput
{
    dglInt32_t nEdgeCost;

} dglSPClipOutput_s;


/*
 * Spanning clip definitions
 */
typedef struct _dglSpanClipInput
{
    dglInt32_t *pnNodeFrom;
    dglInt32_t *pnEdge;
    dglInt32_t *pnNodeTo;

} dglSpanClipInput_s;

typedef struct _dglSpanClipOutput
{
    dglInt32_t *pnReserved;

} dglSpanClipOutput_s;


struct dglGraph;

/*
 * Node Prioritizer
 */
typedef struct
{
    void *pvAVL;
} dglNodePrioritizer_s;

/*
 * Edge Prioritizer
 */
typedef struct
{
    int cEdge;
    int iEdge;
    dglTreeEdgePri32_s *pEdgePri32Item;
    void *pvAVL;
} dglEdgePrioritizer_s;


/*
 * The graph context
 */
typedef struct _dglGraph
{
    int iErrno;

    dglByte_t Version;
    dglByte_t Endian;
    dglInt32_t NodeAttrSize;
    dglInt32_t EdgeAttrSize;
    dglInt32_t aOpaqueSet[16];

    dglInt32_t cNode;
    dglInt32_t cHead;
    dglInt32_t cTail;
    dglInt32_t cAlone;
    dglInt32_t cEdge;
    dglInt64_t nnCost;

    dglInt32_t Flags;
    dglInt32_t nFamily;
    dglInt32_t nOptions;

    void *pNodeTree;
    void *pEdgeTree;
    dglByte_t *pNodeBuffer;
    dglInt32_t iNodeBuffer;
    dglByte_t *pEdgeBuffer;
    dglInt32_t iEdgeBuffer;


    dglEdgePrioritizer_s edgePrioritizer;
    dglNodePrioritizer_s nodePrioritizer;


    /* so far statistics are only computed by dglAddEdge() */
#ifdef DGL_STATS
    clock_t clkAddEdge;		/* cycles spent during the last addedge execution */
    int cAddEdge;		/* # of calls to dglAddEdge() */
    clock_t clkNodeTree;	/* cycles spent in accessing the node binary tree */
    int cNodeTree;		/* # of probes in the node tree */
#endif
}
dglGraph_s;

/*
 * Shortest Path clip function type
 */
typedef int (*dglSPClip_fn) (dglGraph_s *, dglSPClipInput_s *,
			     dglSPClipOutput_s *, void *);

/*
 * Spanning clip function type
 */
typedef int (*dglSpanClip_fn) (dglGraph_s *, dglGraph_s *,
			       dglSpanClipInput_s *, dglSpanClipOutput_s *,
			       void *);

/*
 * An ARC defined as : from-node, to-node, edge pointer, to-node-distance (from the path starting node)
 */
typedef struct _dglSPArc
{
    dglInt32_t nFrom;
    dglInt32_t nTo;
    dglInt32_t *pnEdge;
    dglInt32_t nDistance;
}
dglSPArc_s;

/*
 * Shortest Path Report
 */
typedef struct _dglSPReport
{
    dglInt32_t nStartNode;
    dglInt32_t nDestinationNode;
    dglInt32_t nDistance;
    dglInt32_t cArc;
    dglSPArc_s *pArc;
}
dglSPReport_s;

/*
 * Shortest Path Cache
 */
typedef struct
{
    dglInt32_t nStartNode;
    dglHeap_s NodeHeap;
    void *pvVisited;
    void *pvPredist;
}
dglSPCache_s;

/*
 * Node Traverser
 */
typedef struct
{
    dglGraph_s *pGraph;
    void *pvAVLT;
    dglInt32_t *pnNode;
} dglNodeTraverser_s;

/*
 * Edgeset Traverser
 */
typedef struct
{
    dglGraph_s *pGraph;
    dglInt32_t *pnEdgeset;
    void *pvCurrentItem;
    int cEdge, iEdge;
} dglEdgesetTraverser_s;

/*
 * Edge Traverser
 */
typedef struct
{
    dglGraph_s *pGraph;
    void *pvAVLT;
    dglInt32_t *pnEdge;
    dglEdgePrioritizer_s *pEdgePrioritizer;
} dglEdgeTraverser_s;


/*
 * Error codes returned by dglError
 */
#define DGL_ERR_BadVersion 				1
#define DGL_ERR_BadNodeType 			2
#define DGL_ERR_MemoryExhausted 		3
#define DGL_ERR_HeapError 				4
#define DGL_ERR_UndefinedMethod 		5
#define DGL_ERR_Write 					6
#define DGL_ERR_Read 					7
#define DGL_ERR_NotSupported 			8
#define DGL_ERR_UnknownByteOrder 		9
#define DGL_ERR_HeadNodeNotFound 		10
#define DGL_ERR_TailNodeNotFound 		11
#define DGL_ERR_BadEdge 				12
#define DGL_ERR_BadOnFlatGraph			13
#define DGL_ERR_BadOnTreeGraph			14
#define DGL_ERR_NodeNotFound 			15
#define DGL_ERR_TreeSearchError 		16
#define DGL_ERR_UnexpectedNullPointer 	17
#define DGL_ERR_VersionNotSupported		18
#define DGL_ERR_EdgeNotFound			19
#define DGL_ERR_NodeAlreadyExist		20
#define DGL_ERR_NodeIsAComponent		21
#define DGL_ERR_EdgeAlreadyExist		22
#define DGL_ERR_BadArgument				23



/*
 * graph context management
 */
int dglInitialize(dglGraph_s * pGraph, dglByte_t Version,
		  dglInt32_t NodeAttrSize, dglInt32_t EdgeAttrSize,
		  dglInt32_t * pOpaqueSet);
int dglRelease(dglGraph_s * pGraph);
int dglUnflatten(dglGraph_s * pGraph);
int dglFlatten(dglGraph_s * pGraph);
void dglResetStats(dglGraph_s * pgraph);

/*
 * node management
 */
dglInt32_t *dglGetNode(dglGraph_s * pGraph, dglInt32_t nNodeId);
int dglAddNode(dglGraph_s * pGraph,
	       dglInt32_t nNodeId, void *pvNodeAttr, dglInt32_t nFlags);
int dglDelNode(dglGraph_s * pGraph, dglInt32_t nNodeId);
dglInt32_t dglNodeGet_Id(dglGraph_s * pGraph, dglInt32_t * pnNode);
dglInt32_t *dglNodeGet_OutEdgeset(dglGraph_s * pGraph, dglInt32_t * pnNode);
dglInt32_t *dglNodeGet_InEdgeset(dglGraph_s * pGraph, dglInt32_t * pnNode);
dglInt32_t dglNodeGet_Status(dglGraph_s * pGraph, dglInt32_t * pnNode);
dglInt32_t *dglNodeGet_Attr(dglGraph_s * pGraph, dglInt32_t * pnNode);
void dglNodeSet_Attr(dglGraph_s * pGraph, dglInt32_t * pnNode,
		     dglInt32_t * pnAttr);
int dglNodeGet_InDegree(dglGraph_s * pGraph, dglInt32_t * pnNode);
int dglNodeGet_OutDegree(dglGraph_s * pGraph, dglInt32_t * pnNode);
int dglNodeGet_Valence(dglGraph_s * pGraph, dglInt32_t * pnNode);

/*
 * edge management
 */
dglInt32_t dglEdgesetGet_EdgeCount(dglGraph_s * pGraph,
				   dglInt32_t * pnOutEdgeset);

dglInt32_t dglEdgeGet_Id(dglGraph_s * pGraph, dglInt32_t * pnEdge);
dglInt32_t dglEdgeGet_Cost(dglGraph_s * pGraph, dglInt32_t * pnEdge);
dglInt32_t *dglEdgeGet_Head(dglGraph_s * pGraph, dglInt32_t * pnEdge);
dglInt32_t *dglEdgeGet_Tail(dglGraph_s * pGraph, dglInt32_t * pnEdge);
dglInt32_t *dglEdgeGet_Attr(dglGraph_s * pGraph, dglInt32_t * pnEdge);
int dglEdgeSet_Attr(dglGraph_s * pGraph, dglInt32_t * pnAttr,
		    dglInt32_t * pnEdge);

dglInt32_t *dglGetEdge(dglGraph_s * pGraph, dglInt32_t nEdgeId);

int dglDelEdge(dglGraph_s * pGraph, dglInt32_t nEdgeId);

int dglAddEdge(dglGraph_s * pGraph,
	       dglInt32_t nHead,
	       dglInt32_t nTail, dglInt32_t nCost, dglInt32_t nEdge);

int dglAddEdgeX(dglGraph_s * pGraph,
		dglInt32_t nHead,
		dglInt32_t nTail,
		dglInt32_t nCost,
		dglInt32_t nEdge,
		void *pvFnodeAttr,
		void *pvTnodeAttr, void *pvEdgeAttr, dglInt32_t nFlags);


/*
 * graph I/O
 */
int dglWrite(dglGraph_s * pGraph, int fd);
int dglRead(dglGraph_s * pGraph, int fd);

typedef struct
{
    dglGraph_s *pG;
    int nState;
    int fSwap;
    int cb;
    int ib;
    unsigned char *pb;
    unsigned char ab[118];	/* 118 = graph header size */
} dglIOContext_s;

int dglIOContextInitialize(dglGraph_s *, dglIOContext_s *);
void dglIOContextRelease(dglIOContext_s *);

/*
 * Chunked Write callback function type
 */
typedef int (*dglWriteChunk_fn) (dglGraph_s *, unsigned char *pbChunk,
				 int cbChunk, void *pvArg);

int dglWriteChunk(dglIOContext_s *, dglWriteChunk_fn, void *pvArg);
int dglReadChunk(dglIOContext_s *, dglByte_t * pbChunk, int cbChunk);



/*
 * Algorithms
 */
int dglShortestPath(dglGraph_s * pGraph,
		    dglSPReport_s ** ppReport,
		    dglInt32_t nStartNode,
		    dglInt32_t nDestinationNode,
		    dglSPClip_fn fnClip,
		    void *pvClipArg, dglSPCache_s * pCache);
int dglShortestPathGraph(dglGraph_s * pGraph,
			 dglGraph_s * pGraphOut,
			 dglInt32_t nStartNode,
			 dglInt32_t nDestinationNode,
			 dglSPClip_fn fnClip,
			 void *pvClipArg, dglSPCache_s * pCache);
int dglShortestDistance(dglGraph_s * pGraph,
			dglInt32_t * pnDistance,
			dglInt32_t nStartNode,
			dglInt32_t nDestinationNode,
			dglSPClip_fn fnClip,
			void *pvClipArg, dglSPCache_s * pCache);
int dglShortestDistanceGraph(dglGraph_s * pGraph,
			     dglGraph_s * pGraphOut,
			     dglInt32_t nStartNode,
			     dglInt32_t nDestinationNode,
			     dglSPClip_fn fnClip,
			     void *pvClipArg, dglSPCache_s * pCache);

int dglInitializeSPCache(dglGraph_s * pgraph, dglSPCache_s * pCache);
void dglReleaseSPCache(dglGraph_s * pgraph, dglSPCache_s * pCache);
void dglFreeSPReport(dglGraph_s * pGraph, dglSPReport_s * pSPReport);

int dglDepthSpanning(dglGraph_s * pgraphInput,
		     dglGraph_s * pgraphOutput,
		     dglInt32_t nVertexNode,
		     dglSpanClip_fn fnClip, void *pvClipArg);

int dglDepthComponents(dglGraph_s * pgraphInput,
		       dglGraph_s * pgraphComponents,
		       int cgraphComponents,
		       dglSpanClip_fn fnClip, void *pvClipArg);

int dglMinimumSpanning(dglGraph_s * pgraphInput,
		       dglGraph_s * pgraphOutput,
		       dglInt32_t nVertexNode,
		       dglSpanClip_fn fnClip, void *pvClipArg);

/*
 * error management
 */
int dglErrno(dglGraph_s * pgraph);
char *dglStrerror(dglGraph_s * pgraph);

/*
 * graph property hiders
 */
int dglGet_Version(dglGraph_s * pGraph);
void dglSet_Version(dglGraph_s * pGraph, int Version);
int dglGet_Endianess(dglGraph_s * pGraph);
int dglGet_NodeAttrSize(dglGraph_s * pGraph);
int dglGet_EdgeAttrSize(dglGraph_s * pGraph);
int dglGet_NodeCount(dglGraph_s * pGraph);
int dglGet_HeadNodeCount(dglGraph_s * pGraph);
int dglGet_TailNodeCount(dglGraph_s * pGraph);
int dglGet_AloneNodeCount(dglGraph_s * pGraph);
int dglGet_EdgeCount(dglGraph_s * pGraph);
int dglGet_State(dglGraph_s * pGraph);
dglInt32_t *dglGet_Opaque(dglGraph_s * pGraph);
void dglSet_Opaque(dglGraph_s * pGraph, dglInt32_t * pOpaque);
int dglGet_NodeSize(dglGraph_s * pGraph);
int dglGet_EdgeSize(dglGraph_s * pGraph);
dglInt64_t dglGet_Cost(dglGraph_s * pGraph);
void dglSet_Cost(dglGraph_s * pGraph, dglInt64_t nnCost);
dglInt32_t dglGet_Family(dglGraph_s * pGraph);
void dglSet_Family(dglGraph_s * pGraph, dglInt32_t nFamily);
dglInt32_t dglGet_Options(dglGraph_s * pGraph);
void dglSet_Options(dglGraph_s * pGraph, dglInt32_t nOptions);
dglEdgePrioritizer_s *dglGet_EdgePrioritizer(dglGraph_s * pGraph);
dglNodePrioritizer_s *dglGet_NodePrioritizer(dglGraph_s * pGraph);


/*
 * node traverser
 */
int dglNode_T_Initialize(dglNodeTraverser_s * pTraverser,
			 dglGraph_s * pGraph);
void dglNode_T_Release(dglNodeTraverser_s * pTraverser);
dglInt32_t *dglNode_T_First(dglNodeTraverser_s * pTraverser);
dglInt32_t *dglNode_T_Last(dglNodeTraverser_s * pTraverser);
dglInt32_t *dglNode_T_Next(dglNodeTraverser_s * pTraverser);
dglInt32_t *dglNode_T_Prev(dglNodeTraverser_s * pTraverser);
dglInt32_t *dglNode_T_Find(dglNodeTraverser_s * pTraverser,
			   dglInt32_t nNodeId);


/*
 * edgeset traverser
 */
int dglEdgeset_T_Initialize(dglEdgesetTraverser_s * pTraverser,
			    dglGraph_s * pGraph, dglInt32_t * pnEdgeset);
void dglEdgeset_T_Release(dglEdgesetTraverser_s * pTraverser);
dglInt32_t *dglEdgeset_T_First(dglEdgesetTraverser_s * pTraverser);
dglInt32_t *dglEdgeset_T_Next(dglEdgesetTraverser_s * pTraverser);


/*
 * edge traverser
 */
int dglEdge_T_Initialize(dglEdgeTraverser_s * pTraverser,
			 dglGraph_s * pGraph,
			 dglEdgePrioritizer_s * pEdgePrioritizer);
void dglEdge_T_Release(dglEdgeTraverser_s * pTraverser);
dglInt32_t *dglEdge_T_First(dglEdgeTraverser_s * pTraverser);
dglInt32_t *dglEdge_T_Next(dglEdgeTraverser_s * pTraverser);

#endif