|
|
1.1 ! root 1: /* ! 2: * Tables for the table-driven CRC16 algorithm. ! 3: * This should be relatively uniform statistically. ! 4: */ ! 5: static unsigned short crctab1[] = { ! 6: 0000000, 0140301, 0140601, 0000500, ! 7: 0141401, 0001700, 0001200, 0141101, ! 8: 0143001, 0003300, 0003600, 0143501, ! 9: 0002400, 0142701, 0142201, 0002100 ! 10: }; ! 11: ! 12: static unsigned short crctab2[] = { ! 13: 0000000, 0146001, 0154001, 0012000, ! 14: 0170001, 0036000, 0024000, 0162001, ! 15: 0120001, 0066000, 0074000, 0132001, ! 16: 0050000, 0116001, 0104001, 0043000 ! 17: }; ! 18: ! 19: /* ! 20: * Read a string return the hash value computed using CRC-16 methods. ! 21: * usefull for various kinds of hashing including diff programs ! 22: * and symbol tables. ! 23: */ ! 24: unsigned short ! 25: crc16(p) ! 26: register char *p; ! 27: { ! 28: register unsigned char tmp, c; ! 29: register unsigned short h; ! 30: ! 31: for(h = 0; c = *p; p++) { ! 32: tmp = c ^ h; ! 33: h = (h >> 8) ^ crctab1[tmp & 15] ^ crctab2[tmp >> 4]; ! 34: } ! 35: return(h); ! 36: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.