1 char rcsid_map[] = "$Id$";
10 static void growMapping ARGS((Mapping));
11 static int hash ARGS((Item_Set, int));
14 newMapping(size) int size;
18 m = (Mapping) zalloc(sizeof(struct mapping));
22 m->hash = (List*) zalloc(size * sizeof(List));
24 m->max_size = STATES_INCR;
25 m->set = (Item_Set*) zalloc(m->max_size * sizeof(Item_Set));
32 growMapping(m) Mapping m;
36 m->max_size += STATES_INCR;
37 tmp = (Item_Set*) zalloc(m->max_size * sizeof(Item_Set));
38 memcpy(tmp, m->set, m->count * sizeof(Item_Set));
44 hash(ts, mod) Item_Set ts; int mod;
46 register Item *p = ts->virgin;
48 register Relevant r = ts->relevant;
56 for (; (nt = *r) != 0; r++) {
57 v ^= ((int)p[nt].rule) + (PRINCIPLECOST(p[nt].delta)<<4);
65 encode(m, ts, new) Mapping m; Item_Set ts; int *new;
72 assert(m->count <= m->max_size);
74 if (grammarNts && errorState && m == globalMap) {
79 for (l = grammarNts; l; l = l->next) {
83 if (ts->virgin[s->u.nt->num].rule) {
95 h = hash(ts, m->hash_size);
96 for (l = m->hash[h]; l; l = l->next) {
97 Item_Set s = (Item_Set) l->x;
98 if (ts->op == s->op && equivSet(ts, s)) {
103 if (m->count >= m->max_size) {
106 assert(m->count < m->max_size);
107 m->set[m->count] = ts;
108 ts->num = m->count++;
110 m->hash[h] = newList(ts, m->hash[h]);
115 decode(m, t) Mapping m; ItemSetNum t;
119 assert(m->count < m->max_size);
120 assert(t < m->count);
126 dumpMapping(m) Mapping m;
130 printf("BEGIN Mapping: Size=%d\n", m->count);
131 for (i = 0; i < m->count; i++) {
132 dumpItem_Set(m->set[i]);
134 printf("END Mapping\n");