text: #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
  
  #define HASHSIZE 101
  
  struct nlist {
      struct nlist *next;
      char *name;
      char *defn;
  };
  
  static struct nlist *hashtab[HASHSIZE];
  
  unsigned hash(char *s) {
      unsigned hashval;
      unsigned result;
      for (hashval = 0; *s != '\0'; s++) {
          hashval = *s + 31 * hashval;
      }
      result = hashval % HASHSIZE;
      printf("hash result: %d\n", result);
      return result;
  };
  
  struct nlist *lookup(char *s) {
      struct nlist *np;
      for (np = hashtab[hash(s)]; np != NULL; np = np->next) {
          if (strcmp(s, np->name) == 0) {
              return np;
          }
      }
      return NULL;
  };
  
  struct nlist *install(char *name, char *defn) {
      struct nlist *np;
      unsigned hashval;
      if ((np = lookup(name)) == NULL) {
          np = (struct nlist *) malloc(sizeof(*np));
          if (np == NULL || (np->name = strdup(name)) == NULL) {
              return NULL;
          }
          hashval = hash(name);
          np->next = hashtab[hashval];
          hashtab[hashval] = np;
      }
      else {
          free((void *) np->defn);
      }
      if ((np->defn = strdup(defn)) == NULL) {
          return NULL;
      }
      return np;
  };
  
  
  main () {
      install("IN", "1");
      install("OUT", "0");
      struct nlist *np;
      np = lookup("IN");
      printf("%s\n", np->defn);
  };
  