- << endl;
- return -1;
- } else
- return t->table->defkey(seq, action, idx+1);
- }
- }
-
- // --- extend list if necessary -------------------------------------
-
- if(tsize % KB_PREALLOC == 0) {
- kb_key *nt = new kb_key[tsize+KB_PREALLOC];
- // Set to 0 as table is used uninitialised later (thornley)
- nt[tsize].table = 0;
- memcpy(nt, tab, tsize*sizeof(kb_key));
- *ptab = nt;
- delete[] tab;
- tab = nt;
- if(size>= 0) size = tsize+KB_PREALLOC;
- }
-
- // --- add action ---------------------------------------------------
-
- tab[tsize--].code = NoSymbol;
- tab[tsize].code = code;
- tab[tsize].mod = modmsk;
- kb_key *newone = &tab[tsize];
-
- // --- convert list to hash table if necessary ----------------------
-
- if(size>= 0 && tsize>= 32) {
- kb_key *oldtab = tab;
- kb_key **nht = new kb_key*[KB_HASHSIZE];
- for(int i = 0; i < KB_HASHSIZE; i++)
- nht[i] = 0;
- htable = nht;
- size = -KB_HASHSIZE;
-
- // --- copy old keys to new hash table ---
- int hashval;
- for(kb_key *tu = oldtab; tu->code != NoSymbol; tu++){
- // copy values from oldtab to htable
- hashval = (tu->code&0xffff);
- hashval = ((hashval&0xff) ^ ((hashval>>8)&0xff)) % KB_HASHSIZE;
- tab = htable[hashval];
-
- if(!tab){
- htable[hashval] = tab = new kb_key[KB_PREALLOC];
- tab->code = NoSymbol;
- }
- int ts = 1;
- for(kb_key *tt = tab; tt->code != NoSymbol; tt++)
- ts++;
- if(ts % KB_PREALLOC == 0){
- // extend table
- kb_key *nt = new kb_key[ts+KB_PREALLOC];
- memcpy(nt, tab, ts*sizeof(kb_key));
- htable[hashval] = nt;
- delete[] tab;
- tab = nt;