GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
vector/dglib/graph.c
Go to the documentation of this file.
1 /* LIBDGL -- a Directed Graph Library implementation
2  * Copyright (C) 2002 Roberto Micarelli
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /*
20  * best view with tabstop=4
21  */
22 
23 #include <stdio.h>
24 #include <string.h>
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <unistd.h>
28 #include <stdlib.h>
29 #include <errno.h>
30 
31 #define DGL_V2 1
32 
33 #include <grass/gis.h>
34 #include "type.h"
35 #include "tree.h"
36 #include "graph.h"
37 #include "graph_v1.h"
38 #if defined(DGL_V2)
39 #include "graph_v2.h"
40 #endif
41 #include "helpers.h"
42 
43 
44 void dglResetStats(dglGraph_s * pgraph)
45 {
46 #ifdef DGL_STATS
47  pgraph->clkAddEdge = 0;
48  pgraph->cAddEdge = 0;
49  pgraph->clkNodeTree = 0;
50  pgraph->cNodeTree = 0;
51 #endif
52 }
53 
54 int dglInitialize(dglGraph_s * pGraph, dglByte_t Version,
55  dglInt32_t NodeAttrSize, dglInt32_t EdgeAttrSize,
56  dglInt32_t * pOpaqueSet)
57 {
58  if (pGraph == NULL) {
59  return -DGL_ERR_BadArgument;
60  }
61  switch (Version) {
62  case 1:
63 #ifdef DGL_V2
64  case 2:
65  case 3:
66 #endif
67  memset(pGraph, 0, sizeof(dglGraph_s));
68  /*
69  * round attr size to the upper multiple of dglInt32_t size
70  */
71  if (NodeAttrSize % sizeof(dglInt32_t))
72  NodeAttrSize +=
73  (sizeof(dglInt32_t) - (NodeAttrSize % sizeof(dglInt32_t)));
74  if (EdgeAttrSize % sizeof(dglInt32_t))
75  EdgeAttrSize +=
76  (sizeof(dglInt32_t) - (EdgeAttrSize % sizeof(dglInt32_t)));
77  pGraph->Version = Version;
78  pGraph->NodeAttrSize = NodeAttrSize;
79  pGraph->EdgeAttrSize = EdgeAttrSize;
80  if (pOpaqueSet)
81  memcpy(&pGraph->aOpaqueSet, pOpaqueSet, sizeof(dglInt32_t) * 16);
82 #ifdef DGL_ENDIAN_BIG
83  pGraph->Endian = DGL_ENDIAN_BIG;
84 #else
85  pGraph->Endian = DGL_ENDIAN_LITTLE;
86 #endif
87  }
88  switch (Version) {
89  case 1:
90  if (dgl_initialize_V1(pGraph) < 0) {
91  return -pGraph->iErrno;
92  }
93  else
94  return 0;
95 #ifdef DGL_V2
96  case 2:
97  case 3:
98  if (dgl_initialize_V2(pGraph) < 0) {
99  return -pGraph->iErrno;
100  }
101  else
102  return 0;
103 #endif
104  }
106  return -pGraph->iErrno;
107 }
108 
109 int dglRelease(dglGraph_s * pGraph)
110 {
111  switch (pGraph->Version) {
112  case 1:
113  return dgl_release_V1(pGraph);
114 #ifdef DGL_V2
115  case 2:
116  case 3:
117  return dgl_release_V2(pGraph);
118 #endif
119  }
120  pGraph->iErrno = DGL_ERR_BadVersion;
121  return -pGraph->iErrno;
122 }
123 
125 {
126  switch (pGraph->Version) {
127  case 1:
128  return dgl_unflatten_V1(pGraph);
129 #ifdef DGL_V2
130  case 2:
131  case 3:
132  return dgl_unflatten_V2(pGraph);
133 #endif
134  }
135  pGraph->iErrno = DGL_ERR_BadVersion;
136  return -pGraph->iErrno;
137 }
138 
139 
140 int dglFlatten(dglGraph_s * pGraph)
141 {
142  switch (pGraph->Version) {
143  case 1:
144  return dgl_flatten_V1(pGraph);
145 #ifdef DGL_V2
146  case 2:
147  case 3:
148  return dgl_flatten_V2(pGraph);
149 #endif
150  }
151  pGraph->iErrno = DGL_ERR_BadVersion;
152  return -pGraph->iErrno;
153 }
154 
155 
157 {
158  switch (pGraph->Version) {
159  case 1:
160  return dgl_get_node_V1(pGraph, nNodeId);
161 #ifdef DGL_V2
162  case 2:
163  case 3:
164  return dgl_get_node_V2(pGraph, nNodeId);
165 #endif
166  }
167  pGraph->iErrno = DGL_ERR_BadVersion;
168  return NULL;
169 }
170 
172 {
173  if (pnNode) {
174  switch (pGraph->Version) {
175  case 1:
176  return dgl_getnode_outedgeset_V1(pGraph, pnNode);
177 #ifdef DGL_V2
178  case 2:
179  case 3:
180  return dgl_getnode_outedgeset_V2(pGraph, pnNode);
181 #endif
182  }
183  pGraph->iErrno = DGL_ERR_BadVersion;
184  return NULL;
185  }
186  return NULL;
187 }
188 
190 {
191  if (pnNode) {
192  switch (pGraph->Version) {
193  case 1:
194  pGraph->iErrno = DGL_ERR_NotSupported;
195  return NULL;
196 #ifdef DGL_V2
197  case 2:
198  case 3:
199  return dgl_getnode_inedgeset_V2(pGraph, pnNode);
200 #endif
201  }
202  pGraph->iErrno = DGL_ERR_BadVersion;
203  return NULL;
204  }
205  return NULL;
206 }
207 
208 
209 
210 /*
211  * Given that node id can be negative, only iErrno can report a error,
212  * thus it is initialized to zero
213  */
215 {
216  pGraph->iErrno = 0;
217  if (pnNode) {
218  switch (pGraph->Version) {
219  case 1:
220  return DGL_NODE_ID_v1(pnNode);
221 #ifdef DGL_V2
222  case 2:
223  case 3:
224  return DGL_NODE_ID_v2(pnNode);
225 #endif
226  }
227  pGraph->iErrno = DGL_ERR_BadVersion;
228  return 0;
229  }
231  return 0;
232 }
233 
234 
236 {
237  pGraph->iErrno = 0;
238  if (pnNode) {
239  switch (pGraph->Version) {
240  case 1:
241  return DGL_NODE_STATUS_v1(pnNode);
242 #ifdef DGL_V2
243  case 2:
244  case 3:
245  return DGL_NODE_STATUS_v2(pnNode);
246 #endif
247  }
248  pGraph->iErrno = DGL_ERR_BadVersion;
249  return 0;
250  }
252  return 0;
253 }
254 
255 
257 {
258  if (pnNode) {
259  switch (pGraph->Version) {
260  case 1:
261  return DGL_NODE_ATTR_PTR_v1(pnNode);
262 #ifdef DGL_V2
263  case 2:
264  case 3:
265  return DGL_NODE_ATTR_PTR_v2(pnNode);
266 #endif
267  }
268  pGraph->iErrno = DGL_ERR_BadVersion;
269  return NULL;
270  }
272  return NULL;
273 }
274 
275 
276 void dglNodeSet_Attr(dglGraph_s * pGraph, dglInt32_t * pnNode,
277  dglInt32_t * pnAttr)
278 {
279  if (pnNode) {
280  switch (pGraph->Version) {
281  case 1:
282  memcpy(DGL_NODE_ATTR_PTR_v1(pnNode), pnAttr,
283  pGraph->NodeAttrSize);
284  return;
285 #ifdef DGL_V2
286  case 2:
287  case 3:
288  memcpy(DGL_NODE_ATTR_PTR_v2(pnNode), pnAttr,
289  pGraph->NodeAttrSize);
290  return;
291 #endif
292  }
293  return;
294  }
295  return;
296 }
297 
299 {
300 #ifdef DGL_V2
301  dglInt32_t *pinedgeset;
302 #endif
303 
304  pGraph->iErrno = 0;
305  if (pnNode) {
306  switch (pGraph->Version) {
307  case 1:
308  pGraph->iErrno = DGL_ERR_NotSupported;
309  return 0;
310 #ifdef DGL_V2
311  case 2:
312  if (DGL_NODE_STATUS_v2(pnNode) & DGL_NS_ALONE)
313  return 0;
314  pinedgeset = dglNodeGet_InEdgeset(pGraph, pnNode);
315  if (pinedgeset)
316  return DGL_EDGESET_EDGECOUNT_v2(pinedgeset);
317  return 0;
318  case 3:
319  return dglNodeGet_Valence(pGraph, pnNode);
320 #endif
321  }
322  pGraph->iErrno = DGL_ERR_BadVersion;
323  return 0;
324  }
326  return 0;
327 }
328 
329 
331 {
332  dglInt32_t *poutedgeset;
333 
334  pGraph->iErrno = 0;
335  if (pnNode) {
336  switch (pGraph->Version) {
337  case 1:
338  if (DGL_NODE_STATUS_v1(pnNode) & DGL_NS_ALONE)
339  return 0;
340  poutedgeset = dglNodeGet_OutEdgeset(pGraph, pnNode);
341  if (poutedgeset)
342  return DGL_EDGESET_EDGECOUNT_v1(poutedgeset);
343  return 0;
344 #ifdef DGL_V2
345  case 2:
346  if (DGL_NODE_STATUS_v2(pnNode) & DGL_NS_ALONE)
347  return 0;
348  poutedgeset = dglNodeGet_OutEdgeset(pGraph, pnNode);
349  if (poutedgeset)
350  return DGL_EDGESET_EDGECOUNT_v2(poutedgeset);
351  return 0;
352  case 3:
353  return dglNodeGet_Valence(pGraph, pnNode);
354 #endif
355  }
356  pGraph->iErrno = DGL_ERR_BadVersion;
357  return 0;
358  }
360  return 0;
361 }
362 
363 
364 int dglNodeGet_Valence(dglGraph_s * pGraph, dglInt32_t * pnNode)
365 {
366 #ifdef DGL_V2
367  dglInt32_t *poutedgeset;
368  dglInt32_t *pinedgeset;
369  int c;
370 #endif
371 
372  pGraph->iErrno = 0;
373  if (pnNode) {
374  switch (pGraph->Version) {
375 #ifdef DGL_V2
376  case 3:
377  if (DGL_NODE_STATUS_v2(pnNode) & DGL_NS_ALONE)
378  return 0;
379  poutedgeset = dglNodeGet_OutEdgeset(pGraph, pnNode);
380  pinedgeset = dglNodeGet_InEdgeset(pGraph, pnNode);
381  c = 0;
382  if (poutedgeset)
383  c += DGL_EDGESET_EDGECOUNT_v2(poutedgeset);
384  if (pinedgeset)
385  c += DGL_EDGESET_EDGECOUNT_v2(pinedgeset);
386  return c;
387 #endif
388  }
389  pGraph->iErrno = DGL_ERR_BadVersion;
390  return 0;
391  }
393  return 0;
394 }
395 
396 
397 
399  dglInt32_t * pnEdgeset)
400 {
401  pGraph->iErrno = 0;
402  if (pnEdgeset) {
403  switch (pGraph->Version) {
404  case 1:
405  return DGL_EDGESET_EDGECOUNT_v1(pnEdgeset);
406 #ifdef DGL_V2
407  case 2:
408  case 3:
409  return DGL_EDGESET_EDGECOUNT_v2(pnEdgeset);
410 #endif
411  }
412  pGraph->iErrno = DGL_ERR_BadVersion;
413  return 0;
414  }
416  return 0;
417 }
418 
420 {
421  pGraph->iErrno = 0;
422  if (pnEdge) {
423  switch (pGraph->Version) {
424  case 1:
425  return DGL_EDGE_COST_v1(pnEdge);
426 #ifdef DGL_V2
427  case 2:
428  case 3:
429  return DGL_EDGE_COST_v2(pnEdge);
430 #endif
431  }
432  pGraph->iErrno = DGL_ERR_BadVersion;
433  return 0;
434  }
436  return 0;
437 }
438 
440 {
441  pGraph->iErrno = 0;
442  if (pnEdge) {
443  switch (pGraph->Version) {
444  case 1:
445  return DGL_EDGE_ID_v1(pnEdge);
446 #ifdef DGL_V2
447  case 2:
448  case 3:
449  return DGL_EDGE_ID_v2(pnEdge);
450 #endif
451  }
452  pGraph->iErrno = DGL_ERR_BadVersion;
453  return 0;
454  }
456  return 0;
457 }
458 
460 {
461  pGraph->iErrno = 0;
462  if (pnEdge) {
463  switch (pGraph->Version) {
464  case 1:
465  if (pGraph->Flags & DGL_GS_FLAT) {
466  return DGL_NODEBUFFER_SHIFT_v1(pGraph,
468  (pnEdge));
469  }
470  else {
471  return dgl_get_node_V1(pGraph,
473  }
474 #ifdef DGL_V2
475  case 2:
476  case 3:
477  if (pGraph->Flags & DGL_GS_FLAT) {
478  return DGL_NODEBUFFER_SHIFT_v2(pGraph,
480  (pnEdge));
481  }
482  else {
483  return dgl_get_node_V2(pGraph,
485  }
486 #endif
487  }
488  pGraph->iErrno = DGL_ERR_BadVersion;
489  return NULL;
490  }
492  return NULL;
493 }
494 
496 {
497  pGraph->iErrno = 0;
498  if (pnEdge) {
499  switch (pGraph->Version) {
500  case 1:
501  if (pGraph->Flags & DGL_GS_FLAT) {
502  return DGL_NODEBUFFER_SHIFT_v1(pGraph,
504  (pnEdge));
505  }
506  else {
507  return dgl_get_node_V1(pGraph,
509  }
510 #ifdef DGL_V2
511  case 2:
512  case 3:
513  if (pGraph->Flags & DGL_GS_FLAT) {
514  return DGL_NODEBUFFER_SHIFT_v2(pGraph,
516  (pnEdge));
517  }
518  else {
519  return dgl_get_node_V2(pGraph,
521  }
522 #endif
523  }
524  pGraph->iErrno = DGL_ERR_BadVersion;
525  return NULL;
526  }
528  return NULL;
529 }
530 
532 {
533  pGraph->iErrno = 0;
534  if (pnEdge) {
535  switch (pGraph->Version) {
536  case 1:
537  return DGL_EDGE_ATTR_PTR_v1(pnEdge);
538 #ifdef DGL_V2
539  case 2:
540  case 3:
541  return DGL_EDGE_ATTR_PTR_v2(pnEdge);
542 #endif
543  }
544  pGraph->iErrno = DGL_ERR_BadVersion;
545  return NULL;
546  }
548  return NULL;
549 }
550 
551 int dglEdgeSet_Attr(dglGraph_s * pGraph, dglInt32_t * pnAttr,
552  dglInt32_t * pnEdge)
553 {
554  if (pnEdge) {
555  switch (pGraph->Version) {
556  case 1:
557  memcpy(DGL_EDGE_ATTR_PTR_v1(pnEdge), pnAttr,
558  pGraph->EdgeAttrSize);
559  return 0;
560 #ifdef DGL_V2
561  case 2:
562  case 3:
563  memcpy(DGL_EDGE_ATTR_PTR_v2(pnEdge), pnAttr,
564  pGraph->EdgeAttrSize);
565  return 0;
566 #endif
567  }
568  pGraph->iErrno = DGL_ERR_BadVersion;
569  return -pGraph->iErrno;
570  }
572  return -pGraph->iErrno;
573 }
574 
575 
576 
578 {
579  switch (pGraph->Version) {
580  case 1:
581  return dgl_get_edge_V1(pGraph, nEdgeId);
582  break;
583 #ifdef DGL_V2
584  case 2:
585  case 3:
586  return dgl_get_edge_V2(pGraph, nEdgeId);
587  break;
588 #endif
589  }
590  pGraph->iErrno = DGL_ERR_BadVersion;
591  return NULL;
592 }
593 
594 int dglDelEdge(dglGraph_s * pGraph, dglInt32_t nEdgeId)
595 {
596  switch (pGraph->Version) {
597  case 1:
598  return dgl_del_edge_V1(pGraph, nEdgeId);
599  break;
600 #ifdef DGL_V2
601  case 2:
602  case 3:
603  return dgl_del_edge_V2(pGraph, nEdgeId);
604  break;
605 #endif
606  }
607  pGraph->iErrno = DGL_ERR_BadVersion;
608  return -pGraph->iErrno;
609 }
610 
611 int dglAddEdge(dglGraph_s * pGraph,
612  dglInt32_t nHead,
613  dglInt32_t nTail, dglInt32_t nCost, dglInt32_t nEdge)
614 {
615  int nRet;
616 
617 #ifdef DGL_STATS
618  clock_t clk;
619 
620  clk = clock();
621  pGraph->cAddEdge++;
622 #endif
623  switch (pGraph->Version) {
624  case 1:
625  nRet =
626  dgl_add_edge_V1(pGraph, nHead, nTail, nCost, nEdge, NULL, NULL,
627  NULL, 0);
628  break;
629 #ifdef DGL_V2
630  case 2:
631  case 3:
632  nRet =
633  dgl_add_edge_V2(pGraph, nHead, nTail, nCost, nEdge, NULL, NULL,
634  NULL, 0);
635  break;
636 #endif
637  default:
638  pGraph->iErrno = DGL_ERR_BadVersion;
639  nRet = -pGraph->iErrno;
640  break;
641  }
642 #ifdef DGL_STATS
643  pGraph->clkAddEdge += clock() - clk;
644 #endif
645  return nRet;
646 }
647 
648 int dglAddEdgeX(dglGraph_s * pGraph,
649  dglInt32_t nHead,
650  dglInt32_t nTail,
651  dglInt32_t nCost,
652  dglInt32_t nEdge,
653  void *pvHeadAttr,
654  void *pvTailAttr, void *pvEdgeAttr, dglInt32_t nFlags)
655 {
656  int nRet;
657 
658 #ifdef DGL_STATS
659  clock_t clk;
660 
661  clk = clock();
662  pGraph->cAddEdge++;
663 #endif
664  switch (pGraph->Version) {
665  case 1:
666  nRet =
667  dgl_add_edge_V1(pGraph, nHead, nTail, nCost, nEdge, pvHeadAttr,
668  pvTailAttr, pvEdgeAttr, nFlags);
669  break;
670 #ifdef DGL_V2
671  case 2:
672  case 3:
673  nRet =
674  dgl_add_edge_V2(pGraph, nHead, nTail, nCost, nEdge, pvHeadAttr,
675  pvTailAttr, pvEdgeAttr, nFlags);
676  break;
677 #endif
678  default:
679  pGraph->iErrno = DGL_ERR_BadVersion;
680  nRet = -pGraph->iErrno;
681  break;
682  }
683 #ifdef DGL_STATS
684  pGraph->clkAddEdge += clock() - clk;
685 #endif
686  return nRet;
687 }
688 
689 int dglAddNode(dglGraph_s * pGraph,
690  dglInt32_t nNodeId, void *pvNodeAttr, dglInt32_t nFlags)
691 {
692  int nRet;
693 
694  switch (pGraph->Version) {
695  case 1:
696  nRet = dgl_add_node_V1(pGraph, nNodeId, pvNodeAttr, nFlags);
697  break;
698 #ifdef DGL_V2
699  case 2:
700  case 3:
701  nRet = dgl_add_node_V2(pGraph, nNodeId, pvNodeAttr, nFlags);
702  break;
703 #endif
704  default:
705  pGraph->iErrno = DGL_ERR_BadVersion;
706  nRet = -pGraph->iErrno;
707  break;
708  }
709  return nRet;
710 }
711 
712 int dglDelNode(dglGraph_s * pGraph, dglInt32_t nNodeId)
713 {
714  int nRet;
715 
716  switch (pGraph->Version) {
717  case 1:
718  nRet = dgl_del_node_V1(pGraph, nNodeId);
719  break;
720 #ifdef DGL_V2
721  case 2:
722  case 3:
723  nRet = dgl_del_node_V2(pGraph, nNodeId);
724  break;
725 #endif
726  default:
727  pGraph->iErrno = DGL_ERR_BadVersion;
728  nRet = -pGraph->iErrno;
729  break;
730  }
731  return nRet;
732 }
733 
734 int dglWrite(dglGraph_s * pGraph, int fd)
735 {
736  int nRet;
737 
738  switch (pGraph->Version) {
739  case 1:
740  nRet = dgl_write_V1(pGraph, fd);
741  break;
742 #ifdef DGL_V2
743  case 2:
744  case 3:
745  nRet = dgl_write_V2(pGraph, fd);
746  break;
747 #endif
748  default:
749  pGraph->iErrno = DGL_ERR_BadVersion;
750  nRet = -pGraph->iErrno;
751  break;
752  }
753  return nRet;
754 }
755 
756 int dglRead(dglGraph_s * pGraph, int fd)
757 {
758  dglByte_t bVersion;
759  int nRet;
760 
761  if (read(fd, &bVersion, 1) != 1) {
762  pGraph->iErrno = DGL_ERR_Read;
763  nRet = -pGraph->iErrno;
764  }
765  else {
766  switch (bVersion) {
767  case 1:
768  nRet = dgl_read_V1(pGraph, fd);
769  break;
770 #ifdef DGL_V2
771  case 2:
772  case 3:
773  nRet = dgl_read_V2(pGraph, fd, bVersion);
774  break;
775 #endif
776  default:
778  nRet = -pGraph->iErrno;
779  break;
780  }
781  }
782  return nRet;
783 }
784 
785 
787  dglSPReport_s ** ppReport,
788  dglInt32_t nStart,
789  dglInt32_t nDestination,
790  dglSPClip_fn fnClip,
791  void *pvClipArg, dglSPCache_s * pCache)
792 {
793  int nRet;
794 
795  switch (pGraph->Version) {
796  case 1:
797  nRet =
798  dgl_dijkstra_V1(pGraph, ppReport, NULL, nStart, nDestination,
799  fnClip, pvClipArg, pCache);
800  break;
801 #ifdef DGL_V2
802  case 2:
803  case 3:
804  nRet =
805  dgl_dijkstra_V2(pGraph, ppReport, NULL, nStart, nDestination,
806  fnClip, pvClipArg, pCache);
807  break;
808 #endif
809  default:
810  pGraph->iErrno = DGL_ERR_BadVersion;
811  nRet = -pGraph->iErrno;
812  break;
813  }
814  return nRet;
815 }
816 
817 
819  dglInt32_t * pnDistance,
820  dglInt32_t nStart,
821  dglInt32_t nDestination,
822  dglSPClip_fn fnClip,
823  void *pvClipArg, dglSPCache_s * pCache)
824 {
825  int nRet;
826 
827  switch (pGraph->Version) {
828  case 1:
829  nRet =
830  dgl_dijkstra_V1(pGraph, NULL, pnDistance, nStart, nDestination,
831  fnClip, pvClipArg, pCache);
832  break;
833 #ifdef DGL_V2
834  case 2:
835  case 3:
836  nRet =
837  dgl_dijkstra_V2(pGraph, NULL, pnDistance, nStart, nDestination,
838  fnClip, pvClipArg, pCache);
839  break;
840 #endif
841  default:
842  pGraph->iErrno = DGL_ERR_BadVersion;
843  nRet = -pGraph->iErrno;
844  break;
845  }
846  return nRet;
847 }
848 
849 
850 int dglDepthSpanning(dglGraph_s * pgraphInput,
851  dglGraph_s * pgraphOutput,
852  dglInt32_t nVertexNode,
853  dglSpanClip_fn fnClip, void *pvClipArg)
854 {
855  int nRet;
856  void *pvVisited;
857 
858  if (dglGet_EdgeCount(pgraphInput) == 0) { /* no span */
859  pgraphInput->iErrno = 0;
860  return 0;
861  }
862 
863 #ifndef DGL_V2
864  if (pgraphInput->Version == 2) {
865  pgraphInput->iErrno = DGL_ERR_BadVersion;
866  return -pgraphInput->iErrno;
867  }
868 #endif
869 
870  nRet = dglInitialize(pgraphOutput,
871  dglGet_Version(pgraphInput),
872  dglGet_NodeAttrSize(pgraphInput),
873  dglGet_EdgeAttrSize(pgraphInput),
874  dglGet_Opaque(pgraphInput));
875 
876  if (nRet < 0)
877  return nRet;
878 
879  if ((pvVisited =
881  dglTreeGetAllocator())) == NULL) {
882  pgraphInput->iErrno = DGL_ERR_MemoryExhausted;
883  return -pgraphInput->iErrno;
884  }
885 
886  switch (pgraphInput->Version) {
887  case 1:
888  nRet =
889  dgl_depthfirst_spanning_V1(pgraphInput, pgraphOutput, nVertexNode,
890  pvVisited, fnClip, pvClipArg);
891  break;
892 #ifdef DGL_V2
893  case 2:
894  case 3:
895  nRet =
896  dgl_depthfirst_spanning_V2(pgraphInput, pgraphOutput, nVertexNode,
897  pvVisited, fnClip, pvClipArg);
898  break;
899 #endif
900  default:
901  pgraphInput->iErrno = DGL_ERR_BadVersion;
902  nRet = -pgraphInput->iErrno;
903  break;
904  }
905 
906  avl_destroy(pvVisited, dglTreeNodeCancel);
907 
908  if (nRet < 0) {
909  dglRelease(pgraphOutput);
910  }
911 
912  return nRet;
913 }
914 
915 int dglDepthComponents(dglGraph_s * pgraphInput,
916  dglGraph_s * pgraphComponents,
917  int cgraphComponents,
918  dglSpanClip_fn fnClip, void *pvClipArg)
919 {
920  int i, nret = 0;
921  dglTreeNode_s findVisited;
922  void *pvVisited;
923  dglInt32_t *pvertex, *pnode;
924 
925  if (dglGet_EdgeCount(pgraphInput) == 0) { /* no span */
926  pgraphInput->iErrno = 0;
927  return 0;
928  }
929 
930 #ifndef DGL_V2
931  if (pgraphInput->Version == 2 || pgraphInput->Version == 3) {
932  pgraphInput->iErrno = DGL_ERR_BadVersion;
933  return -pgraphInput->iErrno;
934  }
935 #endif
936 
937  if ((pvVisited =
939  dglTreeGetAllocator())) == NULL) {
940  pgraphInput->iErrno = DGL_ERR_MemoryExhausted;
941  goto error;
942  }
943 
944  /*
945  * choose a vertex to start from
946  */
947  pvertex = NULL;
948  {
950 
951  dglNode_T_Initialize(&pT, pgraphInput);
952  for (pnode = dglNode_T_First(&pT); pnode; pnode = dglNode_T_Next(&pT)) {
953  switch (pgraphInput->Version) {
954  case 1:
955  if (DGL_NODE_STATUS_v1(pnode) & DGL_NS_HEAD)
956  pvertex = pnode;
957  break;
958 #ifdef DGL_V2
959  case 2:
960  case 3:
961  if (DGL_NODE_STATUS_v2(pnode) & DGL_NS_HEAD)
962  pvertex = pnode;
963  break;
964 #endif
965  }
966  if (pvertex)
967  break;
968  }
969  dglNode_T_Release(&pT);
970  }
971 
972  if (pvertex == NULL) {
973  pgraphInput->iErrno = DGL_ERR_UnexpectedNullPointer;
974  goto error;
975  }
976 
977  for (i = 0; i < cgraphComponents && pvertex; i++) {
978  nret = dglInitialize(&pgraphComponents[i],
979  dglGet_Version(pgraphInput),
980  dglGet_NodeAttrSize(pgraphInput),
981  dglGet_EdgeAttrSize(pgraphInput),
982  dglGet_Opaque(pgraphInput));
983 
984  if (nret < 0)
985  goto error;
986 
987  switch (pgraphInput->Version) {
988  case 1:
989  nret =
990  dgl_depthfirst_spanning_V1(pgraphInput, &pgraphComponents[i],
991  DGL_NODE_ID_v1(pvertex), pvVisited,
992  fnClip, pvClipArg);
993  if (nret < 0)
994  goto error;
995  break;
996 #ifdef DGL_V2
997  case 2:
998  case 3:
999  nret =
1000  dgl_depthfirst_spanning_V2(pgraphInput, &pgraphComponents[i],
1001  DGL_NODE_ID_v1(pvertex), pvVisited,
1002  fnClip, pvClipArg);
1003  if (nret < 0)
1004  goto error;
1005  break;
1006 #endif
1007  default:
1008  pgraphInput->iErrno = DGL_ERR_BadVersion;
1009  nret = -pgraphInput->iErrno;
1010  goto error;
1011  }
1012 
1013  /*
1014  * select next unvisited vertex
1015  */
1016  pvertex = NULL;
1017  {
1018  dglNodeTraverser_s pT;
1019 
1020  dglNode_T_Initialize(&pT, pgraphInput);
1021  for (pnode = dglNode_T_First(&pT); pnode;
1022  pnode = dglNode_T_Next(&pT)) {
1023  switch (pgraphInput->Version) {
1024  case 1:
1025  if (DGL_NODE_STATUS_v1(pnode) & DGL_NS_HEAD) {
1026  findVisited.nKey = DGL_NODE_ID_v1(pnode);
1027  if (avl_find(pvVisited, &findVisited) == NULL) {
1028  pvertex = pnode;
1029  break;
1030  }
1031  }
1032  break;
1033 #ifdef DGL_V2
1034  case 2:
1035  case 3:
1036  if (DGL_NODE_STATUS_v2(pnode) & DGL_NS_HEAD) {
1037  findVisited.nKey = DGL_NODE_ID_v2(pnode);
1038  if (avl_find(pvVisited, &findVisited) == NULL) {
1039  pvertex = pnode;
1040  break;
1041  }
1042  }
1043  break;
1044 #endif
1045  }
1046  if (pvertex)
1047  break;
1048  }
1049  dglNode_T_Release(&pT);
1050  }
1051  }
1052 
1053  avl_destroy(pvVisited, dglTreeNodeCancel);
1054  return i;
1055 
1056  error:
1057  avl_destroy(pvVisited, dglTreeNodeCancel);
1058  return nret;
1059 }
1060 
1061 int dglMinimumSpanning(dglGraph_s * pgraphInput,
1062  dglGraph_s * pgraphOutput,
1063  dglInt32_t nVertexNode,
1064  dglSpanClip_fn fnClip, void *pvClipArg)
1065 {
1066  int nRet;
1067 
1068  if (dglGet_EdgeCount(pgraphInput) == 0) { /* no span */
1069  pgraphInput->iErrno = 0;
1070  return 0;
1071  }
1072 
1073  nRet = dglInitialize(pgraphOutput,
1074  dglGet_Version(pgraphInput),
1075  dglGet_NodeAttrSize(pgraphInput),
1076  dglGet_EdgeAttrSize(pgraphInput),
1077  dglGet_Opaque(pgraphInput));
1078 
1079  if (nRet < 0)
1080  return nRet;
1081 
1082  switch (pgraphInput->Version) {
1083  case 1:
1084  nRet =
1085  dgl_minimum_spanning_V1(pgraphInput, pgraphOutput, nVertexNode,
1086  fnClip, pvClipArg);
1087  break;
1088 #ifdef DGL_V2
1089  case 2:
1090  case 3:
1091  nRet =
1092  dgl_minimum_spanning_V2(pgraphInput, pgraphOutput, nVertexNode,
1093  fnClip, pvClipArg);
1094  break;
1095 #endif
1096  default:
1097  pgraphInput->iErrno = DGL_ERR_BadVersion;
1098  nRet = -pgraphInput->iErrno;
1099  break;
1100  }
1101  if (nRet < 0) {
1102  dglRelease(pgraphOutput);
1103  }
1104  return nRet;
1105 }
1106 
1107 void dglFreeSPReport(dglGraph_s * pgraph, dglSPReport_s * pSPReport)
1108 {
1109  int iArc;
1110 
1111  if (pSPReport) {
1112  if (pSPReport->pArc) {
1113  for (iArc = 0; iArc < pSPReport->cArc; iArc++) {
1114  if (pSPReport->pArc[iArc].pnEdge)
1115  free(pSPReport->pArc[iArc].pnEdge);
1116  }
1117  free(pSPReport->pArc);
1118  }
1119  free(pSPReport);
1120  }
1121 }
1122 
1124 {
1125  switch (pGraph->Version) {
1126  case 1:
1127  return dgl_sp_cache_initialize_V1(pGraph, pCache, 0);
1128 #ifdef DGL_V2
1129  case 2:
1130  case 3:
1131  return dgl_sp_cache_initialize_V2(pGraph, pCache, 0);
1132 #endif
1133  }
1134  pGraph->iErrno = DGL_ERR_BadVersion;
1135  return -pGraph->iErrno;
1136 }
1137 
1139 {
1140  pGraph->iErrno = 0;
1141  switch (pGraph->Version) {
1142  case 1:
1143  dgl_sp_cache_release_V1(pGraph, pCache);
1144  break;
1145 #ifdef DGL_V2
1146  case 2:
1147  case 3:
1148  dgl_sp_cache_release_V2(pGraph, pCache);
1149  break;
1150 #endif
1151  }
1152  pGraph->iErrno = DGL_ERR_BadVersion;
1153 }
1154 
1155 
1156 int dglErrno(dglGraph_s * pgraph)
1157 {
1158  return pgraph->iErrno;
1159 }
1160 
1161 char *dglStrerror(dglGraph_s * pgraph)
1162 {
1163  switch (pgraph->iErrno) {
1164  case DGL_ERR_BadVersion:
1165  return "Bad Version";
1166  case DGL_ERR_BadNodeType:
1167  return "Bad Node Type";
1169  return "Memory Exhausted";
1170  case DGL_ERR_HeapError:
1171  return "Heap Error";
1173  return "Undefined Method";
1174  case DGL_ERR_Write:
1175  return "Write";
1176  case DGL_ERR_Read:
1177  return "Read";
1178  case DGL_ERR_NotSupported:
1179  return "Not Supported";
1181  return "Unknown Byte Order";
1182  case DGL_ERR_NodeNotFound:
1183  return "Node Not Found";
1185  return "Head Node Not Found";
1187  return "Tail Node Not Found";
1188  case DGL_ERR_BadEdge:
1189  return "Bad Edge";
1191  return "Operation Not Supported On Flat-State Graph";
1193  return "Operation Not Supported On Tree-State Graph";
1195  return "Tree Search Error";
1197  return "Unexpected Null Pointer";
1199  return "Version Not Supported";
1200  case DGL_ERR_EdgeNotFound:
1201  return "Edge Not Found";
1203  return "Node Already Exist";
1205  return "Node Is A Component";
1207  return "Edge Already Exist";
1208  case DGL_ERR_BadArgument:
1209  return "Bad Argument";
1210  }
1211 
1212  return "unknown graph error code";
1213 }
1214 
1215 /*
1216  * dglGraph_s hiders
1217  */
1219 {
1220  return pgraph->Version;
1221 }
1222 void dglSet_Version(dglGraph_s * pgraph, int nVersion)
1223 {
1224  pgraph->Version = nVersion;
1225 }
1226 
1228 {
1229  return pgraph->Endian;
1230 }
1231 
1233 {
1234  return pgraph->NodeAttrSize;
1235 }
1236 
1238 {
1239  return pgraph->EdgeAttrSize;
1240 }
1241 
1243 {
1244  return pgraph->cNode;
1245 }
1246 
1248 {
1249  return pgraph->cHead;
1250 }
1251 
1253 {
1254  return pgraph->cTail;
1255 }
1256 
1258 {
1259  return pgraph->cAlone;
1260 }
1261 
1263 {
1264  return pgraph->cEdge;
1265 }
1266 
1268 {
1269  return pgraph->Flags;
1270 }
1271 
1273 {
1274  return pgraph->aOpaqueSet;
1275 }
1276 
1277 void dglSet_Opaque(dglGraph_s * pgraph, dglInt32_t * pOpaque)
1278 {
1279  memcpy(pgraph->aOpaqueSet, pOpaque, sizeof(dglInt32_t) * 16);
1280 }
1281 
1283 {
1284  switch (pgraph->Version) {
1285  case 1:
1286  return DGL_NODE_SIZEOF_v1(pgraph->NodeAttrSize);
1287 #ifdef DGL_V2
1288  case 2:
1289  case 3:
1290  return DGL_NODE_SIZEOF_v2(pgraph->NodeAttrSize);
1291 #endif
1292  }
1293  pgraph->iErrno = DGL_ERR_BadVersion;
1294  return -pgraph->iErrno;
1295 }
1296 
1298 {
1299  switch (pgraph->Version) {
1300  case 1:
1301  return DGL_EDGE_SIZEOF_v1(pgraph->NodeAttrSize);
1302 #ifdef DGL_V2
1303  case 2:
1304  case 3:
1305  return DGL_EDGE_SIZEOF_v2(pgraph->NodeAttrSize);
1306 #endif
1307  }
1308  pgraph->iErrno = DGL_ERR_BadVersion;
1309  return -pgraph->iErrno;
1310 }
1311 
1313 {
1314  return pgraph->nnCost;
1315 }
1316 
1317 void dglSet_Cost(dglGraph_s * pgraph, dglInt64_t nnCost)
1318 {
1319  pgraph->nnCost = nnCost;
1320 }
1321 
1323 {
1324  return pgraph->nFamily;
1325 }
1326 
1327 void dglSet_Family(dglGraph_s * pgraph, dglInt32_t nFamily)
1328 {
1329  pgraph->nFamily = nFamily;
1330 }
1331 
1333 {
1334  return pgraph->nOptions;
1335 }
1336 
1337 void dglSet_Options(dglGraph_s * pgraph, dglInt32_t nOptions)
1338 {
1339  pgraph->nOptions = nOptions;
1340 }
1341 
1343 {
1344  return &pGraph->edgePrioritizer;
1345 }
1346 
1348 {
1349  return &pGraph->nodePrioritizer;
1350 }
1351 
1352 
1353 
1354 /*
1355  * Node Traverse
1356  */
1358 {
1359  switch (pGraph->Version) {
1360  case 1:
1361  return dgl_node_t_initialize_V1(pGraph, pT);
1362 #ifdef DGL_V2
1363  case 2:
1364  case 3:
1365  return dgl_node_t_initialize_V2(pGraph, pT);
1366 #endif
1367  }
1368  pGraph->iErrno = DGL_ERR_BadVersion;
1369  return -pGraph->iErrno;
1370 }
1371 
1373 {
1374  switch (pT->pGraph->Version) {
1375  case 1:
1377  return;
1378 #ifdef DGL_V2
1379  case 2:
1380  case 3:
1382  return;
1383 #endif
1384  }
1386 }
1387 
1389 {
1390  switch (pT->pGraph->Version) {
1391  case 1:
1392  return dgl_node_t_first_V1(pT);
1393 #ifdef DGL_V2
1394  case 2:
1395  case 3:
1396  return dgl_node_t_first_V2(pT);
1397 #endif
1398  }
1400  return NULL;
1401 }
1402 
1404 {
1405  switch (pT->pGraph->Version) {
1406  case 1:
1407  return dgl_node_t_next_V1(pT);
1408 #ifdef DGL_V2
1409  case 2:
1410  case 3:
1411  return dgl_node_t_next_V2(pT);
1412 #endif
1413  }
1415  return NULL;
1416 }
1417 
1419 {
1420  switch (pT->pGraph->Version) {
1421  case 1:
1422  return dgl_node_t_find_V1(pT, nNodeId);
1423 #ifdef DGL_V2
1424  case 2:
1425  case 3:
1426  return dgl_node_t_find_V2(pT, nNodeId);
1427 #endif
1428  }
1430  return NULL;
1431 }
1432 
1433 /*
1434  * Edge Traverser
1435  */
1437  dglGraph_s * pGraph,
1438  dglEdgePrioritizer_s * pEdgePrioritizer)
1439 {
1440  switch (pGraph->Version) {
1441  case 1:
1442  return dgl_edge_t_initialize_V1(pGraph, pT, pEdgePrioritizer);
1443 #ifdef DGL_V2
1444  case 2:
1445  case 3:
1446  return dgl_edge_t_initialize_V2(pGraph, pT, pEdgePrioritizer);
1447 #endif
1448  }
1449  pGraph->iErrno = DGL_ERR_BadVersion;
1450  return -pGraph->iErrno;
1451 }
1452 
1454 {
1455  switch (pT->pGraph->Version) {
1456  case 1:
1458  return;
1459 #ifdef DGL_V2
1460  case 2:
1461  case 3:
1463  return;
1464 #endif
1465  }
1467 }
1468 
1470 {
1471  switch (pT->pGraph->Version) {
1472  case 1:
1473  return dgl_edge_t_first_V1(pT);
1474 #ifdef DGL_V2
1475  case 2:
1476  case 3:
1477  return dgl_edge_t_first_V2(pT);
1478 #endif
1479  }
1481  return NULL;
1482 }
1483 
1485 {
1486  switch (pT->pGraph->Version) {
1487  case 1:
1488  return dgl_edge_t_next_V1(pT);
1489 #ifdef DGL_V2
1490  case 2:
1491  case 3:
1492  return dgl_edge_t_next_V2(pT);
1493 #endif
1494  }
1496  return NULL;
1497 }
1498 
1499 
1501  dglGraph_s * pGraph, dglInt32_t * pnEdgeset)
1502 {
1503  switch (pGraph->Version) {
1504  case 1:
1505  return dgl_edgeset_t_initialize_V1(pGraph, pT, pnEdgeset);
1506 #ifdef DGL_V2
1507  case 2:
1508  case 3:
1509  return dgl_edgeset_t_initialize_V2(pGraph, pT, pnEdgeset);
1510 #endif
1511  }
1512  pGraph->iErrno = DGL_ERR_BadVersion;
1513  return -pGraph->iErrno;
1514 }
1515 
1517 {
1518 }
1519 
1521 {
1522  switch (pT->pGraph->Version) {
1523  case 1:
1524  return dgl_edgeset_t_first_V1(pT);
1525 #ifdef DGL_V2
1526  case 2:
1527  case 3:
1528  return dgl_edgeset_t_first_V2(pT);
1529 #endif
1530  }
1532  return NULL;
1533 }
1534 
1536 {
1537  switch (pT->pGraph->Version) {
1538  case 1:
1539  return dgl_edgeset_t_next_V1(pT);
1540 #ifdef DGL_V2
1541  case 2:
1542  case 3:
1543  return dgl_edgeset_t_next_V2(pT);
1544 #endif
1545  }
1547  return NULL;
1548 }
1549 
1550 
1551 /*
1552  * chunked I/O
1553  */
1554 
1555 #define __CIO_BEGIN 0
1556 #define __CIO_W_HEADER 1
1557 #define __CIO_W_NODEBUFFER 2
1558 #define __CIO_W_EDGEBUFFER 3
1559 #define __CIO_R_HEADER 4
1560 #define __CIO_R_NODEBUFFER 5
1561 #define __CIO_R_EDGEBUFFER 6
1562 #define __CIO_END 7
1563 
1565 {
1566  pIO->pG = pG;
1567  pIO->nState = __CIO_BEGIN;
1568  pIO->cb = 0;
1569  pIO->ib = 0;
1570  pIO->pb = NULL;
1571  return 0;
1572 }
1573 
1575 {
1576 }
1577 
1579 {
1580  unsigned char *pb;
1581  int cb;
1582 
1583  switch (pIO->nState) {
1584  case __CIO_BEGIN:
1585  pIO->pb = pIO->ab;
1586  pb = pIO->pb;
1587  memcpy(pb, &pIO->pG->Version, 1);
1588  pb += 1; /* 1 */
1589  memcpy(pb, &pIO->pG->Endian, 1);
1590  pb += 1; /* 2 */
1591  memcpy(pb, &pIO->pG->NodeAttrSize, 4);
1592  pb += 4; /* 6 */
1593  memcpy(pb, &pIO->pG->EdgeAttrSize, 4);
1594  pb += 4; /* 10 */
1595  memcpy(pb, &pIO->pG->aOpaqueSet, 64);
1596  pb += 64; /* 74 */
1597  memcpy(pb, &pIO->pG->nOptions, 4);
1598  pb += 4; /* 78 */
1599  memcpy(pb, &pIO->pG->nFamily, 4);
1600  pb += 4; /* 82 */
1601  memcpy(pb, &pIO->pG->nnCost, 8);
1602  pb += 8; /* 90 */
1603  memcpy(pb, &pIO->pG->cNode, 4);
1604  pb += 4; /* 94 */
1605  memcpy(pb, &pIO->pG->cHead, 4);
1606  pb += 4; /* 98 */
1607  memcpy(pb, &pIO->pG->cTail, 4);
1608  pb += 4; /* 102 */
1609  memcpy(pb, &pIO->pG->cAlone, 4);
1610  pb += 4; /* 106 */
1611  memcpy(pb, &pIO->pG->cEdge, 4);
1612  pb += 4; /* 110 */
1613  memcpy(pb, &pIO->pG->iNodeBuffer, 4);
1614  pb += 4; /* 114 */
1615  memcpy(pb, &pIO->pG->iEdgeBuffer, 4);
1616  pb += 4; /* 118 */
1617  pIO->cb = 118;
1618  cb = pfn(pIO->pG, pIO->pb, pIO->cb, pv);
1619  if (cb >= 0) {
1620  pIO->ib += cb;
1621  if ((pIO->cb - pIO->ib) == 0) {
1622  pIO->ib = 0;
1623  pIO->cb = pIO->pG->iNodeBuffer;
1624  pIO->pb = pIO->pG->pNodeBuffer;
1625  pIO->nState = __CIO_W_NODEBUFFER;
1626  }
1627  else {
1628  pIO->nState = __CIO_W_HEADER;
1629  }
1630  }
1631  return cb;
1632  case __CIO_W_HEADER:
1633  cb = pfn(pIO->pG, pIO->pb + pIO->ib, pIO->cb - pIO->ib, pv);
1634  if (cb > 0) {
1635  pIO->ib += cb;
1636  if ((pIO->cb - pIO->ib) == 0) {
1637  if (pIO->pG->iNodeBuffer > 0) {
1638  pIO->ib = 0;
1639  pIO->cb = pIO->pG->iNodeBuffer;
1640  pIO->pb = pIO->pG->pNodeBuffer;
1641  pIO->nState = __CIO_W_NODEBUFFER;
1642  }
1643  else if (pIO->pG->iEdgeBuffer > 0) {
1644  pIO->ib = 0;
1645  pIO->cb = pIO->pG->iEdgeBuffer;
1646  pIO->pb = pIO->pG->pEdgeBuffer;
1647  pIO->nState = __CIO_W_EDGEBUFFER;
1648  }
1649  else {
1650  pIO->nState = __CIO_END;
1651  }
1652  }
1653  else {
1654  pIO->nState = __CIO_W_HEADER;
1655  }
1656  }
1657  return cb;
1658  case __CIO_W_NODEBUFFER:
1659  cb = pfn(pIO->pG, pIO->pb + pIO->ib, pIO->cb - pIO->ib, pv);
1660  if (cb > 0) {
1661  pIO->ib += cb;
1662  if ((pIO->cb - pIO->ib) == 0) {
1663  if (pIO->pG->iEdgeBuffer > 0) {
1664  pIO->ib = 0;
1665  pIO->cb = pIO->pG->iEdgeBuffer;
1666  pIO->pb = pIO->pG->pEdgeBuffer;
1667  pIO->nState = __CIO_W_EDGEBUFFER;
1668  }
1669  else {
1670  pIO->nState = __CIO_END;
1671  }
1672  }
1673  }
1674  return cb;
1675  case __CIO_W_EDGEBUFFER:
1676  cb = pfn(pIO->pG, pIO->pb + pIO->ib, pIO->cb - pIO->ib, pv);
1677  if (cb > 0) {
1678  pIO->ib += cb;
1679  if ((pIO->cb - pIO->ib) == 0) {
1680  pIO->nState = __CIO_END;
1681  }
1682  }
1683  return cb;
1684  case __CIO_END:
1685  pfn(pIO->pG, NULL, 0, pv); /* notify end of graph */
1686  return 0;
1687  }
1688  return 0;
1689 }
1690 
1691 int dglReadChunk(dglIOContext_s * pIO, dglByte_t * pbChunk, int cbChunk)
1692 {
1693  int i, c;
1694  unsigned char *pb;
1695 
1696  switch (pIO->nState) {
1697  case __CIO_BEGIN:
1698  pIO->cb = 118;
1699  pIO->ib = 0;
1700  pIO->pb = pIO->ab;
1701 
1702  c = MIN(cbChunk, 118);
1703  memcpy(pIO->pb, pbChunk, c);
1704  pIO->ib += c;
1705  if ((pIO->cb - pIO->ib) == 0)
1706  goto init_nodebuffer;
1707  pIO->nState = __CIO_R_HEADER;
1708  return c;
1709 
1710  case __CIO_R_HEADER:
1711  c = MIN(cbChunk, pIO->cb - pIO->ib);
1712  memcpy(pIO->pb + pIO->ib, pbChunk, c);
1713  pIO->ib += c;
1714  init_nodebuffer:
1715  if ((pIO->cb - pIO->ib) == 0) {
1716  pb = pIO->pb;
1717  memcpy(&pIO->pG->Version, pb, 1);
1718  pb += 1; /* 1 */
1719  memcpy(&pIO->pG->Endian, pb, 1);
1720  pb += 1; /* 2 */
1721  memcpy(&pIO->pG->NodeAttrSize, pb, 4);
1722  pb += 4; /* 6 */
1723  memcpy(&pIO->pG->EdgeAttrSize, pb, 4);
1724  pb += 4; /* 10 */
1725  memcpy(&pIO->pG->aOpaqueSet, pb, 64);
1726  pb += 64; /* 74 */
1727  memcpy(&pIO->pG->nOptions, pb, 4);
1728  pb += 4; /* 78 */
1729  memcpy(&pIO->pG->nFamily, pb, 4);
1730  pb += 4; /* 82 */
1731  memcpy(&pIO->pG->nnCost, pb, 8);
1732  pb += 8; /* 90 */
1733  memcpy(&pIO->pG->cNode, pb, 4);
1734  pb += 4; /* 94 */
1735  memcpy(&pIO->pG->cHead, pb, 4);
1736  pb += 4; /* 98 */
1737  memcpy(&pIO->pG->cTail, pb, 4);
1738  pb += 4; /* 102 */
1739  memcpy(&pIO->pG->cAlone, pb, 4);
1740  pb += 4; /* 106 */
1741  memcpy(&pIO->pG->cEdge, pb, 4);
1742  pb += 4; /* 110 */
1743  memcpy(&pIO->pG->iNodeBuffer, pb, 4);
1744  pb += 4; /* 114 */
1745  memcpy(&pIO->pG->iEdgeBuffer, pb, 4);
1746  pb += 4; /* 118 */
1747 
1748  pIO->fSwap = 0;
1749 #ifdef DGL_ENDIAN_BIG
1750  if (pIO->pG->Endian == DGL_ENDIAN_LITTLE)
1751  pIO->fSwap = 1;
1752 #else
1753  if (pIO->pG->Endian == DGL_ENDIAN_BIG)
1754  pIO->fSwap = 1;
1755 #endif
1756  if (pIO->fSwap) {
1759  dgl_swapInt32Bytes(&pIO->pG->nOptions);
1760  dgl_swapInt32Bytes(&pIO->pG->nFamily);
1761  dgl_swapInt64Bytes(&pIO->pG->nnCost);
1762  dgl_swapInt32Bytes(&pIO->pG->cNode);
1763  dgl_swapInt32Bytes(&pIO->pG->cHead);
1764  dgl_swapInt32Bytes(&pIO->pG->cTail);
1765  dgl_swapInt32Bytes(&pIO->pG->cAlone);
1766  dgl_swapInt32Bytes(&pIO->pG->cEdge);
1769 
1770  for (i = 0; i < 16; i++) {
1771  dgl_swapInt32Bytes(&pIO->pG->aOpaqueSet[i]);
1772  }
1773 
1774 #ifdef DGL_ENDIAN_BIG
1775  pIO->pG->Endian = DGL_ENDIAN_BIG;
1776 #else
1777  pIO->pG->Endian = DGL_ENDIAN_LITTLE;
1778 #endif
1779  }
1780 
1781  if (pIO->pG->iNodeBuffer > 0) {
1782  pIO->pG->pNodeBuffer = malloc(pIO->pG->iNodeBuffer);
1783  if (pIO->pG->pNodeBuffer == NULL) {
1784  return -1;
1785  }
1786  pIO->cb = pIO->pG->iNodeBuffer;
1787  pIO->pb = pIO->pG->pNodeBuffer;
1788  pIO->ib = 0;
1789  pIO->nState = __CIO_R_NODEBUFFER;
1790  }
1791  else {
1792  goto init_edgebuffer;
1793  }
1794  }
1795  return c;
1796  case __CIO_R_NODEBUFFER:
1797  c = MIN(cbChunk, pIO->cb - pIO->ib);
1798  memcpy(pIO->pb + pIO->ib, pbChunk, c);
1799  pIO->ib += c;
1800  init_edgebuffer:
1801  if ((pIO->cb - pIO->ib) == 0) {
1802  if (pIO->pG->iEdgeBuffer > 0) {
1803  pIO->pG->pEdgeBuffer = malloc(pIO->pG->iEdgeBuffer);
1804  if (pIO->pG->pEdgeBuffer == NULL) {
1805  return -1;
1806  }
1807  pIO->cb = pIO->pG->iEdgeBuffer;
1808  pIO->pb = pIO->pG->pEdgeBuffer;
1809  pIO->ib = 0;
1810  pIO->nState = __CIO_R_EDGEBUFFER;
1811  }
1812  else {
1813  pIO->nState = __CIO_END;
1814  }
1815  }
1816  return c;
1817  case __CIO_R_EDGEBUFFER:
1818  c = MIN(cbChunk, pIO->cb - pIO->ib);
1819  memcpy(pIO->pb + pIO->ib, pbChunk, c);
1820  pIO->ib += c;
1821  if ((pIO->cb - pIO->ib) == 0) {
1822  pIO->nState = __CIO_END;
1823  }
1824  return c;
1825  case __CIO_END:
1826  {
1827  /* switch on FLAT bit */
1828  pIO->pG->Flags |= DGL_GS_FLAT;
1829 
1830  /* nodebuffer and edgebuffer are both arrays on 32 bit integer
1831  * byte order swapping is straightforward
1832  */
1833  if (pIO->fSwap && pIO->pG->iNodeBuffer > 0) {
1834  int in, cn;
1835  dglInt32_t *pn;
1836 
1837  for (cn = pIO->pG->iNodeBuffer / sizeof(dglInt32_t),
1838  pn = (dglInt32_t *) pIO->pG->pNodeBuffer,
1839  in = 0; in < cn; in++) {
1840  dgl_swapInt32Bytes(&pn[in]);
1841  }
1842  }
1843  if (pIO->fSwap && pIO->pG->iEdgeBuffer > 0) {
1844  int in, cn;
1845  dglInt32_t *pn;
1846 
1847  for (cn = pIO->pG->iEdgeBuffer / sizeof(dglInt32_t),
1848  pn = (dglInt32_t *) pIO->pG->pEdgeBuffer,
1849  in = 0; in < cn; in++) {
1850  dgl_swapInt32Bytes(&pn[in]);
1851  }
1852  }
1853  }
1854  return 0;
1855  default:
1856  return 0;
1857  }
1858 }
dglGraph_s * pGraph
Definition: graph.h:271
dglInt32_t cEdge
Definition: graph.h:166
#define DGL_NS_HEAD
Definition: graph.h:60
dglInt64_t nnCost
Definition: graph.h:167
#define DGL_ERR_BadArgument
Definition: graph.h:303
dglInt32_t * dgl_node_t_next_V2(dglNodeTraverser_s *pT)
#define DGL_ERR_VersionNotSupported
Definition: graph.h:298
int dglMinimumSpanning(dglGraph_s *pgraphInput, dglGraph_s *pgraphOutput, dglInt32_t nVertexNode, dglSpanClip_fn fnClip, void *pvClipArg)
dglEdgePrioritizer_s * dglGet_EdgePrioritizer(dglGraph_s *pGraph)
dglInt32_t Flags
Definition: graph.h:169
void dgl_node_t_release_V2(dglNodeTraverser_s *pT)
dglInt32_t * dglGetNode(dglGraph_s *pGraph, dglInt32_t nNodeId)
dglEdgePrioritizer_s edgePrioritizer
Definition: graph.h:181
dglInt32_t * dgl_get_node_V2(dglGraph_s *pgraph, dglInt32_t nId)
int dgl_dijkstra_V2(dglGraph_s *pgraph, dglSPReport_s **ppReport, dglInt32_t *pDistance, dglInt32_t nStart, dglInt32_t nDestination, dglSPClip_fn fnClip, void *pvClipArg, dglSPCache_s *pCache)
Definition: graph_v2.c:67
#define DGL_ERR_Write
Definition: graph.h:286
#define DGL_ERR_UnknownByteOrder
Definition: graph.h:289
dglNodePrioritizer_s * dglGet_NodePrioritizer(dglGraph_s *pGraph)
int dgl_release_V2(dglGraph_s *pgraph)
Definition: graph_v2.c:139
void dglTreeNodeCancel(void *pvNode, void *pvParam)
Definition: tree.c:44
unsigned char dglByte_t
Definition: type.h:36
void dgl_sp_cache_release_V1(dglGraph_s *pgraph, dglSPCache_s *pCache)
#define avl_destroy
Definition: tree.h:33
int dglNodeGet_Valence(dglGraph_s *pGraph, dglInt32_t *pnNode)
#define avl_find
Definition: tree.h:38
#define __CIO_W_HEADER
dglInt32_t * pnEdge
Definition: graph.h:215
int dgl_read_V2(dglGraph_s *pgraph, int fd, int version)
Definition: graph_v2.c:256
void dglNodeSet_Attr(dglGraph_s *pGraph, dglInt32_t *pnNode, dglInt32_t *pnAttr)
dglInt32_t * dgl_getnode_outedgeset_V2(dglGraph_s *pgraph, dglInt32_t *pnode)
dglInt32_t nFamily
Definition: graph.h:170
dglInt32_t NodeAttrSize
Definition: graph.h:158
#define DGL_NODEBUFFER_SHIFT_v2(pgrp, o)
Definition: graph_v2.h:108
void dgl_edge_t_release_V2(dglEdgeTraverser_s *pTraverser)
#define DGL_EDGE_ID_v1(p)
Definition: graph_v1.h:81
#define DGL_ERR_TreeSearchError
Definition: graph.h:296
#define DGL_EDGE_COST_v2(p)
Definition: graph_v2.h:82
dglInt32_t dglNodeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglInt32_t iEdgeBuffer
Definition: graph.h:178
#define DGL_ERR_NodeAlreadyExist
Definition: graph.h:300
#define DGL_EDGE_SIZEOF_v2(lattr)
Definition: graph_v2.h:75
int dgl_initialize_V1(dglGraph_s *pgraph)
Definition: graph_v1.c:120
#define __CIO_R_NODEBUFFER
#define DGL_ERR_EdgeAlreadyExist
Definition: graph.h:302
dglNodePrioritizer_s nodePrioritizer
Definition: graph.h:182
dglInt32_t * dgl_edge_t_next_V2(dglEdgeTraverser_s *pT)
void dglNode_T_Release(dglNodeTraverser_s *pT)
#define DGL_EDGESET_EDGECOUNT_v1(p)
Definition: graph_v1.h:60
dglInt32_t dglEdgeGet_Cost(dglGraph_s *pGraph, dglInt32_t *pnEdge)
int dgl_del_node_V2(dglGraph_s *pgraph, dglInt32_t nId)
int dgl_del_node_V1(dglGraph_s *pgraph, dglInt32_t nId)
void dgl_sp_cache_release_V2(dglGraph_s *pgraph, dglSPCache_s *pCache)
int dgl_release_V1(dglGraph_s *pgraph)
Definition: graph_v1.c:133
int dgl_node_t_initialize_V1(dglGraph_s *pGraph, dglNodeTraverser_s *pT)
dglInt32_t * dgl_node_t_find_V2(dglNodeTraverser_s *pT, dglInt32_t nId)
int dglEdgeSet_Attr(dglGraph_s *pGraph, dglInt32_t *pnAttr, dglInt32_t *pnEdge)
int dgl_sp_cache_initialize_V2(dglGraph_s *pgraph, dglSPCache_s *pCache, dglInt32_t nStart)
dglInt32_t * dgl_get_edge_V1(dglGraph_s *pgraph, dglInt32_t nId)
long nKey
Definition: tree.h:63
dglInt32_t * dglEdgeGet_Head(dglGraph_s *pGraph, dglInt32_t *pnEdge)
dglInt32_t * dglEdge_T_Next(dglEdgeTraverser_s *pT)
void dglSet_Version(dglGraph_s *pgraph, int nVersion)
int dglDelNode(dglGraph_s *pGraph, dglInt32_t nNodeId)
void dgl_swapInt64Bytes(dglInt64_t *pn)
Definition: helpers.c:68
#define DGL_NODE_ID_v2(p)
Definition: graph_v2.h:43
unsigned char ab[118]
Definition: graph.h:381
int dglGet_NodeCount(dglGraph_s *pgraph)
int dgl_node_t_initialize_V2(dglGraph_s *pGraph, dglNodeTraverser_s *pT)
int(* dglSpanClip_fn)(dglGraph_s *, dglGraph_s *, dglSpanClipInput_s *, dglSpanClipOutput_s *, void *)
Definition: graph.h:204
dglInt32_t * dglEdgeGet_Tail(dglGraph_s *pGraph, dglInt32_t *pnEdge)
void free(void *)
dglInt32_t * dglGet_Opaque(dglGraph_s *pgraph)
#define NULL
Definition: ccmath.h:32
unsigned char * pb
Definition: graph.h:380
int dgl_add_edge_V2(dglGraph_s *pgraph, dglInt32_t nHead, dglInt32_t nTail, dglInt32_t nCost, dglInt32_t nEdge, void *pvHeadAttr, void *pvTailAttr, void *pvEdgeAttr, dglInt32_t nFlags)
dglInt32_t dglNodeGet_Status(dglGraph_s *pGraph, dglInt32_t *pnNode)
#define DGL_EDGE_ID_v2(p)
Definition: graph_v2.h:83
int dglGet_EdgeAttrSize(dglGraph_s *pgraph)
#define DGL_ERR_HeadNodeNotFound
Definition: graph.h:290
dglInt32_t * dgl_edge_t_first_V1(dglEdgeTraverser_s *pT)
#define DGL_ENDIAN_BIG
Definition: graph.h:74
#define DGL_NODE_SIZEOF_v1(nattr)
Definition: graph_v1.h:39
#define DGL_NODE_SIZEOF_v2(nattr)
Definition: graph_v2.h:39
int dgl_edgeset_t_initialize_V1(dglGraph_s *pGraph, dglEdgesetTraverser_s *pTraverser, dglInt32_t *pnEdgeset)
int dgl_add_edge_V1(dglGraph_s *pgraph, dglInt32_t nHead, dglInt32_t nTail, dglInt32_t nCost, dglInt32_t nEdge, void *pvHeadAttr, void *pvTailAttr, void *pvEdgeAttr, dglInt32_t nFlags)
int dgl_dijkstra_V1(dglGraph_s *pgraph, dglSPReport_s **ppReport, dglInt32_t *pDistance, dglInt32_t nStart, dglInt32_t nDestination, dglSPClip_fn fnClip, void *pvClipArg, dglSPCache_s *pCache)
Definition: graph_v1.c:67
int dglGet_Version(dglGraph_s *pgraph)
int dglInitialize(dglGraph_s *pGraph, dglByte_t Version, dglInt32_t NodeAttrSize, dglInt32_t EdgeAttrSize, dglInt32_t *pOpaqueSet)
int dgl_sp_cache_initialize_V1(dglGraph_s *pgraph, dglSPCache_s *pCache, dglInt32_t nStart)
dglInt32_t * dglEdge_T_First(dglEdgeTraverser_s *pT)
dglInt32_t * dgl_edgeset_t_next_V1(dglEdgesetTraverser_s *pTraverser)
dglInt32_t cNode
Definition: graph.h:162
#define DGL_EDGE_ATTR_PTR_v1(p)
Definition: graph_v1.h:82
void * malloc(YYSIZE_T)
dglGraph_s * pGraph
Definition: graph.h:260
dglGraph_s * pG
Definition: graph.h:375
int dglTreeNodeCompare(const void *pvNodeA, const void *pvNodeB, void *pvParam)
Definition: tree.c:53
dglInt32_t * dgl_get_edge_V2(dglGraph_s *pgraph, dglInt32_t nId)
int dglGet_HeadNodeCount(dglGraph_s *pgraph)
#define DGL_ERR_Read
Definition: graph.h:287
#define DGL_ERR_BadVersion
Definition: graph.h:281
int dglGet_Endianess(dglGraph_s *pgraph)
int dgl_write_V2(dglGraph_s *pgraph, int fd)
Definition: graph_v2.c:160
void dgl_node_t_release_V1(dglNodeTraverser_s *pT)
#define __CIO_BEGIN
void dglSet_Opaque(dglGraph_s *pgraph, dglInt32_t *pOpaque)
int iErrno
Definition: graph.h:154
#define DGL_GS_FLAT
Definition: graph.h:36
dglInt32_t * dgl_getnode_inedgeset_V2(dglGraph_s *pgraph, dglInt32_t *pnode)
#define DGL_EDGE_TAILNODE_OFFSET_v2(p)
Definition: graph_v2.h:80
#define __CIO_END
int dgl_minimum_spanning_V1(dglGraph_s *pgraphIn, dglGraph_s *pgraphOut, dglInt32_t nVertex, dglSpanClip_fn fnClip, void *pvClipArg)
Definition: graph_v1.c:104
dglInt32_t aOpaqueSet[16]
Definition: graph.h:160
#define DGL_NODE_ATTR_PTR_v1(p)
Definition: graph_v1.h:46
dglInt32_t * dglNode_T_First(dglNodeTraverser_s *pT)
char * dglStrerror(dglGraph_s *pgraph)
#define DGL_EDGE_TAILNODE_OFFSET_v1(p)
Definition: graph_v1.h:79
int dglErrno(dglGraph_s *pgraph)
int dglGet_EdgeSize(dglGraph_s *pgraph)
dglInt32_t cTail
Definition: graph.h:164
int dgl_depthfirst_spanning_V2(dglGraph_s *pgraphIn, dglGraph_s *pgraphOut, dglInt32_t nVertex, void *pvVisited, dglSpanClip_fn fnClip, void *pvClipArg)
Definition: graph_v2.c:86
int dglWrite(dglGraph_s *pGraph, int fd)
int dgl_del_edge_V2(dglGraph_s *pgraph, dglInt32_t nId)
int dglInitializeSPCache(dglGraph_s *pGraph, dglSPCache_s *pCache)
#define DGL_ERR_UndefinedMethod
Definition: graph.h:285
void dglReleaseSPCache(dglGraph_s *pGraph, dglSPCache_s *pCache)
#define DGL_ERR_HeapError
Definition: graph.h:284
#define DGL_ERR_NotSupported
Definition: graph.h:288
void dgl_edge_t_release_V1(dglEdgeTraverser_s *pTraverser)
#define DGL_NODE_STATUS_v2(p)
Definition: graph_v2.h:44
dglInt32_t * dglEdgeset_T_First(dglEdgesetTraverser_s *pT)
#define __CIO_W_EDGEBUFFER
int dgl_add_node_V2(dglGraph_s *pgraph, dglInt32_t nId, void *pvNodeAttr, dglInt32_t nFlags)
#define MIN(a, b)
Definition: gis.h:140
dglSPArc_s * pArc
Definition: graph.h:229
#define avl_create
Definition: tree.h:31
#define DGL_NODE_ID_v1(p)
Definition: graph_v1.h:43
#define DGL_EDGE_HEADNODE_OFFSET_v1(p)
Definition: graph_v1.h:78
void dgl_swapInt32Bytes(dglInt32_t *pn)
Definition: helpers.c:55
#define DGL_ERR_MemoryExhausted
Definition: graph.h:283
int dgl_edge_t_initialize_V1(dglGraph_s *pGraph, dglEdgeTraverser_s *pTraverser, dglEdgePrioritizer_s *pEP)
long long dglInt64_t
Definition: type.h:38
dglInt32_t * dgl_get_node_V1(dglGraph_s *pgraph, dglInt32_t nId)
#define DGL_ERR_BadOnFlatGraph
Definition: graph.h:293
long dglInt32_t
Definition: type.h:37
int dgl_flatten_V2(dglGraph_s *pgraph)
int dglGet_NodeSize(dglGraph_s *pgraph)
int dgl_minimum_spanning_V2(dglGraph_s *pgraphIn, dglGraph_s *pgraphOut, dglInt32_t nVertex, dglSpanClip_fn fnClip, void *pvClipArg)
Definition: graph_v2.c:104
void * dglTreeGetAllocator()
Definition: tree.c:422
#define DGL_EDGE_COST_v1(p)
Definition: graph_v1.h:80
int dgl_unflatten_V2(dglGraph_s *pgraph)
#define DGL_ERR_TailNodeNotFound
Definition: graph.h:291
void dglEdgeset_T_Release(dglEdgesetTraverser_s *pT)
int dgl_initialize_V2(dglGraph_s *pgraph)
Definition: graph_v2.c:120
#define DGL_ENDIAN_LITTLE
Definition: graph.h:75
void dglIOContextRelease(dglIOContext_s *pIO)
int dgl_del_edge_V1(dglGraph_s *pgraph, dglInt32_t nId)
#define __CIO_W_NODEBUFFER
int dglShortestDistance(dglGraph_s *pGraph, dglInt32_t *pnDistance, dglInt32_t nStart, dglInt32_t nDestination, dglSPClip_fn fnClip, void *pvClipArg, dglSPCache_s *pCache)
#define DGL_NODE_STATUS_v1(p)
Definition: graph_v1.h:44
dglInt32_t * dgl_node_t_first_V1(dglNodeTraverser_s *pT)
int dglWriteChunk(dglIOContext_s *pIO, dglWriteChunk_fn pfn, void *pv)
dglGraph_s * pGraph
Definition: graph.h:250
int dglRead(dglGraph_s *pGraph, int fd)
dglInt32_t * dglGetEdge(dglGraph_s *pGraph, dglInt32_t nEdgeId)
dglInt32_t cAlone
Definition: graph.h:165
int dglDepthSpanning(dglGraph_s *pgraphInput, dglGraph_s *pgraphOutput, dglInt32_t nVertexNode, dglSpanClip_fn fnClip, void *pvClipArg)
dglInt32_t dglEdgesetGet_EdgeCount(dglGraph_s *pGraph, dglInt32_t *pnEdgeset)
int dgl_edgeset_t_initialize_V2(dglGraph_s *pGraph, dglEdgesetTraverser_s *pTraverser, dglInt32_t *pnEdgeset)
int dgl_add_node_V1(dglGraph_s *pgraph, dglInt32_t nId, void *pvNodeAttr, dglInt32_t nFlags)
int dglGet_TailNodeCount(dglGraph_s *pgraph)
dglInt32_t cHead
Definition: graph.h:163
#define DGL_EDGESET_EDGECOUNT_v2(p)
Definition: graph_v2.h:60
#define DGL_ERR_BadOnTreeGraph
Definition: graph.h:294
int(* dglWriteChunk_fn)(dglGraph_s *, unsigned char *pbChunk, int cbChunk, void *pvArg)
Definition: graph.h:390
dglInt32_t * dgl_edgeset_t_next_V2(dglEdgesetTraverser_s *pTraverser)
dglInt32_t * dglNode_T_Find(dglNodeTraverser_s *pT, dglInt32_t nNodeId)
#define DGL_EDGE_ATTR_PTR_v2(p)
Definition: graph_v2.h:84
int dgl_unflatten_V1(dglGraph_s *pgraph)
int(* dglSPClip_fn)(dglGraph_s *, dglSPClipInput_s *, dglSPClipOutput_s *, void *)
Definition: graph.h:198
dglInt32_t * dgl_node_t_find_V1(dglNodeTraverser_s *pT, dglInt32_t nId)
int dglEdge_T_Initialize(dglEdgeTraverser_s *pT, dglGraph_s *pGraph, dglEdgePrioritizer_s *pEdgePrioritizer)
int dglAddEdge(dglGraph_s *pGraph, dglInt32_t nHead, dglInt32_t nTail, dglInt32_t nCost, dglInt32_t nEdge)
int dgl_edge_t_initialize_V2(dglGraph_s *pGraph, dglEdgeTraverser_s *pTraverser, dglEdgePrioritizer_s *pEP)
int dgl_flatten_V1(dglGraph_s *pgraph)
dglInt32_t dglGet_Options(dglGraph_s *pgraph)
#define __CIO_R_HEADER
dglInt32_t * dgl_edge_t_first_V2(dglEdgeTraverser_s *pT)
int dglUnflatten(dglGraph_s *pGraph)
#define DGL_NODE_ATTR_PTR_v2(p)
Definition: graph_v2.h:46
#define DGL_ERR_EdgeNotFound
Definition: graph.h:299
dglInt32_t * dgl_getnode_outedgeset_V1(dglGraph_s *pgraph, dglInt32_t *pnode)
int dglAddEdgeX(dglGraph_s *pGraph, dglInt32_t nHead, dglInt32_t nTail, dglInt32_t nCost, dglInt32_t nEdge, void *pvHeadAttr, void *pvTailAttr, void *pvEdgeAttr, dglInt32_t nFlags)
dglInt32_t cArc
Definition: graph.h:228
#define __CIO_R_EDGEBUFFER
#define DGL_ERR_BadNodeType
Definition: graph.h:282
int dgl_depthfirst_spanning_V1(dglGraph_s *pgraphIn, dglGraph_s *pgraphOut, dglInt32_t nVertex, void *pvVisited, dglSpanClip_fn fnClip, void *pvClipArg)
Definition: graph_v1.c:86
int dglNodeGet_InDegree(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglInt32_t * dglNodeGet_Attr(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglByte_t Version
Definition: graph.h:156
dglInt32_t * dglEdgeGet_Attr(dglGraph_s *pGraph, dglInt32_t *pnEdge)
#define DGL_ERR_BadEdge
Definition: graph.h:292
int dglNodeGet_OutDegree(dglGraph_s *pGraph, dglInt32_t *pnNode)
int dglGet_EdgeCount(dglGraph_s *pgraph)
void dglEdge_T_Release(dglEdgeTraverser_s *pT)
void dglResetStats(dglGraph_s *pgraph)
#define DGL_NODEBUFFER_SHIFT_v1(pgrp, o)
Definition: graph_v1.h:105
dglInt32_t * dgl_edgeset_t_first_V1(dglEdgesetTraverser_s *pTraverser)
int dgl_read_V1(dglGraph_s *pgraph, int fd)
Definition: graph_v1.c:250
dglInt32_t * dgl_node_t_next_V1(dglNodeTraverser_s *pT)
int dglDepthComponents(dglGraph_s *pgraphInput, dglGraph_s *pgraphComponents, int cgraphComponents, dglSpanClip_fn fnClip, void *pvClipArg)
int dglDelEdge(dglGraph_s *pGraph, dglInt32_t nEdgeId)
#define DGL_ERR_NodeNotFound
Definition: graph.h:295
dglInt32_t EdgeAttrSize
Definition: graph.h:159
void dglSet_Family(dglGraph_s *pgraph, dglInt32_t nFamily)
#define DGL_ERR_UnexpectedNullPointer
Definition: graph.h:297
int dglReadChunk(dglIOContext_s *pIO, dglByte_t *pbChunk, int cbChunk)
dglByte_t Endian
Definition: graph.h:157
dglInt32_t * dglNodeGet_InEdgeset(dglGraph_s *pGraph, dglInt32_t *pnNode)
#define DGL_NS_ALONE
Definition: graph.h:62
#define DGL_EDGE_SIZEOF_v1(lattr)
Definition: graph_v1.h:74
#define DGL_ERR_NodeIsAComponent
Definition: graph.h:301
int dglNode_T_Initialize(dglNodeTraverser_s *pT, dglGraph_s *pGraph)
int dglGet_AloneNodeCount(dglGraph_s *pgraph)
dglInt32_t * dglEdgeset_T_Next(dglEdgesetTraverser_s *pT)
void dglSet_Options(dglGraph_s *pgraph, dglInt32_t nOptions)
dglInt32_t * dgl_edge_t_next_V1(dglEdgeTraverser_s *pT)
dglInt32_t iNodeBuffer
Definition: graph.h:176
void dglSet_Cost(dglGraph_s *pgraph, dglInt64_t nnCost)
dglInt32_t * dglNodeGet_OutEdgeset(dglGraph_s *pGraph, dglInt32_t *pnNode)
#define DGL_EDGE_HEADNODE_OFFSET_v2(p)
Definition: graph_v2.h:79
int dglEdgeset_T_Initialize(dglEdgesetTraverser_s *pT, dglGraph_s *pGraph, dglInt32_t *pnEdgeset)
int dglIOContextInitialize(dglGraph_s *pG, dglIOContext_s *pIO)
int dglGet_State(dglGraph_s *pgraph)
dglInt32_t * dglNode_T_Next(dglNodeTraverser_s *pT)
dglByte_t * pEdgeBuffer
Definition: graph.h:177
dglInt32_t nOptions
Definition: graph.h:171
int dglFlatten(dglGraph_s *pGraph)
int dglAddNode(dglGraph_s *pGraph, dglInt32_t nNodeId, void *pvNodeAttr, dglInt32_t nFlags)
dglInt32_t dglEdgeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnEdge)
int dglRelease(dglGraph_s *pGraph)
dglInt32_t * dgl_node_t_first_V2(dglNodeTraverser_s *pT)
dglInt64_t dglGet_Cost(dglGraph_s *pgraph)
void dglFreeSPReport(dglGraph_s *pgraph, dglSPReport_s *pSPReport)
dglInt32_t * dgl_edgeset_t_first_V2(dglEdgesetTraverser_s *pTraverser)
int nState
Definition: graph.h:376
dglByte_t * pNodeBuffer
Definition: graph.h:175
int dglGet_NodeAttrSize(dglGraph_s *pgraph)
int dglShortestPath(dglGraph_s *pGraph, dglSPReport_s **ppReport, dglInt32_t nStart, dglInt32_t nDestination, dglSPClip_fn fnClip, void *pvClipArg, dglSPCache_s *pCache)
dglInt32_t dglGet_Family(dglGraph_s *pgraph)
int dgl_write_V1(dglGraph_s *pgraph, int fd)
Definition: graph_v1.c:154