当前位置: 首页>>代码示例>>C++>>正文


C++ do_hash函数代码示例

本文整理汇总了C++中do_hash函数的典型用法代码示例。如果您正苦于以下问题:C++ do_hash函数的具体用法?C++ do_hash怎么用?C++ do_hash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了do_hash函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: hash_key

static khint_t hash_key(key_data_t key) {
    int i = 0;
    khint_t hash;

    if (key.single) {
        unsigned char sig[12];

        memcpy(sig + i, &key.this_ref, 4);      i += 4;
        memcpy(sig + i, &key.this_coord, 4);    i += 4;
        memcpy(sig + i, &key.orientation, 4);   i += 4;

        hash = do_hash(sig, i);
    } else {
        unsigned char sig[24];

        memcpy(sig + i, &key.this_ref, 4);      i += 4;
        memcpy(sig + i, &key.this_coord, 4);    i += 4;
        memcpy(sig + i, &key.other_ref, 4);     i += 4;
        memcpy(sig + i, &key.other_coord, 4);   i += 4;
        memcpy(sig + i, &key.leftmost, 4);      i += 4;
        memcpy(sig + i, &key.orientation, 4);   i += 4;

        hash = do_hash(sig, i);
    }

    return hash;
}
开发者ID:jkbonfield,项目名称:samtools,代码行数:27,代码来源:bam_markdup.c

示例2: st_find_or_add

int
st_find_or_add(st_table *table, char *key, char ***slot)
{
    int hash_val;
    st_table_entry *newEntry, *ptr, **last;

    hash_val = do_hash(key, table);

    FIND_ENTRY(table, hash_val, key, ptr, last);

    if (ptr == NULL) {
	if (table->num_entries / table->num_bins >= table->max_density) {
	    if (rehash(table) == ST_OUT_OF_MEM) {
		return ST_OUT_OF_MEM;
	    }
	    hash_val = do_hash(key, table);
	}
	newEntry = ABC_ALLOC(st_table_entry, 1);
	if (newEntry == NULL) {
	    return ST_OUT_OF_MEM;
	}
	newEntry->key = key;
	newEntry->record = (char *) 0;
	newEntry->next = table->bins[hash_val];
	table->bins[hash_val] = newEntry;
	table->num_entries++;
	if (slot != NULL) *slot = &newEntry->record;
	return 0;
    } else {
	if (slot != NULL) *slot = &ptr->record;
	return 1;
    }
}
开发者ID:kyotobay,项目名称:ABC_withFD_check,代码行数:33,代码来源:st.c

示例3: st_insert

int
st_insert(st_table *table, const char *key, char *value)
{
    int hash_val;
    st_table_entry *newEntry;
    st_table_entry *ptr, **last;

    hash_val = do_hash(key, table);

    FIND_ENTRY(table, hash_val, key, ptr, last);

    if (ptr == NULL) {
	if (table->num_entries/table->num_bins >= table->max_density) {
	    if (rehash(table) == ST_OUT_OF_MEM) {
		return ST_OUT_OF_MEM;
	    }
	    hash_val = do_hash(key, table);
	}
	newEntry = ABC_ALLOC(st_table_entry, 1);
	if (newEntry == NULL) {
	    return ST_OUT_OF_MEM;
	}
	newEntry->key = (char *)key;
	newEntry->record = value;
	newEntry->next = table->bins[hash_val];
	table->bins[hash_val] = newEntry;
	table->num_entries++;
	return 0;
    } else {
	ptr->record = value;
	return 1;
    }
}
开发者ID:kyotobay,项目名称:ABC_withFD_check,代码行数:33,代码来源:st.c

示例4: undo

