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
|
#include "config.h"
#include <assert.h>
#include <ccan/agar/agar.h>
#include <ccan/container_of/container_of.h>
#include <ccan/ptrint/ptrint.h>
#include "simple-graphr.h"
static const void *parallel_first_edge_r(const struct agar_graph *gr,
const void *nr)
{
const struct parallel_graphr *pgr
= container_of(gr, struct parallel_graphr, gr);
if (ptr2int(nr) != 1) {
assert(ptr2int(nr) == 2);
return NULL;
}
if (pgr->nlinks)
return int2ptr(1);
else
return NULL;
}
static const void *parallel_next_edge_r(const struct agar_graph *gr,
const void *nr, const void *edge)
{
const struct parallel_graphr *pgr
= container_of(gr, struct parallel_graphr, gr);
int index = ptr2int(edge);
if (ptr2int(nr) != 1) {
assert(ptr2int(nr) == 2);
return NULL;
}
if (index < pgr->nlinks)
return int2ptr(index + 1);
else
return NULL;
}
static int parallel_edge_info_r(const struct agar_graph *gr,
const void *nr, const void *edge,
struct agar_edge_info *eir)
{
assert(ptr2int(nr) == 1);
eir->to = int2ptr(2);
return 0;
}
void parallel_graphr_init(struct parallel_graphr *pgr, int nlinks)
{
pgr->nlinks = nlinks;
agar_init_graph(&pgr->gr, parallel_first_edge_r, parallel_next_edge_r,
parallel_edge_info_r);
}
|