1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2009 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 static DFASet mk_DFASetElement (DFASetType st, int n);
32 DFASetType mk_DFASetType (int chunk)
36 assert (chunk > 8 && chunk < 8000);
38 st = (DFASetType) imalloc (sizeof(*st));
41 st->alloclist = st->freelist = NULL;
47 int inf_DFASetType (DFASetType st, long *used, long *allocated)
53 for (s = st->alloclist; s; s = s->next)
54 *allocated += st->chunk;
55 return sizeof (DFASetElement);
58 DFASetType rm_DFASetType (DFASetType st)
61 for (s = st->alloclist; (s1 = s);)
70 DFASet mk_DFASet (DFASetType st)
76 static DFASet mk_DFASetElement (DFASetType st, int n)
82 assert (st->chunk > 8);
85 s = (DFASet) imalloc (sizeof(*s) * (1+st->chunk));
87 s->next = st->alloclist;
90 for (i=st->chunk; --i > 0; s++)
96 st->freelist = s->next;
102 static void rm_DFASetElement (DFASetType st, DFASetElement *p)
105 assert (st->used > 0);
106 p->next = st->freelist;
112 DFASet rm_DFASet (DFASetType st, DFASet s)
124 s->next = st->freelist;
127 assert (st->used >= 0);
132 DFASet add_DFASet (DFASetType st, DFASet s, int n)
135 DFASet p = &dummy, snew;
137 while (p->next && p->next->value < n)
140 if (!(p->next && p->next->value == n))
142 snew = mk_DFASetElement (st, n);
143 snew->next = p->next;
149 DFASet union_DFASet (DFASetType st, DFASet s1, DFASet s2)
155 for (p = &dummy; s1 && s2;)
156 if (s1->value < s2->value)
161 else if (s1->value > s2->value)
163 p = p->next = mk_DFASetElement (st, s2->value);
178 p = p->next = mk_DFASetElement (st, s2->value);
186 DFASet cp_DFASet (DFASetType st, DFASet s)
188 return merge_DFASet (st, s, NULL);
191 DFASet merge_DFASet (DFASetType st, DFASet s1, DFASet s2)
196 for (p = &dummy; s1 && s2; p = p->next)
197 if (s1->value < s2->value)
199 p->next = mk_DFASetElement (st, s1->value);
202 else if (s1->value > s2->value)
204 p->next = mk_DFASetElement (st, s2->value);
209 p->next = mk_DFASetElement (st, s1->value);
217 p = p->next = mk_DFASetElement (st, s1->value);
224 void pr_DFASet (DFASetType st, DFASet s)
229 printf (" %d", s->value);
235 unsigned hash_DFASet (DFASetType st, DFASet s)
246 int eq_DFASet (DFASetType st, DFASet s1, DFASet s2)
248 for (; s1 && s2; s1=s1->next, s2=s2->next)
249 if (s1->value != s2->value)
256 * c-file-style: "Stroustrup"
257 * indent-tabs-mode: nil
259 * vim: shiftwidth=4 tabstop=8 expandtab