?? hash.c
字號:
/* Copyright (C) 2002, 2003 Slava Astashonok <sla@0n.ru> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License. $Id: hash.c,v 1.3.2.1 2003/03/28 22:57:51 sla Exp $*/#include <common.h>#include <hash.h>#ifdef HASH_TYPE_CRCstatic uint16_t crc16_table[256];uint16_t crc16(uint16_t crc, uint8_t val){ int i; crc ^= val << 8; for (i = 8; i--; ) crc = crc & 0x8000 ? (crc << 1) ^ CRC16_POLY : crc << 1; return crc;}#endifhash_t hash(void *p, int size){ /* ?FIXME? Check for valid size (> 0) */ hash_t hash = 0;#if defined HASH_TYPE_XOR && HASH_BITS == 16 size--;#endif for (;size--;) {#ifdef HASH_TYPE_XOR hash ^= *((hash_t *)p++);#endif#ifdef HASH_TYPE_CRC hash = crc16_table[*((uint8_t *)p++) ^ (hash >> 8)] ^ (hash << 8);#endif } return hash;}void hash_init(){#ifdef HASH_TYPE_CRC int i; for (i = 0; i < 256 ; i++) crc16_table[i] = crc16(0, i);#endif}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -