13 struct tab
*tab_alloc(int sz
)
15 struct tab
*tab
= malloc(sizeof(*tab
));
17 memset(tab
, 0, sizeof(*tab
));
18 tab
->keys
= malloc(sz
* sizeof(tab
->keys
[0]));
19 tab
->vals
= malloc(sz
* sizeof(tab
->vals
[0]));
20 tab
->next
= malloc(sz
* sizeof(tab
->next
[0]));
21 for (i
= 0; i
< 256; i
++)
26 void tab_free(struct tab
*tab
)
34 void tab_put(struct tab
*tab
, char *k
, void *v
)
36 tab
->keys
[tab
->n
] = k
;
37 tab
->vals
[tab
->n
] = v
;
38 tab
->next
[tab
->n
] = tab
->head
[(unsigned char) k
[0]];
39 tab
->head
[(unsigned char) k
[0]] = tab
->n
;
43 void *tab_get(struct tab
*tab
, char *k
)
45 int i
= tab
->head
[(unsigned char) k
[0]];
47 if (k
[1] == tab
->keys
[i
][1] && !strcmp(k
, tab
->keys
[i
]))