-
Notifications
You must be signed in to change notification settings - Fork 0
/
setset.c
138 lines (117 loc) · 2.17 KB
/
setset.c
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
*
* setset.h
*
* set of intset
*
* 07/16/01
*
*/
#include "mem.h"
#include "intset.h"
#include "setset.h"
#include "debug.h"
/*
* 新規
*/
Setsetp NewSetSet ()
{
Setsetp p = (Setsetp) getmem (sizeof (_Setset));
p->nsets = 0;
return p;
}
/*
* 解放
*/
void SSrelease (Setsetp ss)
{
int i;
for (i = 0; i < ss->nsets; i++)
memfree ((char*)ss->sets[i]);
memfree ((char*)ss);
}
/*
* セットを検索する。インデックスを返す。
* 見つからない場合は-1を返す。
*/
int SSsearch (Setsetp ss, Intsetp is)
{
int i;
for (i = 0; i < ss->nsets; i++) {
if (ISisEqual (ss->sets[i], is))
return i;
}
return -1; /* not found */
}
/*
* セットを追加する。追加したインデックスを返す。
*/
int SSadd (Setsetp ss, Intsetp is)
{
if (is->maximum == 0) {
/* never add null set */
return -1;
}
ss->sets[ss->nsets] = is;
ss->nsets++;
return ss->nsets-1;
}
/*
* インデックスのセットを返す。
*/
Intsetp SSget (Setsetp ss, int index) {
if (ss->nsets <= index)
_fatal ("SSget() index out of range.");
return ss->sets[index];
}
/*
*
*/
int SSgetNumSets (Setsetp ss) { return ss->nsets; }
#if 0
/*
*
*/
Intsetp* SSgetSets (Setsetp ss) { return ss->sets; }
int SSgetSymbol (Setsetp ss, int index) {
if (ss->nsets <= index)
_fatal ("SSgetSymbol() index out of range.");
return ss->onsymbols[index];
}
/*
* returns new set's index if it doesn't exist and added.
* -1 otherwise.
*/
int SSaddSetIfNotExist (Setsetp ss, Intsetp is, int onsymbol)
{
int i, r;
if (is->maximum == 0) {
/* never add null set */
return -1;
}
if (ss->nsets == 0) {
/* if no sets now */
ss->sets[ss->nsets] = is;
ss->onsymbols[ss->nsets] = onsymbol;
ss->nsets++;
r = ss->nsets-1;
}
else {
int eq = 0;
for (i = 0; i < ss->nsets; i++) {
if (ISisEqual (ss->sets[i], is)) {
eq++;
ss->onsymbols[i] = onsymbol;
}
}
if (eq == 0) {
/* no same set */
ss->sets[ss->nsets] = is;
ss->onsymbols[ss->nsets] = onsymbol;
ss->nsets++;
r = ss->nsets-1;
}
}
return r; /* already there */
}
#endif