void undo( letter_t c, keyword_t i )
/**********************************/
{
    keyword_t index;
    unsigned first_weight;
    unsigned last_weight;

    /*
        every keyword that had a full hash value calculated
        because of the weight of the character specified
        must deregister its hash value position
    */
    first_weight = first_scale * weights[c];
    last_weight = last_scale * weights[c];
    for( ; i > 0; --i ) {
        if( first[i] == c ) {
            --done[i];
            if( done[i] == 1 ) {      // 2 -> 1 transition
                index = do_hash( hash[i] );
                used[index] = NULL_KEYWORD;
            }
            hash[i] -= first_weight;
        }
        if( last[i] == c ) {
            --done[i];
            if( done[i] == 1 ) {      // 2 -> 1 transition
                index = do_hash( hash[i] );
                used[index] = NULL_KEYWORD;
            }
            hash[i] -= last_weight;
        }
    }
}
开发者ID:Azarien,项目名称:open-watcom-v2,代码行数:33,代码来源:findhash.c

示例5: sha1_hash

	extern int sha1_hash(t_hash * hashout, unsigned int size, void const * datain)
	{
		t_uint32              tmp[64 + 16];
		unsigned char const * data;
		unsigned int          inc;
		unsigned int          orgSize;

		if (!hashout || !*hashout)
		{
			eventlog(eventlog_level_error, __FUNCTION__, "got NULL hashout");
			return -1;
		}
		if (size > 0 && !datain)
		{
			eventlog(eventlog_level_error, __FUNCTION__, "got NULL datain with size=%u", size);
			return -1;
		}

		hash_init(hashout);
		orgSize = size;

		data = (const unsigned char*)datain;
		while (size > 0)
		{
			if (size >= 64)
				inc = 64;
			else
				inc = size;

			if (size >= 64)
			{
				hash_set_16(tmp, data, inc, do_sha1_hash);
				do_hash(hashout, tmp, do_sha1_hash);
			}
			else if (size > 55){

				hash_set_16(tmp, data, inc, do_sha1_hash);
				do_hash(hashout, tmp, do_sha1_hash);

				// now use blizz variant as we only wanna fill in zeros
				hash_set_16(tmp, data, 0, do_blizzard_hash);
				hash_set_length(tmp, orgSize);
				do_hash(hashout, tmp, do_sha1_hash);
			}
			else{
				hash_set_16(tmp, data, inc, do_sha1_hash);
				hash_set_length(tmp, orgSize);
				do_hash(hashout, tmp, do_sha1_hash);
			}

			data += inc;
			size -= inc;
		}

		return 0;
	}
开发者ID:AleXoundOS,项目名称:pvpgn,代码行数:56,代码来源:bnethash.cpp

示例6: dump_weights

void dump_weights( unsigned first_index, unsigned last_index )
/************************************************************/
{
    int bad_mask_hash;
    unsigned mask;
    char *prt_c;
    letter_t c;
    keyword_t i;
    unsigned h;

    outfile = fopen( get_gh_filename( "weights" ), "w" );
    dump_common_defs( first_index, last_index );
    bad_mask_hash = 0;
    for( mask = 1; mask != 0; mask <<= 1 ) {
        if( mask >= hashsize ) {
            for( i = 1; i <= num_keywords; ++i ) {
                h = hash[i];
                h &= mask - 1;
                if( mask != hashsize ) {
                    if( h >= hashsize ) {
                        h -= hashsize;
                    }
                }
                if( h != do_hash(hash[i]) ) {
                    output( "  %s: %u+%u*%u+%u*%u=%u mod %u = %u (%u)\n",
                            tokens[i],
                            init_hash[i],
                            first_scale, weights[first[i]],
                            last_scale, weights[last[i]],
                            hash[i],
                            hashsize,
                            do_hash( hash[i] ),
                            h );
                    bad_mask_hash = 1;
                    //break;
                }
            }
            break;
        }
    }
    if( bad_mask_hash ) {
        output( "code will use '%%' operator\n" );
    } else {
        fprintf( outfile, "#define KEYWORD_HASH_MASK  0x%0x\n", mask - 1 );
        if( mask != hashsize ) {
            fprintf( outfile, "#define KEYWORD_HASH_EXTRA\n" );
        }
    }
    fputc( '\n', outfile );
    for( c = LETTER_MIN; c <= LETTER_MAX; ++c ) {
        prt_c = make_define( c );
        fprintf( outfile, "#define W_%s     ", prt_c );
        fprintf( outfile, "%2d\n", weights[c]);
    }
    fclose( outfile );
}
开发者ID:Azarien,项目名称:open-watcom-v2,代码行数:56,代码来源:findhash.c

