Annotation of researchv10no/cmd/mk/export/symtab.c, revision 1.1.1.1

1.1       root        1: #include       "mk.h"
                      2: 
                      3: #define        NHASH   4099
                      4: #define        HASHMUL 79L     /* this is a good value */
                      5: static Symtab *hash[NHASH];
                      6: 
                      7: syminit()
                      8: {
                      9:        register Symtab **s, *ss;
                     10: 
                     11:        for(s = hash; s < &hash[NHASH]; s++){
                     12:                for(ss = *s; ss; ss = ss->next)
                     13:                        free((char *)ss);
                     14:                *s = 0;
                     15:        }
                     16: }
                     17: 
                     18: Symtab *
                     19: symlook(sym, space, install)
                     20:        char *sym;
                     21:        char *install;
                     22: {
                     23:        register long h;
                     24:        register char *p;
                     25:        register Symtab *s;
                     26: 
                     27:        for(p = sym, h = space; *p; h += *p++)
                     28:                h *= HASHMUL;
                     29:        if(h < 0)
                     30:                h = ~h;
                     31:        h %= NHASH;
                     32:        for(s = hash[h]; s; s = s->next)
                     33:                if((s->space == space) && (strcmp(s->name, sym) == 0))
                     34:                        return(s);
                     35:        if(install == 0)
                     36:                return((Symtab *)0);
                     37:        s = (Symtab *)Malloc(sizeof(Symtab));
                     38:        s->space = space;
                     39:        s->name = sym;
                     40:        s->value = install;
                     41:        s->next = hash[h];
                     42:        hash[h] = s;
                     43:        return(s);
                     44: }
                     45: 
                     46: symdel(sym, space)
                     47:        char *sym;
                     48: {
                     49:        register long h;
                     50:        register char *p;
                     51:        register Symtab *s, *ls;
                     52: 
                     53:        for(p = sym, h = space; *p; h += *p++)
                     54:                h *= HASHMUL;
                     55:        if(h < 0)
                     56:                h = ~h;
                     57:        h %= NHASH;
                     58:        for(s = hash[h], ls = 0; s; ls = s, s = s->next)
                     59:                if((s->space == space) && (strcmp(s->name, sym) == 0)){
                     60:                        if(ls)
                     61:                                ls->next = s->next;
                     62:                        else
                     63:                                hash[h] = s->next;
                     64:                        free((char *)s);
                     65:                }
                     66: }
                     67: 
                     68: symtraverse(space, fn)
                     69:        void (*fn)();
                     70: {
                     71:        register Symtab **s, *ss;
                     72: 
                     73:        for(s = hash; s < &hash[NHASH]; s++)
                     74:                for(ss = *s; ss; ss = ss->next)
                     75:                        if(ss->space == space)
                     76:                                (*fn)(ss);
                     77: }
                     78: 
                     79: symstat()
                     80: {
                     81:        register Symtab **s, *ss;
                     82:        register n;
                     83:        int l[1000];
                     84: 
                     85:        memset((char *)l, 0, sizeof(l));
                     86:        for(s = hash; s < &hash[NHASH]; s++){
                     87:                for(ss = *s, n = 0; ss; ss = ss->next)
                     88:                        n++;
                     89:                l[n]++;
                     90:        }
                     91:        for(n = 0; n < 1000; n++)
                     92:                if(l[n]) Fprint(1, "%ld of length %d\n", l[n], n);
                     93: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.