-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraph.h
93 lines (66 loc) · 1.58 KB
/
graph.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef GRAPH_H
#define GRAPH_H
#include "list.h"
#include "hash.h"
typedef void (*data_dtor_func_t)(void *);
typedef struct _graph_vertex_t
{
void *data;
char *key;
list_t *edges;
struct _graph_t *container;
}graph_vertex_t;
typedef int graph_edge_weight_t;
typedef struct _graph_edge_t
{
struct _graph_vertex_t *src;
struct _graph_vertex_t *dest;
graph_edge_weight_t weight;
}graph_edge_t;
typedef struct _graph_t
{
ht_t *vertices;
data_dtor_func_t vertex_data_dtor;
size_t size;
}graph_t;
graph_vertex_t *
graph_vertex_create(void *data, char * key);
void
graph_vertex_destroy(graph_vertex_t *v);
graph_edge_t *
graph_edge_create(graph_vertex_t *src, graph_vertex_t *dest, graph_edge_weight_t weight);
void
graph_edge_destroy(graph_edge_t *e);
graph_t *
graph_create(data_dtor_func_t dtor);
void
graph_destroy(graph_t *g);
int
graph_add_vertex(graph_t *g, graph_vertex_t *v, int flags);
int
graph_has_vertex(graph_t *g, char *key);
graph_vertex_t *
graph_get_vertex(graph_t *g, char *key);
const list_t *
graph_get_all_vertices(graph_t *g);
int
graph_remove_vertex(graph_t *g, char *key);
int
graph_remove_all_vertices(graph_t *g);
int
graph_add_edge(graph_t *g, graph_edge_t *e);
int
graph_has_edge(graph_t *g, char *src, char *dest);
graph_edge_t *
graph_get_edge(graph_t *g, char *src, char *dest);
const list_t *
graph_vertex_get_all_edges(graph_t *g, char *key);
const list_t *
graph_vertex_edges_of(graph_t *g, char *key);
const list_t *
graph_get_all_edges(graph_t *g);
int
graph_remove_edge(graph_t *g, char *src, char *dest);
int
graph_remove_all_edges(graph_t *g);
#endif