GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
graph.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2002 Roberto Micarelli
3 * SPDX-FileCopyrightText: GRASS Development Team
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7/*
8 * best view tabstop=4
9 */
10
11#ifndef _DGL_dglGraph_s_H_
12#define _DGL_dglGraph_s_H_
13
14#ifdef DGL_STATS
15#include <time.h>
16#endif
17
18#include "heap.h"
19#include "tree.h"
20
21/*
22 * Graph State bitmask - returned by dglGet_State() function
23 */
24#define DGL_GS_FLAT 0x1 /* otherwise is TREE */
25
26/*
27 * Graph Family
28 */
29#define DGL_GF_COMPLETE 0x1
30#define DGL_GF_BIPARTITE 0x2
31#define DGL_GF_REGULAR 0x4
32#define DGL_GF_BOUQUET 0x8
33#define DGL_GF_DIPOLE 0x10
34#define DGL_GF_PATH 0x20
35#define DGL_GF_CYCLE 0x40
36
37/*
38 * Graph Options
39 */
40#define DGL_GO_EdgePrioritize_COST 0x10
41#define DGL_GO_EdgePrioritize_ATTR 0x20
42#define DGL_GO_NodePrioritize_ATTR 0x40
43
44/*
45 * Node Status bitmask - returned by dglNodeGet_Status()
46 */
47#define DGL_NS_HEAD 0x1 /* node exists as at least one edge's head (static) */
48#define DGL_NS_TAIL 0x2 /* node exists as at least one edge's tail (static) */
49#define DGL_NS_ALONE 0x4 /* node is a component */
50
51/*
52 * Edge Status bitmask - returned by dglEdgeGet_Status()
53 */
54#define DGL_ES_DIRECTED 0x1 /* force edge to be directed */
55
56/*
57 * Endianness Values - returned by dglGet_Endianess() function
58 */
59#define DGL_ENDIAN_BIG 1
60#define DGL_ENDIAN_LITTLE 2
61
62/*
63 * miscellaneous
64 */
65/* add-edge/add-node flags */
66#define DGL_STRONGCONNECT 0x1
67#define DGL_ALONE 0x2
68#define DGL_MERGE_EDGE 0x4
69/* */
70
71/*
72 * Shortest Path clip definitions
73 */
82
87
88/*
89 * Spanning clip definitions
90 */
97
102
103struct dglGraph;
104
105/*
106 * Node Prioritizer
107 */
108typedef struct {
109 void *pvAVL;
111
112/*
113 * Edge Prioritizer
114 */
121
122/*
123 * The graph context
124 */
125typedef struct _dglGraph {
127
133
140
144
151
154
155 /* so far statistics are only computed by dglAddEdge() */
156#ifdef DGL_STATS
157 clock_t clkAddEdge; /* cycles spent during the last addedge execution */
158 int cAddEdge; /* # of calls to dglAddEdge() */
159 clock_t clkNodeTree; /* cycles spent in accessing the node binary tree */
160 int cNodeTree; /* # of probes in the node tree */
161#endif
163
164/*
165 * Shortest Path clip function type
166 */
168 dglSPClipOutput_s *, void *);
169
170/*
171 * Spanning clip function type
172 */
174 dglSpanClipOutput_s *, void *);
175
176/*
177 * An ARC defined as : from-node, to-node, edge pointer, to-node-distance (from
178 * the path starting node)
179 */
186
187/*
188 * Shortest Path Report
189 */
197
198/*
199 * Shortest Path Cache
200 */
207
208/*
209 * Node Traverser
210 */
216
217/*
218 * Edgeset Traverser
219 */
226
227/*
228 * Edge Traverser
229 */
236
237/*
238 * Error codes returned by dglError
239 */
240#define DGL_ERR_BadVersion 1
241#define DGL_ERR_BadNodeType 2
242#define DGL_ERR_MemoryExhausted 3
243#define DGL_ERR_HeapError 4
244#define DGL_ERR_UndefinedMethod 5
245#define DGL_ERR_Write 6
246#define DGL_ERR_Read 7
247#define DGL_ERR_NotSupported 8
248#define DGL_ERR_UnknownByteOrder 9
249#define DGL_ERR_HeadNodeNotFound 10
250#define DGL_ERR_TailNodeNotFound 11
251#define DGL_ERR_BadEdge 12
252#define DGL_ERR_BadOnFlatGraph 13
253#define DGL_ERR_BadOnTreeGraph 14
254#define DGL_ERR_NodeNotFound 15
255#define DGL_ERR_TreeSearchError 16
256#define DGL_ERR_UnexpectedNullPointer 17
257#define DGL_ERR_VersionNotSupported 18
258#define DGL_ERR_EdgeNotFound 19
259#define DGL_ERR_NodeAlreadyExist 20
260#define DGL_ERR_NodeIsAComponent 21
261#define DGL_ERR_EdgeAlreadyExist 22
262#define DGL_ERR_BadArgument 23
263
264/*
265 * graph context management
266 */
267int dglInitialize(dglGraph_s *pGraph, dglByte_t Version,
268 dglInt32_t NodeAttrSize, dglInt32_t EdgeAttrSize,
270int dglRelease(dglGraph_s *pGraph);
271int dglUnflatten(dglGraph_s *pGraph);
272int dglFlatten(dglGraph_s *pGraph);
274
275/*
276 * node management
277 */
287void dglNodeSet_Attr(dglGraph_s *pGraph, dglInt32_t *pnNode,
289int dglNodeGet_InDegree(dglGraph_s *pGraph, dglInt32_t *pnNode);
290int dglNodeGet_OutDegree(dglGraph_s *pGraph, dglInt32_t *pnNode);
291int dglNodeGet_Valence(dglGraph_s *pGraph, dglInt32_t *pnNode);
292
293/*
294 * edge management
295 */
298
305
307
309
312
316
317/*
318 * graph I/O
319 */
320int dglWrite(dglGraph_s *pGraph, int fd);
321int dglRead(dglGraph_s *pGraph, int fd);
322
323typedef struct {
326 int fSwap;
327 int cb;
328 int ib;
329 unsigned char *pb;
330 unsigned char ab[118]; /* 118 = graph header size */
332
335
336/*
337 * Chunked Write callback function type
338 */
339typedef int (*dglWriteChunk_fn)(dglGraph_s *, unsigned char *pbChunk,
340 int cbChunk, void *pvArg);
341
344
345/*
346 * Algorithms
347 */
349 dglInt32_t nStartNode, dglInt32_t nDestinationNode,
352 dglInt32_t nStartNode, dglInt32_t nDestinationNode,
356 dglInt32_t nStartNode, dglInt32_t nDestinationNode,
360 dglInt32_t nStartNode, dglInt32_t nDestinationNode,
363
367
370 void *pvClipArg);
371
374 void *pvClipArg);
375
378 void *pvClipArg);
379
380/*
381 * error management
382 */
385
386/*
387 * graph property hiders
388 */
389int dglGet_Version(dglGraph_s *pGraph);
390void dglSet_Version(dglGraph_s *pGraph, int Version);
391int dglGet_Endianess(dglGraph_s *pGraph);
394int dglGet_NodeCount(dglGraph_s *pGraph);
398int dglGet_EdgeCount(dglGraph_s *pGraph);
399int dglGet_State(dglGraph_s *pGraph);
402int dglGet_NodeSize(dglGraph_s *pGraph);
403int dglGet_EdgeSize(dglGraph_s *pGraph);
405void dglSet_Cost(dglGraph_s *pGraph, dglInt64_t nnCost);
407void dglSet_Family(dglGraph_s *pGraph, dglInt32_t nFamily);
409void dglSet_Options(dglGraph_s *pGraph, dglInt32_t nOptions);
412
413/*
414 * node traverser
415 */
423
424/*
425 * edgeset traverser
426 */
428 dglGraph_s *pGraph, dglInt32_t *pnEdgeset);
432
433/*
434 * edge traverser
435 */
437 dglEdgePrioritizer_s *pEdgePrioritizer);
441
442#endif
dglInt32_t * dglNode_T_Find(dglNodeTraverser_s *pTraverser, dglInt32_t nNodeId)
dglInt32_t * dglGetNode(dglGraph_s *pGraph, dglInt32_t nNodeId)
int(* dglSPClip_fn)(dglGraph_s *, dglSPClipInput_s *, dglSPClipOutput_s *, void *)
Definition graph.h:167
int dglRead(dglGraph_s *pGraph, int fd)
int dglNode_T_Initialize(dglNodeTraverser_s *pTraverser, dglGraph_s *pGraph)
void dglSet_Family(dglGraph_s *pGraph, dglInt32_t nFamily)
int dglGet_TailNodeCount(dglGraph_s *pGraph)
dglInt32_t * dglNodeGet_OutEdgeset(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglInt32_t * dglEdge_T_Next(dglEdgeTraverser_s *pTraverser)
dglInt32_t dglNodeGet_Status(dglGraph_s *pGraph, dglInt32_t *pnNode)
int dglReadChunk(dglIOContext_s *, dglByte_t *pbChunk, int cbChunk)
int dglGet_HeadNodeCount(dglGraph_s *pGraph)
int dglErrno(dglGraph_s *pgraph)
int dglGet_Endianess(dglGraph_s *pGraph)
int dglAddEdge(dglGraph_s *pGraph, dglInt32_t nHead, dglInt32_t nTail, dglInt32_t nCost, dglInt32_t nEdge)
dglInt32_t * dglEdgeset_T_Next(dglEdgesetTraverser_s *pTraverser)
int dglShortestDistanceGraph(dglGraph_s *pGraph, dglGraph_s *pGraphOut, dglInt32_t nStartNode, dglInt32_t nDestinationNode, dglSPClip_fn fnClip, void *pvClipArg, dglSPCache_s *pCache)
dglInt32_t * dglNodeGet_InEdgeset(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglInt64_t dglGet_Cost(dglGraph_s *pGraph)
dglInt32_t dglEdgeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnEdge)
int dglGet_Version(dglGraph_s *pGraph)
struct _dglGraph dglGraph_s
struct _dglSPClipInput dglSPClipInput_s
int(* dglWriteChunk_fn)(dglGraph_s *, unsigned char *pbChunk, int cbChunk, void *pvArg)
Definition graph.h:339
dglInt32_t * dglNode_T_First(dglNodeTraverser_s *pTraverser)
void dglSet_Options(dglGraph_s *pGraph, dglInt32_t nOptions)
int dglShortestPathGraph(dglGraph_s *pGraph, dglGraph_s *pGraphOut, dglInt32_t nStartNode, dglInt32_t nDestinationNode, dglSPClip_fn fnClip, void *pvClipArg, dglSPCache_s *pCache)
int dglDepthSpanning(dglGraph_s *pgraphInput, dglGraph_s *pgraphOutput, dglInt32_t nVertexNode, dglSpanClip_fn fnClip, void *pvClipArg)
int dglGet_EdgeSize(dglGraph_s *pGraph)
dglInt32_t * dglEdge_T_First(dglEdgeTraverser_s *pTraverser)
int dglInitializeSPCache(dglGraph_s *pgraph, dglSPCache_s *pCache)
void dglNodeSet_Attr(dglGraph_s *pGraph, dglInt32_t *pnNode, dglInt32_t *pnAttr)
int dglRelease(dglGraph_s *pGraph)
void dglSet_Version(dglGraph_s *pGraph, int Version)
int dglGet_AloneNodeCount(dglGraph_s *pGraph)
void dglSet_Cost(dglGraph_s *pGraph, dglInt64_t nnCost)
dglInt32_t * dglNode_T_Prev(dglNodeTraverser_s *pTraverser)
int dglGet_NodeCount(dglGraph_s *pGraph)
dglNodePrioritizer_s * dglGet_NodePrioritizer(dglGraph_s *pGraph)
struct _dglSPArc dglSPArc_s
int dglEdgeSet_Attr(dglGraph_s *pGraph, dglInt32_t *pnAttr, dglInt32_t *pnEdge)
struct _dglSpanClipInput dglSpanClipInput_s
dglEdgePrioritizer_s * dglGet_EdgePrioritizer(dglGraph_s *pGraph)
void dglReleaseSPCache(dglGraph_s *pgraph, dglSPCache_s *pCache)
int dglInitialize(dglGraph_s *pGraph, dglByte_t Version, dglInt32_t NodeAttrSize, dglInt32_t EdgeAttrSize, dglInt32_t *pOpaqueSet)
dglInt32_t * dglNode_T_Next(dglNodeTraverser_s *pTraverser)
dglInt32_t dglEdgesetGet_EdgeCount(dglGraph_s *pGraph, dglInt32_t *pnOutEdgeset)
void dglFreeSPReport(dglGraph_s *pGraph, dglSPReport_s *pSPReport)
int dglShortestPath(dglGraph_s *pGraph, dglSPReport_s **ppReport, dglInt32_t nStartNode, dglInt32_t nDestinationNode, dglSPClip_fn fnClip, void *pvClipArg, dglSPCache_s *pCache)
int dglGet_NodeSize(dglGraph_s *pGraph)
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)
struct _dglSPReport dglSPReport_s
dglInt32_t * dglNode_T_Last(dglNodeTraverser_s *pTraverser)
void dglIOContextRelease(dglIOContext_s *)
int dglMinimumSpanning(dglGraph_s *pgraphInput, dglGraph_s *pgraphOutput, dglInt32_t nVertexNode, dglSpanClip_fn fnClip, void *pvClipArg)
void dglNode_T_Release(dglNodeTraverser_s *pTraverser)
char * dglStrerror(dglGraph_s *pgraph)
dglInt32_t * dglEdgeset_T_First(dglEdgesetTraverser_s *pTraverser)
dglInt32_t * dglGet_Opaque(dglGraph_s *pGraph)
int dglNodeGet_OutDegree(dglGraph_s *pGraph, dglInt32_t *pnNode)
struct _dglSPClipOutput dglSPClipOutput_s
int dglDelEdge(dglGraph_s *pGraph, dglInt32_t nEdgeId)
struct _dglSpanClipOutput dglSpanClipOutput_s
void dglEdge_T_Release(dglEdgeTraverser_s *pTraverser)
int dglNodeGet_Valence(dglGraph_s *pGraph, dglInt32_t *pnNode)
int dglGet_State(dglGraph_s *pGraph)
int dglNodeGet_InDegree(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglInt32_t * dglNodeGet_Attr(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglInt32_t * dglGetEdge(dglGraph_s *pGraph, dglInt32_t nEdgeId)
int dglIOContextInitialize(dglGraph_s *, dglIOContext_s *)
int dglWriteChunk(dglIOContext_s *, dglWriteChunk_fn, void *pvArg)
int dglShortestDistance(dglGraph_s *pGraph, dglInt32_t *pnDistance, dglInt32_t nStartNode, dglInt32_t nDestinationNode, dglSPClip_fn fnClip, void *pvClipArg, dglSPCache_s *pCache)
int dglWrite(dglGraph_s *pGraph, int fd)
dglInt32_t * dglEdgeGet_Attr(dglGraph_s *pGraph, dglInt32_t *pnEdge)
int dglEdge_T_Initialize(dglEdgeTraverser_s *pTraverser, dglGraph_s *pGraph, dglEdgePrioritizer_s *pEdgePrioritizer)
void dglEdgeset_T_Release(dglEdgesetTraverser_s *pTraverser)
int dglFlatten(dglGraph_s *pGraph)
dglInt32_t dglGet_Options(dglGraph_s *pGraph)
dglInt32_t dglEdgeGet_Cost(dglGraph_s *pGraph, dglInt32_t *pnEdge)
int dglDepthComponents(dglGraph_s *pgraphInput, dglGraph_s *pgraphComponents, int cgraphComponents, dglSpanClip_fn fnClip, void *pvClipArg)
int(* dglSpanClip_fn)(dglGraph_s *, dglGraph_s *, dglSpanClipInput_s *, dglSpanClipOutput_s *, void *)
Definition graph.h:173
void dglSet_Opaque(dglGraph_s *pGraph, dglInt32_t *pOpaque)
int dglUnflatten(dglGraph_s *pGraph)
int dglGet_NodeAttrSize(dglGraph_s *pGraph)
int dglGet_EdgeAttrSize(dglGraph_s *pGraph)
int dglGet_EdgeCount(dglGraph_s *pGraph)
int dglEdgeset_T_Initialize(dglEdgesetTraverser_s *pTraverser, dglGraph_s *pGraph, dglInt32_t *pnEdgeset)
void dglResetStats(dglGraph_s *pgraph)
dglInt32_t dglGet_Family(dglGraph_s *pGraph)
dglInt32_t * dglEdgeGet_Head(dglGraph_s *pGraph, dglInt32_t *pnEdge)
dglInt32_t * dglEdgeGet_Tail(dglGraph_s *pGraph, dglInt32_t *pnEdge)
int dglDelNode(dglGraph_s *pGraph, dglInt32_t nNodeId)
dglInt32_t dglNodeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnNode)
int dglAddNode(dglGraph_s *pGraph, dglInt32_t nNodeId, void *pvNodeAttr, dglInt32_t nFlags)
dglByte_t * pEdgeBuffer
Definition graph.h:149
dglInt32_t NodeAttrSize
Definition graph.h:130
dglInt32_t cTail
Definition graph.h:136
dglInt32_t cEdge
Definition graph.h:138
dglByte_t Endian
Definition graph.h:129
dglInt32_t nOptions
Definition graph.h:143
dglInt32_t EdgeAttrSize
Definition graph.h:131
dglEdgePrioritizer_s edgePrioritizer
Definition graph.h:152
dglInt32_t cAlone
Definition graph.h:137
dglByte_t * pNodeBuffer
Definition graph.h:147
dglInt32_t iEdgeBuffer
Definition graph.h:150
dglInt32_t iNodeBuffer
Definition graph.h:148
dglInt32_t cHead
Definition graph.h:135
dglInt32_t nFamily
Definition graph.h:142
int iErrno
Definition graph.h:126
dglInt32_t cNode
Definition graph.h:134
dglInt32_t aOpaqueSet[16]
Definition graph.h:132
dglByte_t Version
Definition graph.h:128
void * pNodeTree
Definition graph.h:145
dglNodePrioritizer_s nodePrioritizer
Definition graph.h:153
void * pEdgeTree
Definition graph.h:146
dglInt32_t Flags
Definition graph.h:141
dglInt64_t nnCost
Definition graph.h:139
dglInt32_t nDistance
Definition graph.h:184
dglInt32_t nTo
Definition graph.h:182
dglInt32_t * pnEdge
Definition graph.h:183
dglInt32_t nFrom
Definition graph.h:181
dglInt32_t nFromDistance
Definition graph.h:79
dglInt32_t * pnNodeTo
Definition graph.h:78
dglInt32_t * pnNodeFrom
Definition graph.h:76
dglInt32_t * pnPrevEdge
Definition graph.h:75
dglInt32_t * pnEdge
Definition graph.h:77
dglInt32_t nEdgeCost
Definition graph.h:84
dglInt32_t nDistance
Definition graph.h:193
dglInt32_t cArc
Definition graph.h:194
dglSPArc_s * pArc
Definition graph.h:195
dglInt32_t nStartNode
Definition graph.h:191
dglInt32_t nDestinationNode
Definition graph.h:192
dglInt32_t * pnNodeTo
Definition graph.h:94
dglInt32_t * pnNodeFrom
Definition graph.h:92
dglInt32_t * pnEdge
Definition graph.h:93
dglInt32_t * pnReserved
Definition graph.h:99
dglTreeEdgePri32_s * pEdgePri32Item
Definition graph.h:118
dglInt32_t * pnEdge
Definition graph.h:233
dglGraph_s * pGraph
Definition graph.h:231
dglEdgePrioritizer_s * pEdgePrioritizer
Definition graph.h:234
dglInt32_t * pnEdgeset
Definition graph.h:222
dglGraph_s * pGraph
Definition graph.h:221
dglGraph_s * pG
Definition graph.h:324
unsigned char * pb
Definition graph.h:329
dglInt32_t * pnNode
Definition graph.h:214
dglGraph_s * pGraph
Definition graph.h:212
void * pvPredist
Definition graph.h:205
void * pvVisited
Definition graph.h:204
dglHeap_s NodeHeap
Definition graph.h:203
dglInt32_t nStartNode
Definition graph.h:202
long long dglInt64_t
Definition type.h:25
unsigned char dglByte_t
Definition type.h:23
long dglInt32_t
Definition type.h:24