• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ djb2_hash函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: djb2_hash

void GlobalGroupFlag::AddFlag(const char *flag_id)
{
	const unsigned int hash_id = djb2_hash((unsigned char *) flag_id);

	std::multimap<const unsigned int, FlagAccessSwitch, ltint>::iterator p;
	flag_list.insert(std::make_pair(hash_id, FlagAccessSwitch(flag_id, true)));
}
开发者ID:imyzcn,项目名称:mani-admin-plugin,代码行数:7,代码来源:mani_client_util.cpp


示例2: pk_send

int
pk_send(int id, Packet * pckt, int nbytes)
{
	int n, len;
	struct sockaddr * addr;

	UdpPacket udp_pckt;
	memcpy(&(udp_pckt.pckt), pckt, sizeof(Packet));
	udp_pckt.checksum = djb2_hash((char *) pckt, sizeof(Packet));	

	if (id == SRV_ID) { // sending from client to server
		addr = (struct sockaddr *) &srvaddr;
		len = sizeof srvaddr;
	} else { // sending from server to client
		addr = (struct sockaddr *) &cliaddr;
		len = sizeof cliaddr;
	}

	n = sendto(sockfd, &udp_pckt, sizeof udp_pckt, 0, addr, len);
	if (n == -1) {
		printf("Error sending packet.\n");
		return -1;
	}

	return n;
}
开发者ID:tomidelucca,项目名称:TP1-SO,代码行数:26,代码来源:comm.c


示例3: main

int main(void)
{
    gnrc_netreg_entry_t ne;

    uint8_t cpuid[CPUID_LEN];
    cpuid_get(cpuid);
    conn_test_id = djb2_hash(cpuid, CPUID_LEN);
    random_init(conn_test_id);

    ne.pid = thread_create(_stack, sizeof(_stack), THREAD_PRIORITY_MAIN - 1,
                             THREAD_CREATE_STACKTEST, _listener, NULL,
                             "listener");

    ne.demux_ctx = GNRC_NETREG_DEMUX_CTX_ALL;
    gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &ne);

    puts("Connectivity Test program!");
    printf("MY ID: %08lX\n", (unsigned long) conn_test_id);
    unsigned res = CONN_TEST_CHAN;
    if (gnrc_netapi_set(CONN_TEST_NETIF, NETOPT_CHANNEL, 0, (uint16_t *)&res, sizeof(uint16_t)) < 0) {
        puts("main: error setting channel");
    }

    unsigned int addr_len = 8;
    if (gnrc_netapi_set(CONN_TEST_NETIF, NETOPT_SRC_LEN, 0, (uint16_t *)&addr_len, sizeof(uint16_t)) < 0) {
        printf("main: error setting addressing mode\n");
    }
    xtimer_set_msg(&ct_timer, (SEC_IN_USEC * 3) + (random_uint32() & 0x001FFFFF), &ct_m, ne.pid);

    char line_buf[SHELL_DEFAULT_BUFSIZE];
    shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
    return 0;
}
开发者ID:OlegHahm,项目名称:miniature-dangerzone,代码行数:33,代码来源:main.c


示例4: djb2_hash

bool CharacterDB::del_name_validation_set( uint32 characterID )
{
	CharIdNameMapItr helper_itr = mIdNameContainer.find(characterID);

	/* if we are unable to find the entry... return.
	 * @note we do risk keeping the name in the name validation. 
	 * which I am willing to take.
	 */
	if (helper_itr == mIdNameContainer.end())
		return false;

	const char* name = helper_itr->second.c_str();
	if (name == NULL || *name == '\0')
		return false;

	uint32 hash = djb2_hash(name);

	CharValidationSetItr name_itr = mNameValidation.find(hash);
	if (name_itr != mNameValidation.end())
	{
		// we found the name hash... deleting
		mNameValidation.erase(name_itr);
		mIdNameContainer.erase(helper_itr);
		return true;
	}
	else
	{
		/* normally this should never happen... */
		printf("CharacterDB::del_name_validation_set: unable to remove: %s as its not in the set", name);
		return false;
	}
}
开发者ID:adam3696,项目名称:evemu_apocrypha,代码行数:32,代码来源:CharacterDB.cpp


示例5: codelog

void CharacterDB::load_name_validation_set()
{
	DBQueryResult res;
	if(!sDatabase.RunQuery(res,
		"SELECT"
		" characterID, itemName AS characterName"
		" FROM character_"
		"	JOIN entity ON characterID = itemID"
		))
	{
		codelog(SERVICE__ERROR, "Error in query for %s", res.error.c_str());
		return;
	}

	DBResultRow row;
	while(res.GetRow(row) == true)
	{
		uint32 characterID = row.GetUInt(0);
		const char* name = row.GetText(1);

		//printf("initializing name validation: %s\n", name);
		uint32 hash = djb2_hash(name);

		mNameValidation.insert(hash);
		mIdNameContainer.insert(std::make_pair(characterID, name));
	}
}
开发者ID:adam3696,项目名称:evemu_apocrypha,代码行数:27,代码来源:CharacterDB.cpp


示例6: pk_receive

int
pk_receive(int id, Packet * pckt, int nbytes)
{
	int n, len;
	struct sockaddr * addr;

	UdpPacket udp_pckt;
	
	if (id != SRV_ID) { // client receiving
		len = sizeof srvaddr;
		addr = (struct sockaddr *) &srvaddr;
	} else { // server receiving
		len = sizeof cliaddr;
		addr = (struct sockaddr *) &cliaddr;
	}

	n = recvfrom(sockfd, &udp_pckt, sizeof udp_pckt, 0, addr, (socklen_t *) &len);
	if (n == -1) {
		printf("Error receiving packet.\n");
		return -1;
	}

	unsigned long checksum;
	checksum = djb2_hash((char *) &(udp_pckt.pckt), sizeof(Packet));
	if (checksum == udp_pckt.checksum) {
		memcpy(pckt, &(udp_pckt.pckt), sizeof(Packet));
	} else {
		return -1;
	}

	return n;
}
开发者ID:tomidelucca,项目名称:TP1-SO,代码行数:32,代码来源:comm.c


示例7: djb2_hash

int snippet_library::add_snippet( const std::string &category, const std::string &text )
{
    int hash = djb2_hash( ( const unsigned char * )text.c_str() );
    snippets.insert( std::pair<int, std::string>( hash, text ) );
    categories.insert( std::pair<std::string, int>( category, hash ) );
    return hash;
}
开发者ID:BevapDin,项目名称:Cataclysm-DDA,代码行数:7,代码来源:text_snippets.cpp


示例8: __get_bucket_addr

/* Finds the address where the pointer should be (whether or not it is there)
 * So that we can add it if we want
 * returns 0 if it exists, 1 otherwise
 */
static int __get_bucket_addr(hash h, char* key, bucket** ret) {
    char* lower_key = str_to_lower(key);
    unsigned int i = djb2_hash(lower_key) % (h -> size);
    free(lower_key);
    int found = 0;
    bucket* it = &(h -> table)[i];
    bucket* head = it;

    // try to find it in the current bucket
    while(*it && !found) {
        if( strcasecmp( (*it) -> key, key) == 0 )
            found = 1;
        else
            it = &( (*it) -> next );
    }

    // if we found a bucket, we need to return it
    if(*it)
        *ret = it;
    else
        *ret = head; // otherwise return where it should be (head of the bucket)

    // returning the flag
    return found;
}
开发者ID:frmendes,项目名称:uminho,代码行数:29,代码来源:hash.c


示例9: djb2_hash

const struct macro *definition(struct token name)
{
    struct macro *ref;
    unsigned long hash, pos;

    if (name.token != IDENTIFIER)
        return NULL;

    hash = djb2_hash(name.strval);
    pos = hash % HASH_TABLE_LENGTH;
    ref = &macro_hash_table[pos];
    if (!ref->name.strval) {
        return NULL;
    }

    while ((ref->hash.val != hash || strcmp(ref->name.strval, name.strval)) &&
            ref->hash.next)
        ref = ref->hash.next;

    if (ref->hash.val == hash && !strcmp(ref->name.strval, name.strval)) {
        if (!strcmp(ref->name.strval, "__LINE__")) {
            ref->replacement[0].token.intval = current_file.line;
        }
        return ref;
    }

    return NULL;
}
开发者ID:JamesLinus,项目名称:c-compiler,代码行数:28,代码来源:macro.c


示例10: stringHashDjb2

/* adrpo: see the comment above about djb2 hash */
modelica_integer stringHashDjb2(metamodelica_string_const s)
{
  const char* str = MMC_STRINGDATA(s);
  long res = djb2_hash((const unsigned char*)str);
  res = labs(res);
  /* fprintf(stderr, "stringHashDjb2 %s-> %ld %ld %ld\n", str, res, mmc_mk_icon(res), mmc_unbox_integer(mmc_mk_icon(res))); */
  return res;
}
开发者ID:AntonDV235,项目名称:OMCompiler,代码行数:9,代码来源:meta_modelica_builtin.c


示例11: _

