⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hash.c

📁 模仿cisco路由器
💻 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 + -