|
|
1.1 ! root 1: /********************************************************************* ! 2: * COPYRIGHT NOTICE * ! 3: ********************************************************************** ! 4: * This software is copyright (C) 1982 by Pavel Curtis * ! 5: * * ! 6: * Permission is granted to reproduce and distribute * ! 7: * this file by any means so long as no fee is charged * ! 8: * above a nominal handling fee and so long as this * ! 9: * notice is always included in the copies. * ! 10: * * ! 11: * Other rights are reserved except as explicitly granted * ! 12: * by written permission of the author. * ! 13: * Pavel Curtis * ! 14: * Computer Science Dept. * ! 15: * 405 Upson Hall * ! 16: * Cornell University * ! 17: * Ithaca, NY 14853 * ! 18: * * ! 19: * Ph- (607) 256-4934 * ! 20: * * ! 21: * Pavel.Cornell@Udel-Relay (ARPAnet) * ! 22: * decvax!cornell!pavel (UUCPnet) * ! 23: *********************************************************************/ ! 24: ! 25: /* ! 26: * comp_hash.c --- Routines to deal with the hashtable of capability ! 27: * names. ! 28: * ! 29: * $Log: comp_hash.c,v $ ! 30: * Revision 1.1 92/03/13 10:45:37 bin ! 31: * Initial revision ! 32: * ! 33: * Revision 2.1 82/10/25 14:45:34 pavel ! 34: * Added Copyright Notice ! 35: * ! 36: * Revision 2.0 82/10/24 15:16:34 pavel ! 37: * Beta-one Test Release ! 38: * ! 39: * Revision 1.3 82/08/23 22:29:33 pavel ! 40: * The REAL Alpha-one Release Version ! 41: * ! 42: * Revision 1.2 82/08/19 19:09:46 pavel ! 43: * Alpha Test Release One ! 44: * ! 45: * Revision 1.1 82/08/12 18:36:23 pavel ! 46: * Initial revision ! 47: * ! 48: * ! 49: */ ! 50: ! 51: #ifndef COHERENT ! 52: static char RCSid[] = ! 53: "$Header: /src386/usr/bin/tic/RCS/comp_hash.c,v 1.1 92/03/13 10:45:37 bin Exp $"; ! 54: #endif ! 55: ! 56: #include "compiler.h" ! 57: #include "term.h" ! 58: ! 59: ! 60: ! 61: /* ! 62: * make_hash_table() ! 63: * ! 64: * Takes the entries in cap_table[] and hashes them into cap_hash_table[] ! 65: * by name. There are Captabsize entries in cap_table[] and Hashtabsize ! 66: * slots in cap_hash_table[]. ! 67: * ! 68: */ ! 69: ! 70: make_hash_table() ! 71: { ! 72: int i; ! 73: int hashvalue; ! 74: int collisions = 0; ! 75: ! 76: for (i=0; i < Captabsize; i++) ! 77: { ! 78: hashvalue = hash_function(cap_table[i].nte_name); ! 79: DEBUG(9, "%d\n", hashvalue); ! 80: ! 81: if (cap_hash_table[hashvalue] != (struct name_table_entry *) 0) ! 82: collisions++; ! 83: ! 84: cap_table[i].nte_link = cap_hash_table[hashvalue]; ! 85: cap_hash_table[hashvalue] = &cap_table[i]; ! 86: } ! 87: ! 88: DEBUG(3, "Hash table complete\n%d collisions ", collisions); ! 89: DEBUG(3, "out of %d entries\n", Captabsize); ! 90: } ! 91: ! 92: ! 93: ! 94: /* ! 95: * int hash_function(string) ! 96: * ! 97: * Computes the hashing function on the given string. ! 98: * ! 99: * The current hash function is the sum of each consectutive pair ! 100: * of characters, taken as two-byte integers, mod Hashtabsize. ! 101: * ! 102: */ ! 103: ! 104: static ! 105: int ! 106: hash_function(string) ! 107: char *string; ! 108: { ! 109: long sum = 0; ! 110: ! 111: while (*string) ! 112: { ! 113: sum += *string + (*(string + 1) << 8); ! 114: string++; ! 115: } ! 116: ! 117: return (sum % Hashtabsize); ! 118: } ! 119: ! 120: ! 121: ! 122: /* ! 123: * struct name_table_entry * ! 124: * find_entry(string) ! 125: * ! 126: * Finds the entry for the given string in the hash table if present. ! 127: * Returns a pointer to the entry in the table or 0 if not found. ! 128: * ! 129: */ ! 130: ! 131: struct name_table_entry * ! 132: find_entry(string) ! 133: char *string; ! 134: { ! 135: int hashvalue; ! 136: struct name_table_entry *ptr; ! 137: ! 138: hashvalue = hash_function(string); ! 139: ! 140: ptr = cap_hash_table[hashvalue]; ! 141: ! 142: while (ptr != (struct name_table_entry *) 0 && ! 143: strcmp(ptr->nte_name, string) != 0) ! 144: ptr = ptr->nte_link; ! 145: ! 146: return (ptr); ! 147: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.