void snippet_library::load_snippet(JsonObject &jsobj)
{
    std::string category = jsobj.get_string("category");
    std::string text = _(jsobj.get_string("text").c_str());
    int hash = djb2_hash( (const unsigned char*)text.c_str() );

    snippets.insert( std::pair<int, std::string>(hash, text) );
    categories.insert( std::pair<std::string, int>(category, hash) );
}
开发者ID:8Z,项目名称:Cataclysm-DDA,代码行数:9,代码来源:text_snippets.cpp


示例12: relation_salt_cpp

static unsigned int relation_salt_cpp(const td_scanner *scanner)
{
	int i, count;
	unsigned int hash = 0;
	for (i = 0, count = scanner->path_count; i < count; ++i)
	{
		hash ^= (unsigned int) djb2_hash(scanner->include_paths[i]->path);
	}
	return hash;
}
开发者ID:greatwolf,项目名称:tundra,代码行数:10,代码来源:scanner.c


示例13: stringHashDjb2Mod

/* adrpo: see the comment above about djb2 hash */
modelica_integer stringHashDjb2Mod(metamodelica_string_const s, modelica_integer mod)
{
  const char* str = MMC_STRINGDATA(s);
  long res;
  if (mod == 0) {
    MMC_THROW();
  }
  res = djb2_hash((const unsigned char*)str) % (unsigned int) mod;
  res = labs(res);
  /* fprintf(stderr, "stringHashDjb2Mod %s %ld-> %ld %ld %ld\n", str, mod, res, mmc_mk_icon(res), mmc_unbox_integer(mmc_mk_icon(res))); */
  return res;
}
开发者ID:AntonDV235,项目名称:OMCompiler,代码行数:13,代码来源:meta_modelica_builtin.c


示例14: djb2_hash

entry *findName(char lastname[], entry *pHead[])
{
    unsigned long i;
    i = djb2_hash((unsigned char *)lastname)%SIZE_OF_TABLE;
    entry *e = pHead[i];

    while (e != NULL) {
        if (strcasecmp(lastname, e->lastName) == 0)
            return e;
        e = e->pNext;
    }
    return NULL;
}
开发者ID:apple11361,项目名称:homework1,代码行数:13,代码来源:phonebook_opt2.c


示例15: define

void define(struct macro macro)
{
    static int clean_on_exit;

    struct macro *ref;
    unsigned long
        hash = djb2_hash(macro.name.strval),
        pos = hash % HASH_TABLE_LENGTH;

    if (!clean_on_exit) {
        atexit(cleanup);
        clean_on_exit = 1;
    }

    ref = &macro_hash_table[pos];
    if (!ref->name.strval) {
        *ref = macro;
        ref->hash.val = hash;
        return;
    }

    while ((ref->hash.val != hash
            || strcmp(ref->name.strval, macro.name.strval)) && ref->hash.next)
        ref = ref->hash.next;

    if (ref->hash.val == hash && !strcmp(ref->name.strval, macro.name.strval)) {
        if (macrocmp(ref, &macro)) {
            error("Redefinition of macro '%s' with different substitution.",
                macro.name.strval);
            exit(1);
        }
        /* Already have this definition, but need to clean up memory that we
         * took ownership of. */
        if (macro.size) {
            free(macro.replacement);
        }
        return;
    }

    assert(!ref->hash.next);
    ref->hash.next = calloc(1, sizeof(*ref));
    ref = ref->hash.next;
    *ref = macro;
    ref->hash.val = hash;
}
开发者ID:JamesLinus,项目名称:c-compiler,代码行数:45,代码来源:macro.c


示例16: undef

void undef(struct token name)
{
    struct macro *ref, *prev;
    unsigned long hash, pos;

    if (name.token != IDENTIFIER)
        return;

    hash = djb2_hash(name.strval);
    pos = hash % HASH_TABLE_LENGTH;
    ref = &macro_hash_table[pos];
    prev = ref;
    if (!ref->name.strval) {
        return;
    }

    /* Special case if found in static buffer. */
    if (ref->hash.val == hash && !strcmp(ref->name.strval, name.strval)) {
        prev = ref->hash.next;
        if (ref->replacement)
            free(ref->replacement);
        memset(ref, 0, sizeof(*ref));
        if (prev) {
            *ref = *prev;
            free(prev);
        }
        return;
    }

    /* Get pointer to match, and predecessor. */
    while ((ref->hash.val != hash || strcmp(ref->name.strval, name.strval))
            && ref->hash.next)
    {
        prev = ref;
        ref = ref->hash.next;
    }

    /* Remove node in middle of list. */
    if (ref->hash.val == hash && !strcmp(ref->name.strval, name.strval)) {
        assert(ref != prev);
        prev->hash.next = ref->hash.next;
        hash_node_free(ref);
    }
}
开发者ID:JamesLinus,项目名称:c-compiler,代码行数:44,代码来源:macro.c


示例17: append

void append(entry *pHead[],char lastName[])
{
    entry *e;
    unsigned long i;
    i = djb2_hash((unsigned char *)lastName)%SIZE_OF_TABLE;

    if(pHead[i]==NULL) {
        pHead[i] = (entry *) malloc(sizeof(entry));
        pHead[i]->pNext = NULL;
        strcpy(pHead[i]->lastName,lastName);
        pHead[i]->pDetail = NULL;
    } else {
        for(e=pHead[i]; e->pNext!=NULL; e=e->pNext);
        e->pNext = (entry *) malloc(sizeof(entry));
        e = e->pNext;
        strcpy(e->lastName, lastName);
        e->pNext = NULL;
        e->pDetail = NULL;

    }
}
开发者ID:apple11361,项目名称:homework1,代码行数:21,代码来源:phonebook_opt2.c


示例18: throw

void snippet_library::load() throw (std::string)
{
    catajson snippetRaw("data/raw/snippets.json");

    if(!json_good())
    	throw (std::string)"Could not read data/raw/snippets.json";

    catajson snippetList = snippetRaw.get("snippets");
    for( snippetList.set_begin(); snippetList.has_curr(); snippetList.next() )
    {
        const catajson curr = snippetList.curr();
        // required fields
        const std::string category = curr.get("category").as_string();
        const std::string text = curr.get("text").as_string();
        const int hash = djb2_hash( (const unsigned char*)text.c_str() );

        snippets.insert( std::pair<int, std::string>(hash, text) );
        categories.insert( std::pair<std::string, int>(category, hash) );
    }
    if(!json_good())
        throw (std::string)"There was an error reading data/raw/snippets.json";
}
开发者ID:TarikMechEng,项目名称:Cataclysm-DDA,代码行数:22,代码来源:text_snippets.cpp


示例19: hash_index

static int hash_index(hash_table_t * hash, const char *key)
{
    return djb2_hash((const unsigned char *)key) % hash->n_buckets;
}
开发者ID:HulaBurger,项目名称:opkg,代码行数:4,代码来源:hash_table.c


示例20: WinMain

int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
 int argc = __argc;
 char **argv = __argv;
#else
int main(int argc, char *argv[])
{
#endif
#ifdef ENABLE_LOGGING
  setupDebug();
#endif
 int seed = time(NULL);

// set locale to system default
 setlocale(LC_ALL, "");
#ifdef LOCALIZE
 bindtextdomain("cataclysm-dda", "lang/mo");
 bind_textdomain_codeset("cataclysm-dda", "UTF-8");
 textdomain("cataclysm-dda");
#endif

//args: world seeding only.
 argc--; argv++;
 while (argc){
  if(std::string(argv[0]) == "--seed"){
   argc--; argv++;
   if(argc){
    seed = djb2_hash((unsigned char*)argv[0]);
    argc--; argv++;
   }
  }
  else // ignore unknown args.
   argc--; argv++;
 }

// ncurses stuff
 initOptions();
 load_options(); // For getting size options
 initscr(); // Initialize ncurses
 #ifdef SDLTILES
 init_tiles();
 #endif // SDLTILES
 noecho();  // Don't echo keypresses
 cbreak();  // C-style breaks (e.g. ^C to SIGINT)
 keypad(stdscr, true); // Numpad is numbers
 init_colors(); // See color.cpp
// curs_set(0); // Invisible cursor
 set_escdelay(10); // Make escape actually responsive

 std::srand(seed);

 bool quit_game = false;
 g = new game;
 g->init_data();
 if(g->game_error())
  exit_handler(-999);
 g->init_ui();
 MAPBUFFER.set_game(g);
 if(g->game_error())
  exit_handler(-999);

 curs_set(0); // Invisible cursor here, because MAPBUFFER.load() is crash-prone

 #if (!(defined _WIN32 || defined WINDOWS))
  struct sigaction sigIntHandler;
  sigIntHandler.sa_handler = exit_handler;
  sigemptyset(&sigIntHandler.sa_mask);
  sigIntHandler.sa_flags = 0;
  sigaction(SIGINT, &sigIntHandler, NULL);
 #endif

 do {
  if(!g->opening_screen()) {
     quit_game = true;
  }
  while (!g->do_turn()) ;
  if (g->game_quit() || g->game_error())
   quit_game = true;
 } while (!quit_game);


 exit_handler(-999);

 return 0;
}
开发者ID:GlyphGryph,项目名称:Cataclysm-DDA,代码行数:85,代码来源:main.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ dkcksum函数代码示例发布时间:2022-05-30
下一篇:
C++ dixSetPrivate函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap