2 * Copyright (C) 1994-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.5 1999-02-02 14:50:04 adam
8 * Updated WIN32 code specific sections. Changed header.
10 * Revision 1.4 1996/10/29 13:57:20 adam
11 * Include of zebrautl.h instead of alexutil.h.
13 * Revision 1.3 1995/09/04 12:33:25 adam
14 * Various cleanup. YAZ util used instead.
16 * Revision 1.2 1995/01/24 16:00:21 adam
17 * Added -ansi to CFLAGS.
18 * Some changes to the dfa module.
20 * Revision 1.1 1994/09/26 10:16:53 adam
21 * First version of dfa module in alex. This version uses yacc to parse
22 * regular expressions. This should be hand-made instead.
35 #define GET_BIT(s,m) (s[(m)/(sizeof(BSetWord)*8)]&(1<<(m&(sizeof(BSetWord)*8-1))))
36 #define SET_BIT(s,m) (s[(m)/(sizeof(BSetWord)*8)]|=(1<<(m&(sizeof(BSetWord)*8-1))))
38 BSetHandle *mk_BSetHandle (int size, int chunk)
40 int wsize = 1+size/(sizeof(BSetWord)*8);
45 sh = (BSetHandle *) imalloc (sizeof(BSetHandle) +
46 chunk*sizeof(BSetWord)*wsize);
50 sh->chunk = chunk * wsize;
56 void rm_BSetHandle (BSetHandle **shp)
71 int inf_BSetHandle (BSetHandle *sh, long *used, long *allocated)
82 *allocated += sh->chunk;
83 } while ((sh = sh->setchain));
87 BSet mk_BSet (BSetHandle **shp)
96 if ((off + sh->wsize) > sh->chunk)
98 sh1 = (BSetHandle *) imalloc (sizeof(BSetHandle) +
99 sh->chunk*sizeof(BSetWord));
100 sh1->size = sh->size;
101 sh1->wsize = sh->wsize;
102 sh1->chunk = sh->chunk;
103 off = sh1->offset = 0;
107 sh->offset = off + sh->wsize;
108 return sh->setarray + off;
111 void add_BSet (BSetHandle *sh, BSet dst, unsigned member)
115 assert (member <= sh->size);
116 SET_BIT(dst, member);
119 unsigned test_BSet (BSetHandle *sh, BSet src, unsigned member)
123 assert (member <= sh->size);
124 return GET_BIT (src , member) != 0;
127 BSet cp_BSet (BSetHandle *sh, BSet dst, BSet src)
132 memcpy (dst, src, sh->wsize * sizeof(BSetWord));
136 void res_BSet (BSetHandle *sh, BSet dst)
139 memset (dst, 0, sh->wsize * sizeof(BSetWord));
142 void union_BSet (BSetHandle *sh, BSet dst, BSet src)
148 for (i=sh->wsize; --i >= 0;)
152 unsigned hash_BSet (BSetHandle *sh, BSet src)
158 for (i=sh->wsize; --i >= 0;)
163 void com_BSet (BSetHandle *sh, BSet dst)
168 for (i=sh->wsize; --i >= 0; dst++)
172 int eq_BSet (BSetHandle *sh, BSet dst, BSet src)
178 for (i=sh->wsize; --i >= 0;)
179 if (*dst++ != *src++)
184 int trav_BSet (BSetHandle *sh, BSet src, unsigned member)
186 int i = sh->size - member;
187 BSetWord *sw = src+member/(sizeof(BSetWord)*8);
188 unsigned b = member & (sizeof(BSetWord)*8-1);
190 if (b == 0 && *sw == 0)
192 member += sizeof(BSetWord)*8;
194 i -= sizeof(BSetWord)*8;
196 else if (*sw & (1<<b))
202 if (++b == sizeof(BSetWord)*8)
211 int travi_BSet (BSetHandle *sh, BSet src, unsigned member)
213 int i = sh->size - member;
214 BSetWord *sw = src+member/(sizeof(BSetWord)*8);
215 unsigned b = member & (sizeof(BSetWord)*8-1);
217 if (b == 0 && *sw == (BSetWord) ~ 0)
219 member += sizeof(BSetWord)*8;
221 i -= sizeof(BSetWord)*8;
223 else if ((*sw & (1<<b)) == 0)
229 if (++b == sizeof(BSetWord)*8)
239 void pr_BSet (BSetHandle *sh, BSet src)
244 for (i=0; (i=trav_BSet(sh,src,i)) != -1; i++)
249 void pr_charBSet (BSetHandle *sh, BSet src, void (*f) (int))
255 i = trav_BSet (sh, src, 0);
262 i1 = trav_BSet (sh, src, ++i);
265 while ((i1=trav_BSet (sh, src, ++i)) == i)