Annotation of coherent/d/bin/tsort/hash.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: #include "tsort.h"
                      3: 
                      4: 
                      5: /*
                      6:  *     Htab is the hash table.
                      7:  */
                      8: 
                      9:        static struct wordlist *htable[HASHSIZE];
                     10: 
                     11: 
                     12: /*
                     13:  *     The function insert returns a pointer to the hash table entry
                     14:  *     corresponding to the name "str".
                     15:  *     If the entry is new, then it initializes the ancestors field to
                     16:  *     NULL.
                     17:  */
                     18: 
                     19: struct word *
                     20: insert(str)
                     21: register char *str;
                     22: {
                     23:        register struct wordlist *ptr; 
                     24:        unsigned hindex;
                     25:        unsigned hash();
                     26:        struct word *newword();
                     27:        struct wordlist *newwordl();
                     28: 
                     29:        hindex = hash(str) % HASHSIZE;
                     30:        for (ptr=htable[hindex]; ptr != NULL; ptr=ptr->next)
                     31:                if (strcmp(ptr->element->name, str) == 0)
                     32:                        return (ptr->element);
                     33:        ptr = newwordl(newword(str));
                     34:        ptr->next = htable[hindex];
                     35:        htable[hindex] = ptr;
                     36:        return (ptr->element);
                     37: }
                     38: 
                     39: 
                     40: /*
                     41:  *     The function hash computes the hash index of the
                     42:  *     string pointed to by "str".
                     43:  */
                     44: 
                     45: static unsigned
                     46: hash(str)
                     47: register char *str;
                     48: {
                     49:        register unsigned result = 0;
                     50:        register int ch;
                     51: 
                     52:        while ((ch = *str++) != '\0')
                     53:                result = 128 * result - result + 16 * (ch % 16) + (ch / 16);
                     54:        return (result);
                     55: }
                     56: 
                     57: 
                     58: /*
                     59:  *     Cmphash returns a pointer to a wordlist which is a linked list
                     60:  *     of all words in the hash table.
                     61:  */
                     62: 
                     63: struct wordlist *
                     64: cmphash()
                     65: {
                     66:        register struct wordlist *mrk;
                     67:        register struct wordlist *head;
                     68:        register struct wordlist **htabp;
                     69: 
                     70:        head = NULL;
                     71:        for (htabp = htable; htabp - htable < HASHSIZE; ++htabp)
                     72:                if (*htabp != NULL) {
                     73:                        for (mrk = *htabp; mrk->next != NULL; mrk = mrk->next)
                     74:                                ;
                     75:                        mrk->next = head;
                     76:                        head = *htabp;
                     77:                }
                     78:        return (head);
                     79: }

unix.superglobalmegacorp.com

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