|
|
1.1 ! root 1: #include "../h/rt.h" ! 2: ! 3: /* ! 4: * hash - compute hash value of arbitrary object for table and set accessing. ! 5: */ ! 6: ! 7: hash(d) ! 8: struct descrip *d; ! 9: { ! 10: register int i, j; ! 11: register char *s; ! 12: ! 13: if (QUAL(*d)) { ! 14: /* ! 15: * Compute the hash value for the string by summing the value ! 16: * of all the characters (up to a maximum of 10) plus the length. ! 17: */ ! 18: i = 0; ! 19: s = STRLOC(*d); ! 20: j = STRLEN(*d); ! 21: for (j = (j <= 10) ? j : 10 ; j > 0; j--) ! 22: i += *s++ & 0377; ! 23: i += STRLEN(*d) & 0377; ! 24: } ! 25: else { ! 26: switch (TYPE(*d)) { ! 27: /* ! 28: * The hash value for numeric types is the bitstring representation ! 29: * of the value. ! 30: */ ! 31: case T_INTEGER: ! 32: i = INTVAL(*d); ! 33: break; ! 34: ! 35: #ifdef LONGS ! 36: case T_LONGINT: ! 37: i = BLKLOC(*d)->longint.intval; ! 38: break; ! 39: ! 40: #endif LONGS ! 41: case T_REAL: ! 42: i = BLKLOC(*d)->realblk.realval; ! 43: break; ! 44: ! 45: case T_CSET: ! 46: /* ! 47: * Compute the hash value for a cset by exclusive or-ing the ! 48: * words in the bit array. ! 49: */ ! 50: i = 0; ! 51: for (j = 0; j < CSETSIZE; j++) ! 52: i ^= BLKLOC(*d)->cset.bits[j]; ! 53: break; ! 54: ! 55: default: ! 56: /* ! 57: * For other types, just use the type value as the hash ! 58: * value. This produces loads of collisions, but that's ! 59: * why collision insurance is mandatory. ! 60: */ ! 61: i = TYPE(*d); ! 62: break; ! 63: } ! 64: } ! 65: /* ! 66: * Return the hash value as a positive number. ! 67: */ ! 68: return ((unsigned)i); ! 69: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.