示例7: time

UniqueID::UniqueID()
{
	time_t m_time;
	int m_pid;
	char userName[255];
	char hostName[255];
	int ip = 3434;



	time(&(m_time));
	UniqueID::basedata += m_time;
	

	m_pid = _getpid();

	strcpy(userName,getenv(ENVSTRING));


	WSADATA wsaData;

	if(WSAStartup(MAKEWORD( 2, 2),&wsaData) == 0)
	{
		gethostname(hostName,255);	

		HOSTENT * host = gethostbyname(hostName);
		memcpy((void*)&ip, host->h_addr, 4);
	}
	else
	{
		strcpy(hostName,"ERROR_SOCKET");
	}

#ifdef WIN32
	MEMORYSTATUS lpBuffer;   // memory status structure
	GlobalMemoryStatus(&lpBuffer);
	int paso = (lpBuffer.dwAvailVirtual >> 8) * GenRandom() + GenRandom();	
#else
	int paso = GenRandom() * GenRandom();
#endif WIN32


	char* temp = uid;
	sprintf(temp,"%04.4x-",m_pid);
	temp += 5;
	sprintf(temp,"%08.8x-",m_time);
	temp += 9;	
	sprintf(temp,"%08.8x",do_hash(userName) + ip);
	temp += 8;
	sprintf(temp,"%08.8x-",do_hash(hostName) + ip);
	temp += 9;
	sprintf(temp,"%08.8x",paso);

	UniqueID::basedata++;
}
开发者ID:veladan,项目名称:StreamLib,代码行数:55,代码来源:UniqueID.cpp

示例8: os_uuid

int os_uuid(lua_State* L)
{
	char uuid[38];
	unsigned char bytes[16];
	
	/* If a name argument is supplied, build the UUID from that. For speed we
	 * are using a simple DBJ2 hashing function; if this isn't sufficient we
	 * can switch to a full RFC 4122 §4.3 implementation later. */
	const char* name = luaL_optstring(L, 1, NULL);
	if (name != NULL)
	{
		add(bytes, 0, do_hash(name, 0));
		add(bytes, 4, do_hash(name, 'L'));
		add(bytes, 8, do_hash(name, 'u'));
		add(bytes, 12, do_hash(name, 'a'));
	}

	/* If no name is supplied, try to build one properly */	
	else
	{
#if PLATFORM_WINDOWS
		CoCreateGuid((GUID*)bytes);
#elif PLATFORM_OS2
		int i;
		for (i = 0; i < 16; i++)
			bytes[i] = (unsigned char)gethrtime();
#else
		int result;

		/* not sure how to get a UUID here, so I fake it */
		FILE* rnd = fopen("/dev/urandom", "rb");
		result = fread(bytes, 16, 1, rnd);
		fclose(rnd);
		if (!result)
		{
			return 0;
		}
#endif
	}

	sprintf(uuid, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
		bytes[0], bytes[1], bytes[2], bytes[3],
		bytes[4], bytes[5],
		bytes[6], bytes[7],
		bytes[8], bytes[9],
		bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]);

	lua_pushstring(L, uuid);
	return 1;
}
开发者ID:Ashura-X,项目名称:mame,代码行数:50,代码来源:os_uuid.c

示例9: hash_ok

bool hash_ok( void )
/*********************/
{
    keyword_t i,j,h;

    for( i = 1; i <= num_keywords; ++i ) {
        h = do_hash( hash[i] );
        for( j = i + 1; j <= num_keywords; ++j ) {
            if( h == do_hash( hash[j] ) ) {
                return( false );
            }
        }
    }
    return( true );
}
开发者ID:Azarien,项目名称:open-watcom-v2,代码行数:15,代码来源:findhash.c

示例10: st_get_key

int
st_get_key(st_table *table, register st_data_t key, st_data_t *result)
{
    unsigned int hash_val, bin_pos;
    register st_table_entry *ptr;

    if (table->entries_packed) {
        int i;
        for (i = 0; i < table->num_entries; i++) {
            if ((st_data_t)table->bins[i*2] == key) {
                if (result !=0) *result = (st_data_t)table->bins[i*2];
                return 1;
            }
        }
        return 0;
    }

    hash_val = do_hash(key, table);
    FIND_ENTRY(table, ptr, hash_val, bin_pos);

    if (ptr == 0) {
	return 0;
    }
    else {
	if (result != 0)  *result = ptr->key;
	return 1;
    }
}
开发者ID:iriscouch,项目名称:ruby-inabox,代码行数:28,代码来源:st.c

示例11: st_lookup

int
st_lookup(st_table *table, register st_data_t key, st_data_t *value)
{
    unsigned int hash_val, bin_pos;
    register st_table_entry *ptr;

    if (table->entries_packed) {
        int i;
        for (i = 0; i < table->num_entries; i++) {
            if ((st_data_t)table->bins[i*2] == key) {
                if (value !=0) *value = (st_data_t)table->bins[i*2+1];
                return 1;
            }
        }
        return 0;
    }

    hash_val = do_hash(key, table);
    FIND_ENTRY(table, ptr, hash_val, bin_pos);

    if (ptr == 0) {
	return 0;
    }
    else {
	if (value != 0)  *value = ptr->record;
	return 1;
    }
}
开发者ID:iriscouch,项目名称:ruby-inabox,代码行数:28,代码来源:st.c

示例12: E_ASSERT

/*
 * Scans throught the section list, and if found
 * return it. Otherwise, return NULL.
 */
ConfigSection* Config::find_section(const char* section) {
	E_ASSERT(section != NULL);
	int slen = strlen(section);
	unsigned int hh = do_hash(section, slen);

	// check if we have cached section
	if (cached && cached->shash == hh && (strncmp(cached->sname, section, cached->snamelen) == 0)) {
#ifdef CONFIG_INTERNAL
		printf("Found %s cached\n", cached->sname);
#endif
		return cached;
	}

	SectionListIter it = section_list.begin(), it_end = section_list.end();
	for (; it != it_end; ++it) {
		ConfigSection *cs = *it;
		if (cs->shash == hh && (strncmp(cs->sname, section, cs->snamelen) == 0)) {
#ifdef CONFIG_INTERNAL
			printf("XXX found: %s\n", cs->sname);
#endif
			cached = cs;
			return cs;
		}
	}
	return NULL;
}
开发者ID:edeproject,项目名称:svn,代码行数:30,代码来源:Config.cpp

示例13: E_ASSERT

/*
 * ConfigSection methods
 */
ConfigSection::ConfigSection(const char* n) {
	E_ASSERT(n != NULL);

	snamelen = strlen(n);
	sname = strdup(n);
	shash = do_hash(sname, snamelen);
}
开发者ID:edeproject,项目名称:svn,代码行数:10,代码来源:Config.cpp

示例14: st_insert2

int
st_insert2(register st_table *table, register st_data_t key, st_data_t value,
	   st_data_t (*func)(st_data_t))
{
    st_index_t hash_val;
    register st_index_t bin_pos;
    register st_table_entry *ptr;

    hash_val = do_hash(key, table);

    if (table->entries_packed) {
	st_index_t i = find_packed_index(table, hash_val, key);
	if (i < table->real_entries) {
	    PVAL_SET(table, i, value);
	    return 1;
	}
	key = (*func)(key);
	add_packed_direct(table, key, value, hash_val);
	return 0;
    }

    FIND_ENTRY(table, ptr, hash_val, bin_pos);

    if (ptr == 0) {
	key = (*func)(key);
	add_direct(table, key, value, hash_val, bin_pos);
	return 0;
    }
    else {
	ptr->record = value;
	return 1;
    }
}
开发者ID:sho-h,项目名称:ruby,代码行数:33,代码来源:st.c

示例15: string_hash

int string_hash(lua_State* L)
{
	const char* str = luaL_checkstring(L, 1);
	int seed = (int)luaL_optinteger(L, 2, 0);
	lua_pushinteger(L, do_hash(str, seed));
	return 1;
}
开发者ID:dcourtois,项目名称:premake-core,代码行数:7,代码来源:string_hash.c


注:本文中的do_hash函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。