INGOR
Loading...
Searching...
No Matches
ytDLGraph.h
1/*
2 math/ytDLGraph.{h,c} : Graph by Doubly Linked List
3 Copyright (C) 2018, Yoshinori Tamada <tamada A T ytlab.jp>
4 All rights reserved.
5
6 See LICENSE.txt for details of the licensing agreement.
7*/
8
9#ifndef __YTLIB_DL_GRAPH_H
10#define __YTLIB_DL_GRAPH_H
11
12#include "util/ytIntArray.h"
13
14#ifdef DOXY
17#define ytDLGraph_NULL
18#else
19#define ytDLGraph_NULL ((size_t) -1)
20#endif /* DOXY */
21
22typedef struct ytDLGraph_Edge_t {
23 int pa;
24 int ch;
25
26 size_t pa_next;
27 size_t ch_next;
28
29 size_t pa_prev;
30 size_t ch_prev;
32
45typedef struct {
46#ifdef DOXY
47private:
48#endif
49 ytGraph super;
50
51 int nodes;
52 int edges;
53 size_t buff_size;
54 ytDLGraph_Edge * ptr; /* First 'nodes' pointers are used to
55 maintain parents and children for nodes */
56
57 /*
58 'pa_last' & 'ch_last' maintain the last edge for each node.
59 ''pa_last[v]' ('ch_last[v]') points to the position in 'ptr'
60 of the last parent (child) node for 'v'.
61 */
62 size_t * pa_last;
63 size_t * ch_last;
64
65 size_t last;
66
67 /* degrees of nodes. */
68 int * in_degree;
69 int * out_degree;
70
71} ytDLGraph;
72
73ytDLGraph * ytDLGraph_new(int nodes);
74void ytDLGraph_resize_buff(ytDLGraph * this, size_t size);
75void ytDLGraph_delete(void * this);
76void ytDLGraph_copy(ytDLGraph * this, const ytDLGraph * src);
77void ytDLGraph_clear(ytDLGraph * this);
78
79void ytDLGraph_status(ytDLGraph * this, FILE * fp);
80void ytDLGraph_fill(ytDLGraph * this);
81
82size_t ytDLGraph_numNodes(const ytDLGraph * this);
83size_t ytDLGraph_numEdges(const ytDLGraph * this);
84
85size_t ytDLGraph_add_edge(ytDLGraph * this, int u, int v);
86int ytDLGraph_check_edge(ytDLGraph * this, int u, int v);
87size_t ytDLGraph_check_edge_index(ytDLGraph * this, int u, int v);
88size_t ytDLGraph_check_edge_id(ytDLGraph * this, int u, int v);
89void ytDLGraph_remove_edge_id(ytDLGraph * this, size_t id);
90void ytDLGraph_remove_edge(ytDLGraph * this, int u, int v);
91
92void ytDLGraph_copyGraph(ytDLGraph * this, const ytGraph * src);
93void ytDLGraph_addGraph(ytDLGraph * this, const ytGraph * src);
94
95size_t ytDLGraph_first_parent_id(ytDLGraph * this, int v);
96size_t ytDLGraph_first_child_id(ytDLGraph * this, int v);
97size_t ytDLGraph_next_parent_id(ytDLGraph * this, size_t id);
98size_t ytDLGraph_next_child_id(ytDLGraph * this, size_t id);
99size_t ytDLGraph_parent_next(ytDLGraph * this, size_t id, int * pa);
100size_t ytDLGraph_child_next(ytDLGraph * this, size_t id, int * ch);
101
102int ytDLGraph_get_parent(ytDLGraph * this, size_t id);
103int ytDLGraph_get_child(ytDLGraph * this, size_t id);
104void ytDLGraph_get_edge(ytDLGraph * this, size_t id, int * u, int * v);
105void ytDLGraph_get_edge_index(const ytDLGraph * this, size_t index, int * u, int * v);
106
107size_t ytDLGraph_first_edge(ytDLGraph * this);
108size_t ytDLGraph_next_edge(ytDLGraph * this, size_t id);
109
110size_t ytDLGraph_parents(ytDLGraph * this, int v, ytIntArray * ar);
111
112
113int ytDLGraph_check_cyclic(ytDLGraph * this, int u, int v);
114
115size_t ytDLGraph_num_parents(ytDLGraph * this, int v);
116size_t ytDLGraph_num_children(ytDLGraph * this, int v);
117size_t ytDLGraph_degree(ytDLGraph * this, int v);
118
119void ytDLGraph_DAG_fsc_th(ytDLGraph * g, ytFloatArray * sc, float th,
120 ytDLGraph * dag);
121
122void ytDLGraph_print_all_parents(ytDLGraph * this, FILE * fp);
123void ytDLGraph_print_parents(ytDLGraph * this, int j, FILE * fp);
124void ytDLGraph_print_children(ytDLGraph * this, int j, FILE * fp);
125
126#endif /* __YTLIB_DL_GRAPH_H */
Interface class for handling graph structure.
Expandable array.
Definition ytDLGraph.h:22
Graph structure for efficient parents and children handling.
Definition ytDLGraph.h:45