25 #include <sys/types.h>
46 pgraph->clkAddEdge = 0;
48 pgraph->clkNodeTree = 0;
49 pgraph->cNodeTree = 0;
615 pGraph->clkAddEdge += clock() - clk;
622 void *pvTailAttr,
void *pvEdgeAttr,
dglInt32_t nFlags)
635 pvTailAttr, pvEdgeAttr, nFlags);
641 pvTailAttr, pvEdgeAttr, nFlags);
650 pGraph->clkAddEdge += clock() - clk;
727 if (read(fd, &bVersion, 1) != 1) {
760 fnClip, pvClipArg, pCache);
766 fnClip, pvClipArg, pCache);
787 fnClip, pvClipArg, pCache);
793 fnClip, pvClipArg, pCache);
817 if (pgraphInput->
Version == 2) {
819 return -pgraphInput->
iErrno;
834 return -pgraphInput->
iErrno;
837 switch (pgraphInput->
Version) {
841 pvVisited, fnClip, pvClipArg);
848 pvVisited, fnClip, pvClipArg);
853 nRet = -pgraphInput->
iErrno;
883 return -pgraphInput->
iErrno;
902 switch (pgraphInput->
Version) {
921 if (pvertex ==
NULL) {
926 for (i = 0; i < cgraphComponents && pvertex; i++) {
935 switch (pgraphInput->
Version) {
939 pvVisited, fnClip, pvClipArg);
948 pvVisited, fnClip, pvClipArg);
955 nret = -pgraphInput->
iErrno;
969 switch (pgraphInput->
Version) {
1026 switch (pgraphInput->
Version) {
1040 nRet = -pgraphInput->
iErrno;
1054 if (pSPReport->
pArc) {
1055 for (iArc = 0; iArc < pSPReport->
cArc; iArc++) {
1104 switch (pgraph->
iErrno) {
1106 return "Bad Version";
1108 return "Bad Node Type";
1110 return "Memory Exhausted";
1112 return "Heap Error";
1114 return "Undefined Method";
1120 return "Not Supported";
1122 return "Unknown Byte Order";
1124 return "Node Not Found";
1126 return "Head Node Not Found";
1128 return "Tail Node Not Found";
1132 return "Operation Not Supported On Flat-State Graph";
1134 return "Operation Not Supported On Tree-State Graph";
1136 return "Tree Search Error";
1138 return "Unexpected Null Pointer";
1140 return "Version Not Supported";
1142 return "Edge Not Found";
1144 return "Node Already Exist";
1146 return "Node Is A Component";
1148 return "Edge Already Exist";
1150 return "Bad Argument";
1153 return "unknown graph error code";
1185 return pgraph->
cNode;
1190 return pgraph->
cHead;
1195 return pgraph->
cTail;
1205 return pgraph->
cEdge;
1210 return pgraph->
Flags;
1491 #define __CIO_BEGIN 0
1492 #define __CIO_W_HEADER 1
1493 #define __CIO_W_NODEBUFFER 2
1494 #define __CIO_W_EDGEBUFFER 3
1495 #define __CIO_R_HEADER 4
1496 #define __CIO_R_NODEBUFFER 5
1497 #define __CIO_R_EDGEBUFFER 6
1539 memcpy(pb, &pIO->
pG->
cNode, 4);
1541 memcpy(pb, &pIO->
pG->
cHead, 4);
1543 memcpy(pb, &pIO->
pG->
cTail, 4);
1547 memcpy(pb, &pIO->
pG->
cEdge, 4);
1554 cb = pfn(pIO->
pG, pIO->
pb, pIO->
cb, pv);
1557 if ((pIO->
cb - pIO->
ib) == 0) {
1569 cb = pfn(pIO->
pG, pIO->
pb + pIO->
ib, pIO->
cb - pIO->
ib, pv);
1572 if ((pIO->
cb - pIO->
ib) == 0) {
1595 cb = pfn(pIO->
pG, pIO->
pb + pIO->
ib, pIO->
cb - pIO->
ib, pv);
1598 if ((pIO->
cb - pIO->
ib) == 0) {
1612 cb = pfn(pIO->
pG, pIO->
pb + pIO->
ib, pIO->
cb - pIO->
ib, pv);
1615 if ((pIO->
cb - pIO->
ib) == 0) {
1621 pfn(pIO->
pG,
NULL, 0, pv);
1638 c =
MIN(cbChunk, 118);
1639 memcpy(pIO->
pb, pbChunk, c);
1641 if ((pIO->
cb - pIO->
ib) == 0)
1642 goto init_nodebuffer;
1647 c =
MIN(cbChunk, pIO->
cb - pIO->
ib);
1648 memcpy(pIO->
pb + pIO->
ib, pbChunk, c);
1651 if ((pIO->
cb - pIO->
ib) == 0) {
1669 memcpy(&pIO->
pG->
cNode, pb, 4);
1671 memcpy(&pIO->
pG->
cHead, pb, 4);
1673 memcpy(&pIO->
pG->
cTail, pb, 4);
1677 memcpy(&pIO->
pG->
cEdge, pb, 4);
1685 #ifdef DGL_ENDIAN_BIG
1706 for (i = 0; i < 16; i++) {
1710 #ifdef DGL_ENDIAN_BIG
1728 goto init_edgebuffer;
1733 c =
MIN(cbChunk, pIO->
cb - pIO->
ib);
1734 memcpy(pIO->
pb + pIO->
ib, pbChunk, c);
1737 if ((pIO->
cb - pIO->
ib) == 0) {
1754 c =
MIN(cbChunk, pIO->
cb - pIO->
ib);
1755 memcpy(pIO->
pb + pIO->
ib, pbChunk, c);
1757 if ((pIO->
cb - pIO->
ib) == 0) {
#define UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
#define DGL_ERR_VersionNotSupported
int(* dglSPClip_fn)(dglGraph_s *, dglSPClipInput_s *, dglSPClipOutput_s *, void *)
#define DGL_ERR_BadOnTreeGraph
#define DGL_ERR_BadNodeType
#define DGL_ERR_NodeIsAComponent
#define DGL_ERR_UndefinedMethod
#define DGL_ERR_BadArgument
#define DGL_ERR_BadVersion
#define DGL_ERR_TreeSearchError
int(* dglWriteChunk_fn)(dglGraph_s *, unsigned char *pbChunk, int cbChunk, void *pvArg)
#define DGL_ENDIAN_LITTLE
#define DGL_ERR_MemoryExhausted
#define DGL_ERR_BadOnFlatGraph
#define DGL_ERR_EdgeAlreadyExist
#define DGL_ERR_NotSupported
#define DGL_ERR_UnknownByteOrder
#define DGL_ERR_HeadNodeNotFound
#define DGL_ERR_UnexpectedNullPointer
#define DGL_ERR_NodeAlreadyExist
int(* dglSpanClip_fn)(dglGraph_s *, dglGraph_s *, dglSpanClipInput_s *, dglSpanClipOutput_s *, void *)
#define DGL_ERR_HeapError
#define DGL_ERR_EdgeNotFound
#define DGL_ERR_NodeNotFound
#define DGL_ERR_TailNodeNotFound
int dgl_initialize_V1(dglGraph_s *pgraph)
int dgl_write_V1(dglGraph_s *pgraph, int fd)
int dgl_read_V1(dglGraph_s *pgraph, int fd)
int dgl_depthfirst_spanning_V1(dglGraph_s *pgraphIn, dglGraph_s *pgraphOut, dglInt32_t nVertex, void *pvVisited, dglSpanClip_fn fnClip, void *pvClipArg)
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)
int dgl_minimum_spanning_V1(dglGraph_s *pgraphIn, dglGraph_s *pgraphOut, dglInt32_t nVertex, dglSpanClip_fn fnClip, void *pvClipArg)
int dgl_release_V1(dglGraph_s *pgraph)
void dgl_node_t_release_V1(dglNodeTraverser_s *pT)
dglInt32_t * dgl_edgeset_t_next_V1(dglEdgesetTraverser_s *pTraverser)
int dgl_add_node_V1(dglGraph_s *pgraph, dglInt32_t nId, void *pvNodeAttr, dglInt32_t nFlags)
int dgl_unflatten_V1(dglGraph_s *pgraph)
#define DGL_EDGE_ATTR_PTR_v1(p)
dglInt32_t * dgl_node_t_first_V1(dglNodeTraverser_s *pT)
dglInt32_t * dgl_node_t_find_V1(dglNodeTraverser_s *pT, dglInt32_t nId)
int dgl_edgeset_t_initialize_V1(dglGraph_s *pGraph, dglEdgesetTraverser_s *pTraverser, dglInt32_t *pnEdgeset)
void dgl_sp_cache_release_V1(dglGraph_s *pgraph, dglSPCache_s *pCache)
dglInt32_t * dgl_get_edge_V1(dglGraph_s *pgraph, dglInt32_t nId)
#define DGL_NODEBUFFER_SHIFT_v1(pgrp, o)
dglInt32_t * dgl_edge_t_first_V1(dglEdgeTraverser_s *pT)
dglInt32_t * dgl_get_node_V1(dglGraph_s *pgraph, dglInt32_t nId)
#define DGL_NODE_SIZEOF_v1(nattr)
dglInt32_t * dgl_node_t_next_V1(dglNodeTraverser_s *pT)
#define DGL_EDGE_COST_v1(p)
#define DGL_EDGESET_EDGECOUNT_v1(p)
#define DGL_NODE_STATUS_v1(p)
dglInt32_t * dgl_edgeset_t_first_V1(dglEdgesetTraverser_s *pTraverser)
#define DGL_NODE_ATTR_PTR_v1(p)
int dgl_node_t_initialize_V1(dglGraph_s *pGraph, dglNodeTraverser_s *pT)
int dgl_sp_cache_initialize_V1(dglGraph_s *pgraph, dglSPCache_s *pCache, dglInt32_t nStart)
dglInt32_t * dgl_edge_t_next_V1(dglEdgeTraverser_s *pT)
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)
#define DGL_EDGE_SIZEOF_v1(lattr)
int dgl_flatten_V1(dglGraph_s *pgraph)
#define DGL_EDGE_TAILNODE_OFFSET_v1(p)
#define DGL_EDGE_HEADNODE_OFFSET_v1(p)
dglInt32_t * dgl_getnode_outedgeset_V1(dglGraph_s *pgraph, dglInt32_t *pnode)
int dgl_edge_t_initialize_V1(dglGraph_s *pGraph, dglEdgeTraverser_s *pTraverser, dglEdgePrioritizer_s *pEP)
#define DGL_EDGE_ID_v1(p)
int dgl_del_edge_V1(dglGraph_s *pgraph, dglInt32_t nId)
int dgl_del_node_V1(dglGraph_s *pgraph, dglInt32_t nId)
#define DGL_NODE_ID_v1(p)
void dgl_edge_t_release_V1(dglEdgeTraverser_s *pTraverser)
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)
int dgl_write_V2(dglGraph_s *pgraph, int fd)
int dgl_release_V2(dglGraph_s *pgraph)
int dgl_depthfirst_spanning_V2(dglGraph_s *pgraphIn, dglGraph_s *pgraphOut, dglInt32_t nVertex, void *pvVisited, dglSpanClip_fn fnClip, void *pvClipArg)
int dgl_initialize_V2(dglGraph_s *pgraph)
int dgl_read_V2(dglGraph_s *pgraph, int fd, int version)
int dgl_minimum_spanning_V2(dglGraph_s *pgraphIn, dglGraph_s *pgraphOut, dglInt32_t nVertex, dglSpanClip_fn fnClip, void *pvClipArg)
dglInt32_t * dgl_node_t_first_V2(dglNodeTraverser_s *pT)
dglInt32_t * dgl_edge_t_next_V2(dglEdgeTraverser_s *pT)
int dgl_edgeset_t_initialize_V2(dglGraph_s *pGraph, dglEdgesetTraverser_s *pTraverser, dglInt32_t *pnEdgeset)
#define DGL_NODE_ID_v2(p)
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)
#define DGL_NODEBUFFER_SHIFT_v2(pgrp, o)
int dgl_flatten_V2(dglGraph_s *pgraph)
int dgl_node_t_initialize_V2(dglGraph_s *pGraph, dglNodeTraverser_s *pT)
#define DGL_EDGE_SIZEOF_v2(lattr)
int dgl_edge_t_initialize_V2(dglGraph_s *pGraph, dglEdgeTraverser_s *pTraverser, dglEdgePrioritizer_s *pEP)
#define DGL_EDGE_TAILNODE_OFFSET_v2(p)
#define DGL_EDGE_ATTR_PTR_v2(p)
#define DGL_NODE_SIZEOF_v2(nattr)
void dgl_sp_cache_release_V2(dglGraph_s *pgraph, dglSPCache_s *pCache)
int dgl_unflatten_V2(dglGraph_s *pgraph)
dglInt32_t * dgl_getnode_inedgeset_V2(dglGraph_s *pgraph, dglInt32_t *pnode)
#define DGL_EDGESET_EDGECOUNT_v2(p)
dglInt32_t * dgl_edgeset_t_first_V2(dglEdgesetTraverser_s *pTraverser)
dglInt32_t * dgl_edge_t_first_V2(dglEdgeTraverser_s *pT)
#define DGL_NODE_ATTR_PTR_v2(p)
#define DGL_EDGE_COST_v2(p)
int dgl_del_edge_V2(dglGraph_s *pgraph, dglInt32_t nId)
dglInt32_t * dgl_edgeset_t_next_V2(dglEdgesetTraverser_s *pTraverser)
int dgl_del_node_V2(dglGraph_s *pgraph, dglInt32_t nId)
#define DGL_EDGE_HEADNODE_OFFSET_v2(p)
int dgl_sp_cache_initialize_V2(dglGraph_s *pgraph, dglSPCache_s *pCache, dglInt32_t nStart)
void dgl_node_t_release_V2(dglNodeTraverser_s *pT)
dglInt32_t * dgl_get_node_V2(dglGraph_s *pgraph, dglInt32_t nId)
int dgl_add_node_V2(dglGraph_s *pgraph, dglInt32_t nId, void *pvNodeAttr, dglInt32_t nFlags)
dglInt32_t * dgl_get_edge_V2(dglGraph_s *pgraph, dglInt32_t nId)
#define DGL_EDGE_ID_v2(p)
dglInt32_t * dgl_node_t_find_V2(dglNodeTraverser_s *pT, dglInt32_t nId)
dglInt32_t * dgl_getnode_outedgeset_V2(dglGraph_s *pgraph, dglInt32_t *pnode)
#define DGL_NODE_STATUS_v2(p)
void dgl_edge_t_release_V2(dglEdgeTraverser_s *pTraverser)
dglInt32_t * dgl_node_t_next_V2(dglNodeTraverser_s *pT)
void dgl_swapInt64Bytes(dglInt64_t *pn)
void dgl_swapInt32Bytes(dglInt32_t *pn)
dglEdgePrioritizer_s edgePrioritizer
dglInt32_t aOpaqueSet[16]
dglNodePrioritizer_s nodePrioritizer
void dglTreeNodeCancel(void *pvNode, void *pvParam UNUSED)
int dglTreeNodeCompare(const void *pvNodeA, const void *pvNodeB, void *pvParam UNUSED)
void * dglTreeGetAllocator(void)
dglEdgePrioritizer_s * dglGet_EdgePrioritizer(dglGraph_s *pGraph)
dglInt32_t * dglGetEdge(dglGraph_s *pGraph, dglInt32_t nEdgeId)
void dglSet_Family(dglGraph_s *pgraph, dglInt32_t nFamily)
int dglRead(dglGraph_s *pGraph, int fd)
int dglGet_NodeAttrSize(dglGraph_s *pgraph)
dglInt32_t dglGet_Family(dglGraph_s *pgraph)
int dglWriteChunk(dglIOContext_s *pIO, dglWriteChunk_fn pfn, void *pv)
dglInt32_t * dglNode_T_First(dglNodeTraverser_s *pT)
dglInt32_t * dglNodeGet_OutEdgeset(dglGraph_s *pGraph, dglInt32_t *pnNode)
void dglSet_Version(dglGraph_s *pgraph, int nVersion)
#define __CIO_W_NODEBUFFER
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)
int dglGet_EdgeAttrSize(dglGraph_s *pgraph)
#define __CIO_R_EDGEBUFFER
dglInt32_t dglNodeGet_Status(dglGraph_s *pGraph, dglInt32_t *pnNode)
int dglReadChunk(dglIOContext_s *pIO, dglByte_t *pbChunk, int cbChunk)
int dglErrno(dglGraph_s *pgraph)
int dglAddEdge(dglGraph_s *pGraph, dglInt32_t nHead, dglInt32_t nTail, dglInt32_t nCost, dglInt32_t nEdge)
int dglEdgeset_T_Initialize(dglEdgesetTraverser_s *pT, dglGraph_s *pGraph, dglInt32_t *pnEdgeset)
int dglShortestPath(dglGraph_s *pGraph, dglSPReport_s **ppReport, dglInt32_t nStart, dglInt32_t nDestination, dglSPClip_fn fnClip, void *pvClipArg, dglSPCache_s *pCache)
void dglIOContextRelease(dglIOContext_s *pIO UNUSED)
void dglSet_Cost(dglGraph_s *pgraph, dglInt64_t nnCost)
char * dglStrerror(dglGraph_s *pgraph)
int dglNode_T_Initialize(dglNodeTraverser_s *pT, dglGraph_s *pGraph)
dglInt32_t dglEdgeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnEdge)
void dglSet_Options(dglGraph_s *pgraph, dglInt32_t nOptions)
int dglDepthSpanning(dglGraph_s *pgraphInput, dglGraph_s *pgraphOutput, dglInt32_t nVertexNode, dglSpanClip_fn fnClip, void *pvClipArg)
void dglNodeSet_Attr(dglGraph_s *pGraph, dglInt32_t *pnNode, dglInt32_t *pnAttr)
dglInt32_t * dglEdgeset_T_Next(dglEdgesetTraverser_s *pT)
int dglRelease(dglGraph_s *pGraph)
dglInt32_t * dglEdgeGet_Attr(dglGraph_s *pGraph, dglInt32_t *pnEdge)
dglInt32_t * dglEdgeGet_Tail(dglGraph_s *pGraph, dglInt32_t *pnEdge)
dglInt32_t * dglEdgeGet_Head(dglGraph_s *pGraph, dglInt32_t *pnEdge)
dglInt32_t * dglEdge_T_Next(dglEdgeTraverser_s *pT)
int dglEdgeSet_Attr(dglGraph_s *pGraph, dglInt32_t *pnAttr, dglInt32_t *pnEdge)
dglNodePrioritizer_s * dglGet_NodePrioritizer(dglGraph_s *pGraph)
#define __CIO_W_EDGEBUFFER
int dglInitialize(dglGraph_s *pGraph, dglByte_t Version, dglInt32_t NodeAttrSize, dglInt32_t EdgeAttrSize, dglInt32_t *pOpaqueSet)
int dglGet_Endianess(dglGraph_s *pgraph)
int dglGet_EdgeSize(dglGraph_s *pgraph)
int dglGet_EdgeCount(dglGraph_s *pgraph)
dglInt32_t * dglNodeGet_Attr(dglGraph_s *pGraph, dglInt32_t *pnNode)
void dglFreeSPReport(dglGraph_s *pgraph UNUSED, dglSPReport_s *pSPReport)
int dglMinimumSpanning(dglGraph_s *pgraphInput, dglGraph_s *pgraphOutput, dglInt32_t nVertexNode, dglSpanClip_fn fnClip, void *pvClipArg)
int dglShortestDistance(dglGraph_s *pGraph, dglInt32_t *pnDistance, dglInt32_t nStart, dglInt32_t nDestination, dglSPClip_fn fnClip, void *pvClipArg, dglSPCache_s *pCache)
int dglNodeGet_OutDegree(dglGraph_s *pGraph, dglInt32_t *pnNode)
int dglEdge_T_Initialize(dglEdgeTraverser_s *pT, dglGraph_s *pGraph, dglEdgePrioritizer_s *pEdgePrioritizer)
int dglDelEdge(dglGraph_s *pGraph, dglInt32_t nEdgeId)
int dglNodeGet_Valence(dglGraph_s *pGraph, dglInt32_t *pnNode)
int dglNodeGet_InDegree(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglInt32_t * dglNode_T_Next(dglNodeTraverser_s *pT)
int dglInitializeSPCache(dglGraph_s *pGraph, dglSPCache_s *pCache)
int dglGet_NodeCount(dglGraph_s *pgraph)
int dglGet_Version(dglGraph_s *pgraph)
int dglWrite(dglGraph_s *pGraph, int fd)
void dglEdgeset_T_Release(dglEdgesetTraverser_s *pT UNUSED)
int dglGet_AloneNodeCount(dglGraph_s *pgraph)
int dglFlatten(dglGraph_s *pGraph)
dglInt32_t * dglNodeGet_InEdgeset(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglInt32_t dglEdgeGet_Cost(dglGraph_s *pGraph, dglInt32_t *pnEdge)
dglInt32_t * dglEdgeset_T_First(dglEdgesetTraverser_s *pT)
int dglDepthComponents(dglGraph_s *pgraphInput, dglGraph_s *pgraphComponents, int cgraphComponents, dglSpanClip_fn fnClip, void *pvClipArg)
void dglNode_T_Release(dglNodeTraverser_s *pT)
dglInt32_t * dglEdge_T_First(dglEdgeTraverser_s *pT)
dglInt32_t dglEdgesetGet_EdgeCount(dglGraph_s *pGraph, dglInt32_t *pnEdgeset)
int dglUnflatten(dglGraph_s *pGraph)
dglInt32_t dglGet_Options(dglGraph_s *pgraph)
int dglGet_NodeSize(dglGraph_s *pgraph)
void dglEdge_T_Release(dglEdgeTraverser_s *pT)
int dglGet_TailNodeCount(dglGraph_s *pgraph)
dglInt32_t * dglGet_Opaque(dglGraph_s *pgraph)
void dglReleaseSPCache(dglGraph_s *pGraph, dglSPCache_s *pCache)
void dglSet_Opaque(dglGraph_s *pgraph, dglInt32_t *pOpaque)
int dglIOContextInitialize(dglGraph_s *pG, dglIOContext_s *pIO)
dglInt32_t * dglNode_T_Find(dglNodeTraverser_s *pT, dglInt32_t nNodeId)
void dglResetStats(dglGraph_s *pgraph UNUSED)
#define __CIO_R_NODEBUFFER
int dglDelNode(dglGraph_s *pGraph, dglInt32_t nNodeId)
dglInt64_t dglGet_Cost(dglGraph_s *pgraph)
dglInt32_t dglNodeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnNode)
int dglGet_HeadNodeCount(dglGraph_s *pgraph)
int dglGet_State(dglGraph_s *pgraph)
dglInt32_t * dglGetNode(dglGraph_s *pGraph, dglInt32_t nNodeId)
int dglAddNode(dglGraph_s *pGraph, dglInt32_t nNodeId, void *pvNodeAttr, dglInt32_t nFlags)