Exemple #1
0
static wait_queue_head_t *dax_entry_waitqueue(struct address_space *mapping,
					      pgoff_t index)
{
	unsigned long hash = hash_long((unsigned long)mapping ^ index,
				       DAX_WAIT_TABLE_BITS);
	return wait_table + hash;
}
Exemple #2
0
int main()  
{  
    // 假设hash table的长度为8(2^3)  
    int bits = 5;  
    int elem_num = 1<<bits;  
    int vec[elem_num];  
                                                                                                                                      
    for (int i=0; i<elem_num; ++i)  
        vec[i] = 0;  
  
    srand(time(NULL));  
  
    for(int i=0; i<1000; i++)  
    {     
        int num = rand()%1000;  
        printf("num:%d\n", num);  
        int elem_idx = hash_long(num, bits);  

        printf("num:%d\n", elem_idx);  
        vec[elem_idx] ++;   
    }     
  
    printf("========================\n");  
    for (int i=0; i<elem_num; ++i)  
    {     
        printf("vec[%d]: %d\n", i, vec[i]);  
    }     
  
    return 0;  
}  
Exemple #3
0
wait_queue_head_t *bit_waitqueue(void *word, int bit)
{
	const int shift = BITS_PER_LONG == 32 ? 5 : 6;
	const struct zone *zone = page_zone(virt_to_page(word));
	unsigned long val = (unsigned long)word << shift | bit;

	return &zone->wait_table[hash_long(val, zone->wait_table_bits)];
}
Exemple #4
0
void drm_ht_verbose_list(struct drm_open_hash *ht, unsigned long key)
{
	struct drm_hash_item *entry;
	struct hlist_head *h_list;
	unsigned int hashed_key;
	int count = 0;

	hashed_key = hash_long(key, ht->order);
	DRM_DEBUG("Key is 0x%08lx, Hashed key is 0x%08x\n", key, hashed_key);
	h_list = &ht->table[hashed_key];
<<<<<<< HEAD
Exemple #5
0
PRIVATE ThreadInfo* find_thread_info(ULONG tid)
{
    ThreadInfo *info;
    DLList *hashQ, *node;

    ULONG idx = hash_long(tid, TID_HASH_SHIFT);
    hashQ = &(g_threadQ->tidHashQ[idx]);

    dllist_for_each(node, hashQ)
    {
        info = list_entry(node, ThreadInfo, hashNode);
        if(info->tid == tid)
            return info;
    }
void drm_ht_verbose_list(struct drm_open_hash *ht, unsigned long key)
{
	struct drm_hash_item *entry;
	struct hlist_head *h_list;
	struct hlist_node *list;
	unsigned int hashed_key;
	int count = 0;

	hashed_key = hash_long(key, ht->order);
	DRM_DEBUG("Key is 0x%08lx, Hashed key is 0x%08x\n", key, hashed_key);
	h_list = &ht->table[hashed_key];
	hlist_for_each(list, h_list) {
		entry = hlist_entry(list, struct drm_hash_item, head);
		DRM_DEBUG("count %d, key: 0x%08lx\n", count++, entry->key);
	}
Exemple #7
0
/*
 * hash_value - hash a value
 *
 * given:
 *	type	- hash type (see hash.h)
 *	v	- the value
 *	state	- the state to hash or NULL
 *
 * returns:
 *	the new state
 */
HASH *
hash_value(int type, void *v, HASH *state)
{
	LISTELEM *ep;		/* list element pointer */
	ASSOCELEM **assochead;	/* association chain head */
	ASSOCELEM *aep;		/* current association value */
	ASSOCELEM *nextaep;	/* next association value */
	VALUE *value = (VALUE *)v;	/* v cast to a VALUE */
	VALUE *vp;		/* pointer to next OBJ table value */
	ZVALUE fileval;		/* size, position, dev, inode of a file */
	int i;

	/*
	 * initialize if state is NULL
	 */
	if (state == NULL) {
		state = hash_init(type, NULL);
	}

	/*
	 * process the value type
	 */
	switch (value->v_type) {
	case V_NULL:
		(state->chkpt)(state);
		state->bytes = TRUE;
		break;

	case V_INT:
		/* setup for the this value type */
		(state->chkpt)(state);
		(state->type)(value->v_type, state);

		/* hash as if we have a 64 bit value */
		state = hash_int(type, value->v_int, state);
		break;

	case V_NUM:
		/* hash this type */
		state = hash_number(type, value->v_num, state);
		break;

	case V_COM:
		/* setup for the this value type */
		(state->chkpt)(state);
		(state->type)(value->v_type, state);

		/* hash this type */
		state = hash_complex(type, value->v_com, state);
		break;

	case V_ADDR:
		/* there is nothing to setup, simply hash what we point at */
		state = hash_value(type, value->v_addr, state);
		break;

	case V_STR:
		/* strings have no setup */

		/* hash this type */
		state = hash_STR(type, value->v_str, state);
		break;

	case V_MAT:
		/* setup for the this value type */
		(state->chkpt)(state);
		(state->type)(value->v_type, state);
		state->bytes = TRUE;

		/* hash all the elements of the matrix */
		for (i=0; i < value->v_mat->m_size; ++i) {

			/* hash the next matrix value */
			state = hash_value(type,
					value->v_mat->m_table+i, state);
			state->bytes = FALSE;	/* as if reading words */
		}
		break;

	case V_LIST:
		/* setup for the this value type */
		(state->chkpt)(state);
		(state->type)(value->v_type, state);

		/* hash all the elements of the list */
		for (i=0, ep = value->v_list->l_first;
		     ep != NULL && i < value->v_list->l_count;
		     ++i, ep = ep->e_next) {

			/* hash the next list value */
			state = hash_value(type, &ep->e_value, state);
			state->bytes = FALSE;	/* as if reading words */
		}
		break;

	case V_ASSOC:
		/* setup for the this value type */
		(state->chkpt)(state);
		(state->type)(value->v_type, state);
		state->bytes = TRUE;

		/* hash the association */
		assochead = value->v_assoc->a_table;
		for (i = 0; i < value->v_assoc->a_size; i++) {
			nextaep = *assochead;
			while (nextaep) {
				aep = nextaep;
				nextaep = aep->e_next;

				/* hash the next association value */
				state = hash_value(type, &aep->e_value, state);
				state->bytes = FALSE; /* as if reading words */
			}
			assochead++;
		}
		break;

	case V_OBJ:
		/* setup for the this value type */
		(state->chkpt)(state);
		(state->type)(value->v_type, state);
		state->bytes = TRUE;	/* reading bytes */

		/* hash the object name and then the element values */

		state = hash_str(type, objtypename(
			value->v_obj->o_actions->oa_index), state);
		(state->chkpt)(state);

		for (i=value->v_obj->o_actions->oa_count,
		     vp=value->v_obj->o_table;
		     i-- > 0;
		     vp++) {

			/* hash the next object value */
			state = hash_value(type, vp, state);
			state->bytes = FALSE;	/* as if reading words */
		}
		break;

	case V_FILE:
		/* setup for the this value type */
		(state->chkpt)(state);
		(state->type)(value->v_type, state);

		/* hash file length if possible */
		if (getsize(value->v_file, &fileval) == 0) {
			state = hash_zvalue(type, fileval, state);
			zfree(fileval);
		} else {
			/* hash -1 for invalid length */
			state = hash_long(type, (long)-1, state);
		}
		/* hash the file position if possible */
		if (getloc(value->v_file, &fileval) == 0) {
			state = hash_zvalue(type, fileval, state);
			zfree(fileval);
		} else {
			/* hash -1 for invalid location */
			state = hash_long(type, (long)-1, state);
		}
		/* hash the file device if possible */
		if (get_device(value->v_file, &fileval) == 0) {
			state = hash_zvalue(type, fileval, state);
			zfree(fileval);
		} else {
			/* hash -1 for invalid device */
			state = hash_long(type, (long)-1, state);
		}
		/* hash the file inode if possible */
		if (get_inode(value->v_file, &fileval) == 0) {
			state = hash_zvalue(type, fileval, state);
			zfree(fileval);
		} else {
			/* hash -1 for invalid inode */
			state = hash_long(type, (long)-1, state);
		}
		break;

	case V_RAND:
		/* setup for the this value type */
		(state->chkpt)(state);
		(state->type)(value->v_type, state);

		/* hash the RAND state */
		state = hash_int(type, value->v_rand->seeded, state);
		state = hash_int(type, value->v_rand->bits, state);
		(state->update)(state,
			(USB8 *)value->v_rand->buffer, SLEN*FULL_BITS/8);
		state = hash_int(type, value->v_rand->j, state);
		state = hash_int(type, value->v_rand->k, state);
		state = hash_int(type, value->v_rand->need_to_skip, state);
		(state->update)(state,
			(USB8 *)value->v_rand->slot, SCNT*FULL_BITS/8);
		(state->update)(state,
			(USB8*)value->v_rand->shuf, SHUFLEN*FULL_BITS/8);
		state->bytes = FALSE;	/* as if reading words */
		break;

	case V_RANDOM:
		/* setup for the this value type */
		(state->chkpt)(state);
		(state->type)(value->v_type, state);

		/* hash the RANDOM state */
		state = hash_int(type, value->v_random->seeded, state);
		state = hash_int(type, value->v_random->bits, state);
		(state->update)(state,
			(USB8 *)&(value->v_random->buffer), BASEB/8);
		state = hash_zvalue(type, value->v_random->r, state);
		state = hash_zvalue(type, value->v_random->n, state);
		state->bytes = FALSE;	/* as if reading words */
		break;

	case V_CONFIG:
		/* setup for the this value type */
		(state->chkpt)(state);
		(state->type)(value->v_type, state);

		/* hash the CONFIG state */
		state = hash_int(type, value->v_config->outmode, state);
		state = hash_int(type, value->v_config->outmode2, state);
		state = hash_long(type,(long)value->v_config->outdigits, state);
		state = hash_number(type, value->v_config->epsilon, state);
		state = hash_long(type,
			(long)value->v_config->epsilonprec, state);
		state = hash_flag(type, value->v_config->traceflags, state);
		state = hash_long(type, (long)value->v_config->maxprint, state);
		state = hash_len(type, value->v_config->mul2, state);
		state = hash_len(type, value->v_config->sq2, state);
		state = hash_len(type, value->v_config->pow2, state);
		state = hash_len(type, value->v_config->redc2, state);
		state = hash_bool(type, value->v_config->tilde_ok, state);
		state = hash_bool(type, value->v_config->tab_ok, state);
		state = hash_long(type, (long)value->v_config->quomod, state);
		state = hash_long(type, (long)value->v_config->quo, state);
		state = hash_long(type, (long)value->v_config->mod, state);
		state = hash_long(type, (long)value->v_config->sqrt, state);
		state = hash_long(type, (long)value->v_config->appr, state);
		state = hash_long(type, (long)value->v_config->cfappr, state);
		state = hash_long(type, (long)value->v_config->cfsim, state);
		state = hash_long(type, (long)value->v_config->outround, state);
		state = hash_long(type, (long)value->v_config->round, state);
		state = hash_bool(type, value->v_config->leadzero, state);
		state = hash_bool(type, value->v_config->fullzero, state);
		state = hash_long(type,
			(long)value->v_config->maxscancount, state);
		state = hash_str(type, value->v_config->prompt1, state);
		state->bytes = FALSE;	/* as if just read words */
		state = hash_str(type, value->v_config->prompt2, state);
		state->bytes = FALSE;	/* as if just read words */
		state = hash_int(type, value->v_config->blkmaxprint, state);
		state = hash_bool(type, value->v_config->blkverbose, state);
		state = hash_int(type, value->v_config->blkbase, state);
		state = hash_int(type, value->v_config->blkfmt, state);
		state = hash_long(type,
			(long)value->v_config->resource_debug, state);
		state = hash_long(type,
			(long)value->v_config->calc_debug, state);
		state = hash_long(type,
			(long)value->v_config->user_debug, state);
		state = hash_bool(type, value->v_config->verbose_quit, state);
		state = hash_int(type, value->v_config->ctrl_d, state);
		state = hash_str(type, value->v_config->program, state);
		state = hash_str(type, value->v_config->base_name, state);
		state = hash_bool(type, value->v_config->windows, state);
		state = hash_bool(type, value->v_config->cygwin, state);
		state = hash_bool(type, value->v_config->compile_custom, state);
		if (value->v_config->allow_custom != NULL &&
		    *(value->v_config->allow_custom)) {
			state = hash_bool(type, TRUE, state);
		} else {
			state = hash_bool(type, FALSE, state);
		}
		state = hash_str(type, value->v_config->version, state);
		state = hash_int(type, value->v_config->baseb, state);
		state = hash_bool(type, value->v_config->redecl_warn, state);
		state = hash_bool(type, value->v_config->dupvar_warn, state);
		break;

	case V_HASH:
		/* setup for the this value type */
		(state->chkpt)(state);
		(state->type)(value->v_type, state);

		/* hash the HASH state */
		state = hash_int(type, value->v_hash->type, state);
		state = hash_bool(type, value->v_hash->bytes,state);
		state = hash_int(type, value->v_hash->base, state);
		state = hash_int(type, value->v_hash->chunksize, state);
		state = hash_int(type, value->v_hash->unionsize, state);
		(state->update)(state,
		    value->v_hash->h_union.data, state->unionsize);
		state->bytes = FALSE;	/* as if reading words */
		break;

	case V_BLOCK:
		/* there is no setup for a BLOCK */

		/* hash the octets in the BLOCK */
		if (value->v_block->datalen > 0) {
			state = hash_usb8(type, value->v_block->data,
					   value->v_block->datalen, state);
		}
		break;

	case V_OCTET:
		/* there is no setup for an OCTET */

		/* hash the OCTET */
		state = hash_usb8(type, value->v_octet, 1, state);
		break;

	case V_NBLOCK:
		/* there is no setup for a NBLOCK */

		/* hash the octets in the NBLOCK */
		if (value->v_nblock->blk->datalen > 0) {
			state = hash_usb8(type, value->v_nblock->blk->data,
					   value->v_nblock->blk->datalen,
					   state);
		}
		break;

	default:
		math_error("hashing an unknown value");
		/*NOTREACHED*/
	}
	return state;
}
Exemple #8
0
static inline unsigned long faf_polled_fd_hashfn(unsigned long id)
{
	return hash_long(id, FAF_POLLED_FD_HASH_SHIFT);
}
static unsigned long mfn_hash(unsigned long mfn)
{
	return hash_long(mfn, M2P_OVERRIDE_HASH_SHIFT);
}
Exemple #10
0
static unsigned long ihash(ino_t ino, __u64 cno)
{
	return hash_long((unsigned long)((ino << 2) + cno),
			 NILFS_GCINODE_HASH_BITS);
}