INGOR
ytGraph.h
1/*
2 math/ytGraph.{h,c} : Graph
3 Copyright (C) 2018, Yoshinori Tamada <tamada A T ytlab.jp>
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12
13 * Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in
15 the documentation and/or other materials provided with the
16 distribution.
17
18 * Neither the name of Kyoto University nor the names of its
19 contributors may be used to endorse or promote products derived
20 from this software without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 POSSIBILITY OF SUCH DAMAGE.
34*/
35
36#ifndef __YTLIB_GRAPH_H
37#define __YTLIB_GRAPH_H
38
39#include "lang/ytObject.h"
40#include <stdio.h>
41#ifdef USE_MPI
42#include <mpi.h>
43#endif
44
51typedef struct ytGraph_t ytGraph;
52
53typedef struct {
54 int src;
55 int dst;
56 int k;
58
59typedef struct ytGraph_t {
60 ytObject obj;
61
62 void (* setOrder)(ytGraph * g, int order);
63 void (* delete)(ytGraph * g);
64 ytGraph * (*clone)(const ytGraph * g);
65 int (* numNodes)(const ytGraph * g);
66 int (* numEdges)(const ytGraph * g);
67 int (* checkEdge)(const ytGraph * g, int u, int v);
68 int (* degree)(const ytGraph * g, int u);
69 int (* numParents)(const ytGraph * g, int u);
70 int (* numChildren)(const ytGraph * g, int u);
71 void (* addEdge)(ytGraph * g, int u, int v);
72
73 const int * (* getParents)(const ytGraph * g, int u);
74 const int * (* getChildren)(const ytGraph *g, int u);
75 void (* removeEdge)(ytGraph * g, int u, int v);
76 void (* clear)(ytGraph * g);
77
78 void (* print)(const ytGraph * g, FILE * fp);
79
80 ytGraphEdgeIter * (*edgeIter)(const ytGraph * g);
81 void (*edgeIterNext)(const ytGraph * g, ytGraphEdgeIter * iter);
82
83#ifdef USE_MPI
84 void (* MPI_Bcast)(ytGraph ** pg, int root, MPI_Comm comm);
85#endif
86} ytGraph;
87
88#define ytGraph_setOrder(g,n) g->setOrder(g,n)
89#define ytGraph_delete(g) g->delete(g)
90#define ytGraph_clone(g) g->clone(g)
91#define ytGraph_degree(g,u) g->degree(g,u)
92#define ytGraph_addEdge(g,u,v) g->addEdge(g,u,v)
93#define ytGraph_clear(g) g->clear(g)
94#ifdef DOXY
98
102
106int ytGraph_checkEdge(const ytGraph * g, int u, int v);
107
120const int * ytGraph_getParents(const ytGraph * g, int u);
121
124int ytGraph_numParents(const ytGraph * g, int u);
125
137const int * ytGraph_getChildren(const ytGraph * g, int u);
138
143int ytGraph_numChildren(const ytGraph * g, int u);
144
147void ytGraph_removeEdge(ytGraph * g, int u, int v);
148
151void ytGraph_print(const ytGraph * g, FILE * fp);
152
156
160
163void ytGraph_MPI_Bcast(ytGraph ** pg, int root, MPI_Comm comm);
164
165#else
166#define ytGraph_numNodes(g) g->numNodes(g)
167#define ytGraph_numEdges(g) g->numEdges(g)
168#define ytGraph_checkEdge(g,u,v) g->checkEdge(g,u,v)
169#define ytGraph_getParents(g,u) g->getParents(g,u)
170#define ytGraph_numParents(g,u) g->numParents(g,u)
171#define ytGraph_getChildren(g,u) g->getChildren(g,u)
172#define ytGraph_numChildren(g,u) g->numChildren(g,u)
173#define ytGraph_removeEdge(g,u,v) g->removeEdge(g,u,v)
174#define ytGraph_print(g,fp) g->print(g,fp)
175#define ytGraph_edgeIter(g) g->edgeIter(g)
176#define ytGraph_edgeIterNext(g,i) g->edgeIterNext(g,i)
177#ifdef USE_MPI
178#define ytGraph_MPI_Bcast(pg,r,c) (*pg)->MPI_Bcast(pg,r,c)
179#endif
180#endif /* DOXY */
181
182size_t ytGraph_size(const ytGraph * this);
183ytByte * ytGraph_serialize(const ytGraph * this, ytByte ** pptr);
184ytByte * ytGraph_serializeI(const ytObject * obj, ytByte ** pptr);
185ytGraph * ytGraph_deserialize(ytByte ** const pptr);
186
187#endif /* __YTLIB_GRAPH_H */
Interface class for handling graph structure.
int ytGraph_checkEdge(const ytGraph *g, int u, int v)
Checks if the specified edge exists.
int ytGraph_numNodes(const ytGraph *g)
Returns the number of nodes in the graph.
void ytGraph_edgeIterNext(const ytGraph *g, ytGraphEdgeIter *i)
Obtains the next edge.
void ytGraph_MPI_Bcast(ytGraph **pg, int root, MPI_Comm comm)
[MPI] Broadcasts the graph to all the processes.
void ytGraph_removeEdge(ytGraph *g, int u, int v)
Removes the specified edge.
int ytGraph_numChildren(const ytGraph *g, int u)
Returns the number of children.
int ytGraph_numParents(const ytGraph *g, int u)
Return the number of parents for the specified node.
const int * ytGraph_getChildren(const ytGraph *g, int u)
Returns the integer array that contains the indices of children.
int ytGraph_numEdges(const ytGraph *g)
Returns the number of edges in the graph.
ytGraphEdgeIter * ytGraph_edgeIter(const ytGrpah *g)
Returns the ytGraphEdgeIter instance representing the first edge.
const int * ytGraph_getParents(const ytGraph *g, int u)
Returns the integer array that contains the indices of parents of the specifiec node.
The basis class.
Definition: ytGraph.h:59
Definition: ytGraph.h:53