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

📄 quickhash.c

📁 Calc Software Package for Number Calc
💻 C
📖 第 1 页 / 共 2 页
字号:
 * randhash - return a trivial hash for an s100 state * * given: *	state - state to hash * * returns: *	trivial hash integer */static QCKHASHrandhash(RAND *r, QCKHASH val){	/*	 * hash the RAND state	 */	if (!r->seeded) {		/* unseeded state hashes to V_RAND */		return V_RAND+val;	} else {		/* hash control values */	    	val += V_RAND;		quasi_fnv(r->j, val);		quasi_fnv(r->k, val);		quasi_fnv(r->bits, val);		quasi_fnv(r->need_to_skip, val);		/* hash the state arrays */		return fnv_fullhash(&r->buffer[0], SLEN+SCNT+SHUFLEN, val);	}}/* * randomhash - return a trivial hash for a Blum state * * given: *	state - state to hash * * returns: *	trivial hash integer */static QCKHASHrandomhash(RANDOM *state, QCKHASH val){	/*	 * unseeded RANDOM state hashes to V_RANDOM	 */	if (!state->seeded) {		return V_RANDOM+val;	}	/*	 * hash a seeded RANDOM state	 */	val += V_RANDOM;	quasi_fnv(state->buffer+state->bits, val);	if (state->r.v != NULL) {		val = fnv_zhash(state->r, val);	}	if (state->n.v != NULL) {		val = fnv_zhash(state->n, val);	}	return val;}/* * config_hash - return a trivial hash for a configuration state */static QCKHASHconfig_hash(CONFIG *cfg, QCKHASH val){	USB32 value;		/* value to hash from hash elements */	/*	 * build up a scalar value	 *	 * We will rotate a value left 5 bits and xor in each scalar element	 */	value = cfg->outmode;	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->outmode);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->outmode2);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->outdigits);	/* epsilon is handeled out of order */	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->epsilonprec);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->traceflags);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->maxprint);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->mul2);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->sq2);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->pow2);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->redc2);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->tilde_ok);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->tab_ok);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->quomod);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->quo);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->mod);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->sqrt);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->appr);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->cfappr);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->cfsim);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->outround);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->round);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->leadzero);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->fullzero);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->maxscancount);	/* prompt1 is handeled out of order */	/* prompt2 is handeled out of order */	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->blkmaxprint);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->blkverbose);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->blkbase);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->blkfmt);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->calc_debug);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->resource_debug);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->user_debug);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->verbose_quit);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->ctrl_d);	/* program is handeled out of order */	/* basename is handeled out of order */	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->windows);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->cygwin);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->compile_custom);	if (cfg->allow_custom != NULL && *(cfg->allow_custom)) {		value = (((value>>5) | (value<<27)) ^ (USB32)TRUE);	} else {		value = (((value>>5) | (value<<27)) ^ (USB32)FALSE);	}	/* version is handeled out of order */	/*	 * hash the built up scalar	 */	val += V_CONFIG;	quasi_fnv(value, val);	/*	 * hash the strings and pointers if possible	 */	if (cfg->prompt1) {		val = fnv_strhash(cfg->prompt1, val);	}	if (cfg->prompt2) {		val = fnv_strhash(cfg->prompt2, val);	}	if (cfg->program) {		val = fnv_strhash(cfg->program, val);	}	if (cfg->base_name) {		val = fnv_strhash(cfg->base_name, val);	}	if (cfg->version) {		val = fnv_strhash(cfg->version, val);	}	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->baseb);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->redecl_warn);	value = (((value>>5) | (value<<27)) ^ (USB32)cfg->dupvar_warn);	/*	 * hash the epsilon if possible	 */	if (cfg->epsilon) {		val = fnv_qhash(cfg->epsilon, val);	}	return val;}/* * fnv_strhash - Fowler/Noll/Vo 32 bit hash of a null-terminated string * * given: *	ch	the start of the string to hash *	val	initial hash value * * returns: *	a 32 bit QCKHASH value */static QCKHASHfnv_strhash(char *ch, QCKHASH val){	/*	 * hash each character in the string	 */	while (*ch) {		quasi_fnv(*ch++, val);	}	return val;}/* * fnv_STRhash - Fowler/Noll/Vo 32 bit hash of a STRING * * given: *	str	the string to hash *	val	initial hash value * * returns: *	a 32 bit QCKHASH value */static QCKHASHfnv_STRhash(STRING *str, QCKHASH val){	char *ch;	long n;	ch = str->s_str;	n = str->s_len;	/*	 * hash each character in the string	 */	while (n-- > 0) {		quasi_fnv(*ch++, val);	}	return val;}/* * fnv_fullhash - Fowler/Noll/Vo 32 bit hash of an array of HALFs * * given: *	v	an array of FULLs *	len	length of buffer FULLs *	val	initial hash value * * returns: *	a 32 bit QCKHASH value */static QCKHASHfnv_fullhash(FULL *v, LEN len, QCKHASH val){	/*	 * hash each character in the string	 */	while (len-- > 0) {		quasi_fnv(*v++, val);	}	return val;}/* * fnv_zhash - Fowler/Noll/Vo 32 bit hash of ZVALUE * * given: *	z	a ZVALUE *	val	initial hash value * * returns: *	a 32 bit QCKHASH value */static QCKHASHfnv_zhash(ZVALUE z, QCKHASH val){	LEN n;	HALF *hp;#if BASEB == 16	FULL f;#endif	/*	 * hash the sign	 */	val += V_NUM;	quasi_fnv(z.sign, val);	n = z.len;	hp = z.v;#if BASEB == 16	while (n > 1) {		f = (FULL) *hp++;		f |= (FULL) *hp++ << BASEB;		quasi_fnv(f, val);		n -= 2;	}	if (n) {		quasi_fnv(*hp, val);	}#else	while (n--  > 0) {		quasi_fnv(*hp, val);		++hp;	}#endif	return val;}/* * hash_hash - Fowler/Noll/Vo 32 bit hash of a block * * given: *	hash	the HASH to quickhash *	val	initial hash value * * returns: *	a 32 bit QCKHASH value */static QCKHASHhash_hash(HASH *hash, QCKHASH val){	int i;	/*	 * hash each USB8 in the BLOCK	 */	for (i=0; i < hash->unionsize; ++i) {		quasi_fnv(hash->h_union.data[i], val);	}	return val;}/* * blk_hash - Fowler/Noll/Vo 32 bit hash of a block * * given: *	blk	the BLOCK to hash *	val	initial hash value * * returns: *	a 32 bit QCKHASH value */static QCKHASHblk_hash(BLOCK *blk, QCKHASH val){	int i;	if (blk == NULL)		/* block has no data */		return val;	/*	 * hash each USB8 in the BLOCK	 */	if (blk->datalen > 0) {		for (i=0; i < blk->datalen; ++i) {			quasi_fnv(blk->data[i], val);		}	}	return val;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -