本文整理汇总了C++中HASH_ADD_KEYPTR函数的典型用法代码示例。如果您正苦于以下问题:C++ HASH_ADD_KEYPTR函数的具体用法?C++ HASH_ADD_KEYPTR怎么用?C++ HASH_ADD_KEYPTR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HASH_ADD_KEYPTR函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: springfield_set_i
static void springfield_set_i(springfield_t *r, char *key, uint8_t *val, uint32_t vlen) {
int klen = strlen(key) + 1;
assert(klen < MAX_KLEN);
assert(vlen < MAX_VLEN);
uint32_t step = HEADER_SIZE + klen + vlen;
springfield_header_v1 h = {0};
h.klen = klen;
h.vlen = vlen;
h.version = 1;
if (r->in_rewrite) {
springfield_key_t *kobj = NULL;
HASH_FIND(hh, r->rewrite_keys, key, klen, kobj);
if (!kobj) {
kobj = calloc(1, sizeof(springfield_key_t));
kobj->key = strdup(key);
HASH_ADD_KEYPTR(hh, r->rewrite_keys, key, klen, kobj);
}
}
if (r->eof + step > r->mmap_alloc) {
msync(r->map, r->mmap_alloc, MS_SYNC);
int s = munmap(r->map, r->mmap_alloc);
assert(!s);
uint64_t new_size = r->mmap_alloc + ((r->eof + step) * 2);
r->mmap_alloc = new_size;
s = ftruncate(r->mapfd, (off_t)r->mmap_alloc);
assert(!s);
r->map = (uint8_t *)mmap(
NULL, r->mmap_alloc, PROT_READ | PROT_WRITE, MAP_SHARED, r->mapfd, 0);
/* TODO mremap() on linux */
s = madvise(r->map, r->mmap_alloc, MADV_RANDOM);
assert(!s);
}
h.last = springfield_index_keyval(r, key, r->eof);
uint8_t *p = &r->map[r->eof];
springfield_header_v1 *ph = (springfield_header_v1 *)p;
*ph = h;
memmove(p + HEADER_SIZE, key, klen);
if (vlen)
memmove(p + HEADER_SIZE + klen, val, vlen);
ph->crc = crc32(0, p + 4, HEADER_SIZE_MINUS_CRC + klen + vlen);
r->eof += step;
}
开发者ID:jamwt,项目名称:springfield,代码行数:51,代码来源:springfield.c
示例2: symbol_insert
void symbol_insert(const char* name, LLVMValueRef val, int isArg)
{
struct symbol_info *si;
if (head==NULL)
return;
si = (struct symbol_info*) malloc(sizeof(struct symbol_info));
si->name = (char*)name;
si->isArg = isArg;
si->val = val;
HASH_ADD_KEYPTR( hh, head->map, name, strlen(name), si );
}
开发者ID:FeifeiWang7,项目名称:ECE566,代码行数:14,代码来源:symbol.c
示例3: listen_device_if_not_present
static void listen_device_if_not_present(const char *devnode)
{
struct hash_element *same_elem = NULL;
HASH_FIND_STR(fdhash, devnode, same_elem);
if (same_elem) {
return;
}
struct hash_element *elem = hash_element_from_devnode(devnode);
if (!elem) {
return;
}
HASH_ADD_KEYPTR(hh, fdhash, elem->devnode, strlen(elem->devnode), elem);
FD_SET(elem->fd, &evdevfds);
}
开发者ID:gentoo-root,项目名称:jacklistener,代码行数:14,代码来源:watchdevs.c
示例4: olsr_db_ns_gcneigh
olsr_db_ns_tuple_t* olsr_db_ns_gcneigh(uint8_t neighbor_main_addr[ETH_ALEN]) {
olsr_db_ns_tuple_t* tuple;
HASH_FIND(hh, neighbor_set, neighbor_main_addr, ETH_ALEN, tuple);
if(tuple == NULL) {
if(ntuple_create(&tuple, neighbor_main_addr) == false) {
return false;
}
HASH_ADD_KEYPTR(hh, neighbor_set, tuple->neighbor_main_addr, ETH_ALEN, tuple);
}
return tuple;
}
开发者ID:Dekue,项目名称:des-routing-algorithms,代码行数:14,代码来源:neighbor_set.c
示例5: fcitx_handler_table_key_struct
static FcitxHandlerKey*
fcitx_handler_table_key_struct(FcitxHandlerTable *table, size_t keysize,
const void *key, boolean create)
{
FcitxHandlerKey *key_struct = NULL;
HASH_FIND(hh, table->keys, key, keysize, key_struct);
if (key_struct || !create)
return key_struct;
key_struct = malloc(sizeof(FcitxHandlerKey) + keysize);
key_struct->first = key_struct->last = FCITX_OBJECT_POOL_INVALID_ID;
memcpy(key_struct + 1, key, keysize);
key = key_struct + 1;
HASH_ADD_KEYPTR(hh, table->keys, key, keysize, key_struct);
return key_struct;
}
开发者ID:adaptee,项目名称:fcitx,代码行数:15,代码来源:handler-table.c
示例6: frequencies_hash_to_bins
struct document_frequencies_hash* frequencies_hash_to_bins(struct score_hash *scores) {
struct score_hash *s;
struct document_frequencies_hash *tmp, *bins_hash = NULL;
int bin_index = 0;
HASH_SORT(scores, ascending_score_sort);
for(s=scores; s != NULL; s = s->hh.next) {
if (s->score >= 10.5) { break; } // Filter >4 frequent words
tmp = (struct document_frequencies_hash*)malloc(sizeof(struct document_frequencies_hash));
tmp->word = strdup(s->word);
tmp->count = ++bin_index;
HASH_ADD_KEYPTR( hh, bins_hash, tmp->word, strlen(tmp->word), tmp );
}
fprintf(stderr, "Total bins: %d\n",bin_index);
return bins_hash;
}
开发者ID:KWARC,项目名称:deprecated-LLaMaPUn,代码行数:15,代码来源:parallel_libsvm_input_occurence.c
示例7: pkg_update_increment_item_new
static void
pkg_update_increment_item_new(struct pkg_increment_task_item **head, const char *origin,
const char *digest, long offset)
{
struct pkg_increment_task_item *item;
item = calloc(1, sizeof(struct pkg_increment_task_item));
item->origin = strdup(origin);
if (digest == NULL)
digest = "";
item->digest = strdup(digest);
item->offset = offset;
HASH_ADD_KEYPTR(hh, *head, item->origin, strlen(item->origin), item);
}
开发者ID:renchap,项目名称:pkg,代码行数:15,代码来源:update.c
示例8: getTextureID
Texture*
getTextureID(char* path) {
Texture *s;
HASH_FIND_STR( pathToTexTable, path, s ); /* s: output pointer */
if(s == NULL) {
s = (Texture*)malloc(sizeof(Texture));
s->path = (char*)malloc(strlen(path)*sizeof(char));
strcpy(s->path, path);
s->textureID = ilutGLLoadImage(path);
s->width = ilGetInteger(IL_IMAGE_WIDTH);
s->height = ilGetInteger(IL_IMAGE_HEIGHT);
HASH_ADD_KEYPTR( hh, pathToTexTable, s->path, strlen(s->path), s );
}
return s;
}
开发者ID:catdawg,项目名称:Ez2DS,代码行数:15,代码来源:Ez2DSDebugDraw.c
示例9: load_module
Module load_module(char *mn) {
char *modname = malloc(sizeof(char)*768);
snprintf(modname, 767, "%s/%s.so", DPATH "/modules", mn);
int (*mod_init)();
void *modhand;
struct loaded_module *mod = malloc(sizeof(struct loaded_module));
modhand = mod->hand = dlopen(modname, RTLD_LAZY);
mod->name = strdup(mn);
if (modhand == NULL) exit(64);
mod_init = (int (*)())dlsym(modhand, "mod_init");
if (mod_init) (*mod_init)();
else exit(65);
HASH_ADD_KEYPTR(hh, mods, mod->name, strlen(mod->name), mod);
return mod;
};
开发者ID:asterIRC,项目名称:troutfin,代码行数:15,代码来源:module.c
示例10: pkg_repo_overwrite
static void
pkg_repo_overwrite(struct pkg_repo *r, const char *name, const char *url,
const char *type)
{
free(r->name);
r->name = strdup(name);
if (url != NULL) {
free(r->url);
r->url = strdup(url);
}
r->ops = pkg_repo_find_type(type);
HASH_DEL(repos, r);
HASH_ADD_KEYPTR(hh, repos, r->name, strlen(r->name), r);
}
开发者ID:dumbbell,项目名称:pkg,代码行数:15,代码来源:pkg_config.c
示例11: LoadPuncDict
/**
* 加载标点词典
* @param void
* @return void
* @note 文件中数据的格式为: 对应的英文符号 中文标点 <中文标点>
* 加载标点词典。标点词典定义了一组标点转换,如输入‘.’就直接转换成‘。’
*/
boolean LoadPuncDict(FcitxPuncState* puncState)
{
FcitxStringHashSet* puncfiles = FcitxXDGGetFiles("data", PUNC_DICT_FILENAME "." , NULL);
FcitxStringHashSet *curpuncfile = puncfiles;
FcitxPunc* punc;
while (curpuncfile) {
punc = LoadPuncFile(curpuncfile->name);
if (punc)
HASH_ADD_KEYPTR(hh, puncState->puncSet, punc->langCode, strlen(punc->langCode), punc);
curpuncfile = curpuncfile->hh.next;
}
fcitx_utils_free_string_hash_set(puncfiles);
return true;
}
开发者ID:adaptee,项目名称:fcitx,代码行数:22,代码来源:punc.c
示例12: LoadImage
SkinImage* LoadImage(FcitxSkin* sc, const char* name, boolean fallback)
{
cairo_surface_t *png = NULL;
SkinImage *image = NULL;
HASH_FIND_STR(sc->imageTable, name, image);
if (image != NULL) {
return image;
}
if (strlen(name) > 0 && strcmp(name , "NONE") != 0) {
char *skintype = strdup(*sc->skinType);
char *filename;
while (true) {
char* buf = NULL;
asprintf(&buf, "skin/%s", skintype);
FILE* fp = FcitxXDGGetFileWithPrefix(buf, name, "r", &filename);
free(buf);
Bool flagNoFile = (fp == NULL);
if (fp) {
fclose(fp);
png = cairo_image_surface_create_from_png(filename);
break;
}
if (flagNoFile && (!fallback || strcmp(skintype, "default") == 0)) {
png = NULL;
break;
}
free(filename);
free(skintype);
skintype = strdup("default");
}
free(filename);
free(skintype);
}
if (png != NULL) {
image = fcitx_utils_malloc0(sizeof(SkinImage));
image->name = strdup(name);
image->image = png;
HASH_ADD_KEYPTR(hh, sc->imageTable, image->name, strlen(image->name), image);
return image;
}
return NULL;
}
开发者ID:niubenben,项目名称:fcitx,代码行数:48,代码来源:skin.c
示例13: LoadImageWithText
SkinImage* LoadImageWithText(FcitxClassicUI* classicui, FcitxSkin* sc, const char* name, const char* text, int w, int h, boolean active)
{
if (!text || *text == '\0')
return NULL;
UnloadSingleImage(sc, name);
int len = fcitx_utf8_char_len(text);
if (len == 1 && text[len] && fcitx_utf8_char_len(text + len) == 1)
len = 2;
char* iconText = strndup(text, len);
FcitxLog(DEBUG, "%s", iconText);
cairo_surface_t* newsurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
cairo_t* c = cairo_create(newsurface);
int min = w > h? h: w;
min = min * 0.8;
cairo_set_operator(c, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgba(c ,1, 1, 1, 0.0);
cairo_paint(c);
FcitxConfigColor color;
if (sc->skinMainBar.bUseCustomTextIconColor) {
if (active)
color = sc->skinMainBar.textIconColor[0];
else
color = sc->skinMainBar.textIconColor[1];
}
else
color = sc->skinFont.menuFontColor[1];
int textw, texth;
StringSizeStrict(iconText, classicui->font, min, false, &textw, &texth);
OutputString(c, iconText, classicui->font, min, false, (w - textw) * 0.5, 0, &color);
cairo_destroy(c);
SkinImage* image = fcitx_utils_malloc0(sizeof(SkinImage));
image->name = strdup(name);
image->image = newsurface;
image->textIcon = true;
HASH_ADD_KEYPTR(hh, sc->imageTable, image->name, strlen(image->name), image);
return image;
}
开发者ID:areslp,项目名称:fcitx,代码行数:48,代码来源:skin.c
示例14: loadFile
void loadFile( FILE *fp ) {
char buf[BUFFER_SIZE];
char *token;
const char *delimeter_chars = " \n";
frequencyListNode *ptr = NULL;
hashNode *curr_hashNode = (hashNode *)malloc( sizeof( hashNode ) );
while ( fgets( buf, BUFFER_SIZE, fp ) != NULL ) {
token = strtok( buf, delimeter_chars ); /* Stores the first <list> */
while ( token != NULL ) {
if ( strcmp( token, "<list>" ) == 0 ) {
token = strtok( NULL, delimeter_chars ); /* Stores the word in reference of the list */
curr_hashNode->word = (char *)malloc( sizeof( char ) * strlen( token ) + 1 );
strcpy( curr_hashNode->word, token );
}
else if ( strcmp( token, "</list>" ) == 0 ) {
/* Add the built list to the hashtable */
HASH_ADD_KEYPTR( hh, inverted_index, curr_hashNode->word, strlen( curr_hashNode->word ), curr_hashNode );
curr_hashNode = (hashNode *)malloc( sizeof( hashNode ) );
}
else {
ptr = (frequencyListNode *)malloc( sizeof( frequencyListNode ) );
ptr->file_path = (char *)malloc( sizeof( char ) * strlen( token ) + 1 );
strcpy( ptr->file_path, token );
token = strtok( NULL, delimeter_chars ); /*Now holds the frequency of the word in previous file */
ptr->frequency = 0;
ptr->next = curr_hashNode->head;
curr_hashNode->head = ptr;
}
token = strtok( NULL, delimeter_chars );
}
}
free( curr_hashNode );
}
开发者ID:kdharsee,项目名称:Search,代码行数:46,代码来源:search.c
示例15: pkg_repo_new
static struct pkg_repo *
pkg_repo_new(const char *name, const char *url)
{
struct pkg_repo *r;
r = calloc(1, sizeof(struct pkg_repo));
r->type = REPO_BINARY_PKGS;
r->update = repo_update_binary_pkgs;
r->url = strdup(url);
r->signature_type = SIG_NONE;
r->mirror_type = NOMIRROR;
r->enable = true;
asprintf(&r->name, REPO_NAME_PREFIX"%s", name);
HASH_ADD_KEYPTR(hh, repos, r->name, strlen(r->name), r);
return (r);
}
开发者ID:rottenbytes,项目名称:pkg,代码行数:17,代码来源:pkg_config.c
示例16: malloc
struct mod_function *add_cb(char *mod, char *cbn, char *cbsym) {
Module modu = NULL;
ModFunc modf = malloc(sizeof(struct mod_function));
HASH_FIND_STR(mods, mod, modu);
if (modu != NULL) {
int (*func)() = dlsym(modu->hand, cbsym);
if (!func) return NULL;
HASH_FIND_STR(modu->funcs, cbn, modf);
if (modf == NULL) {
modf->cb = cbn;
modf->func = &func;
HASH_ADD_KEYPTR(hh, modu->funcs, modf->cb, strlen(modf->cb), modf);
return modf;
}
}
return NULL;
};
开发者ID:asterIRC,项目名称:troutfin,代码行数:17,代码来源:module.c
示例17: pkg_repo_new
static struct pkg_repo *
pkg_repo_new(const char *name, const char *url, const char *type)
{
struct pkg_repo *r;
r = calloc(1, sizeof(struct pkg_repo));
r->ops = pkg_repo_find_type(type);
r->url = strdup(url);
r->signature_type = SIG_NONE;
r->mirror_type = NOMIRROR;
r->enable = true;
r->meta = pkg_repo_meta_default();
r->name = strdup(name);
HASH_ADD_KEYPTR(hh, repos, r->name, strlen(r->name), r);
return (r);
}
开发者ID:dumbbell,项目名称:pkg,代码行数:17,代码来源:pkg_config.c
示例18: pkg_repo_binary_update_item_new
static void
pkg_repo_binary_update_item_new(struct pkg_increment_task_item **head, const char *origin,
const char *digest, long offset, long length, const char *checksum)
{
struct pkg_increment_task_item *item;
item = calloc(1, sizeof(struct pkg_increment_task_item));
item->origin = strdup(origin);
if (digest == NULL)
digest = "";
item->digest = strdup(digest);
item->offset = offset;
item->length = length;
if (checksum)
item->checksum = strdup(checksum);
HASH_ADD_KEYPTR(hh, *head, item->origin, strlen(item->origin), item);
}
开发者ID:zxombie,项目名称:pkg,代码行数:18,代码来源:update.c
示例19: addInternedString
/**
* Adds a string to the cache of interned string. The string must not already be
* interned. The internedStringsLock MUST be held when calling this function.
*/
static jboolean addInternedString(Env* env, const char* s, Object* string) {
CacheEntry* cacheEntry = allocateMemoryOfKind(env, sizeof(CacheEntry), cacheEntryGCKind);
if (!cacheEntry) {
return FALSE;
}
cacheEntry->key = s;
cacheEntry->string = string;
HASH_ADD_KEYPTR(hh, internedStrings, cacheEntry->key, strlen(cacheEntry->key), cacheEntry);
// prune the cache to MAX_CACHE_SIZE
if (HASH_COUNT(internedStrings) >= MAX_CACHE_SIZE) {
CacheEntry* tmpEntry;
HASH_ITER(hh, internedStrings, cacheEntry, tmpEntry) {
// prune the first entry (loop is based on insertion order so this deletes the oldest item)
HASH_DELETE(hh, internedStrings, cacheEntry);
break;
}
开发者ID:Custard7,项目名称:robovm,代码行数:22,代码来源:string.c
示例20: CloudPinyinAddToCache
CloudPinyinCache* CloudPinyinAddToCache(FcitxCloudPinyin* cloudpinyin, const char* pinyin, char* string)
{
CloudPinyinCache* cacheEntry = fcitx_utils_malloc0(sizeof(CloudPinyinCache));
cacheEntry->pinyin = strdup(pinyin);
cacheEntry->str = strdup(string);
HASH_ADD_KEYPTR(hh, cloudpinyin->cache, cacheEntry->pinyin, strlen(cacheEntry->pinyin), cacheEntry);
/* if there is too much cached, remove the first one, though LRU might be a better algorithm */
if (HASH_COUNT(cloudpinyin->cache) > MAX_CACHE_ENTRY)
{
CloudPinyinCache* head = cloudpinyin->cache;
HASH_DEL(cloudpinyin->cache, cloudpinyin->cache);
free(head->pinyin);
free(head->str);
free(head);
}
return cacheEntry;
}
开发者ID:pkg-ime,项目名称:fcitx-cloudpinyin,代码行数:18,代码来源:cloudpinyin.c
注:本文中的HASH_ADD_KEYPTR函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论