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


C++ HASH_ADD_INT函数代码示例

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


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

示例1: HASH_FIND_INT

page_node *add_page(stored_object *object, uint32_t page_id)
{
    page_node *curr,*page;

    HASH_FIND_INT(global_page_table,&page_id,page);
    if(page)
    {
        printf("ERROR[add_page] Object %lu already contains page %d\n",page->object_id,page_id);
        return NULL;
    }

    object->size += PAGE_SIZE;
    if(object->pages == NULL)
    {
        page = allocate_new_page(object->id,page_id);
        HASH_ADD_INT(global_page_table, page_id, page); 
        object->pages = page;
        return object->pages;
    }
    for(curr=page=object->pages; page && page->page_id != page_id; curr=page,page=page->next)
        ;
    if(page)
    {
        printf("ERROR[add_page] Object %lu already contains page %d\n",page->object_id,page_id);
        return NULL;
    }

    page = allocate_new_page(object->id,page_id);
    HASH_ADD_INT(global_page_table, page_id, page); 
    curr->next = page;
    return curr->next;
}
开发者ID:bkreitch,项目名称:simulator,代码行数:32,代码来源:ftl_obj_strategy.c

示例2: main

int main() {
  item *i, *j, *items=NULL;
  int k;

  /* first item */
  k = 12345;
  i = (item*)malloc(sizeof(item));
  i->key = k; i->data = 0;
  HASH_ADD_INT(items,key,i);

  /* second item */
  k = 6789;
  i = (item*)malloc(sizeof(item));
  i->key = k; i->data = 0;
  HASH_ADD_INT(items,key,i);

  /* third item */
  k = 98765;
  i = (item*)malloc(sizeof(item));
  i->key = k; i->data = 0;
  HASH_ADD_INT(items,key,i);

  /* look them all up */
  k = 12345; HASH_FIND_INT(items, &k, j); if (j) printf("found %d\n",k);
  k = 6789;  HASH_FIND_INT(items, &k, j); if (j) printf("found %d\n",k);
  k = 98765; HASH_FIND_INT(items, &k, j); if (j) printf("found %d\n",k);

  /* delete them not the way we prefer but it works */
  for(j=items; j != NULL; j=(item*)j->hh.next) {
    printf("deleting %d\n", j->key);
    HASH_DEL(items,j);
  }
  return 0;
}
开发者ID:Agyar,项目名称:uthash,代码行数:34,代码来源:test23.c

示例3: mkparticle

int mkparticle(particle_kind_t kind, cpVect pos, cpVect impulse, double energy)
{
  particle_t* p = malloc(sizeof *p);
  if(p == NULL) {
    return -1; // bad malloc
  }
  cpSpace* space = current_space();
  cpBody* body = cpBodyNew(energy / 1000.0, particle_moi);
  cpShape* shape = cpCircleShapeNew(body, particle_r, cpvzero);

  cpBodySetUserData(body, p);
  cpShapeSetUserData(shape, p);
  cpSpaceAddBody(space, body);
  cpSpaceAddShape(space, shape);
  *p = (particle_t){
    .id = id,
    .kind = kind,
    .energy = energy,
    .life = energy,
    .body = body
  };
  HASH_ADD_INT(particles, id, p);

  return id++;
}
开发者ID:niksaak,项目名称:dame,代码行数:25,代码来源:particle.c

示例4: CCASSERT

void ActionManager::addAction(Action *pAction, Node *target, bool paused)
{
    CCASSERT(pAction != NULL, "");
    CCASSERT(target != NULL, "");

    tHashElement *pElement = NULL;
    // we should convert it to Object*, because we save it as Object*
    Object *tmp = target;
    HASH_FIND_INT(_targets, &tmp, pElement);
    if (! pElement)
    {
        pElement = (tHashElement*)calloc(sizeof(*pElement), 1);
        pElement->paused = paused;
        target->retain();
        pElement->target = target;
        HASH_ADD_INT(_targets, target, pElement);
    }

     actionAllocWithHashElement(pElement);
 
     CCASSERT(! ccArrayContainsObject(pElement->actions, pAction), "");
     ccArrayAppendObject(pElement->actions, pAction);
 
     pAction->startWithTarget(target);
}
开发者ID:KIngpon,项目名称:HXGame,代码行数:25,代码来源:CCActionManager.cpp

示例5: farray_create

/**
 * Return an array of prototypes labeled with cluster numbers
 * @param c cluster structure
 * @param a assignment of prototypes
 * @param p prototypes
 * @return rejected feature vectors
 */
farray_t *cluster_get_prototypes(cluster_t *c, assign_t *a, farray_t *p)
{
    int i;
    farray_t *n = farray_create("prototypes");
    count_t *hash = NULL, *entry;

    for (i = 0; i < a->len; i++) {
        /* Skip rejected clusters */
        if (!c->cluster[i])
            continue;

        /* Check if prototype has been added */
        int j = a->proto[i];
        HASH_FIND_INT(hash, &j, entry);
        if (entry)
            continue;

        /* Add new prototype */
        entry = malloc(sizeof(count_t));
        entry->label = j;
        HASH_ADD_INT(hash, label, entry);

        /* Add prototype */
        farray_add(n, fvec_clone(p->x[j]), cluster_get_name(c, i));
    }

    /* Delete hash table */
    while (hash) {
        entry = hash;
        HASH_DEL(hash, entry);
        free(entry);
    }

    return n;
}
开发者ID:JaonLin,项目名称:malheur,代码行数:42,代码来源:cluster.c

示例6: AllocDispatchIndex

static GLboolean AllocDispatchIndex(__GLXvendorInfo *vendor,
                                    const GLubyte *procName)
{
    __GLXdispatchIndexHash *pEntry = malloc(sizeof(*pEntry));
    if (!pEntry) {
        return GL_FALSE;
    }

    pEntry->procName = (GLubyte *)strdup((const char *)procName);
    if (!pEntry->procName) {
        free(pEntry);
        return GL_FALSE;
    }

    LKDHASH_WRLOCK(__glXPthreadFuncs, __glXDispatchIndexHash);
    pEntry->index = __glXNextUnusedHashIndex++;

    // Notify the vendor this is the index which should be used
    vendor->staticDispatch->
        glxvc.setDispatchIndex(procName, pEntry->index);

    HASH_ADD_INT(_LH(__glXDispatchIndexHash),
                 index, pEntry);
    LKDHASH_UNLOCK(__glXPthreadFuncs, __glXDispatchIndexHash);

    return GL_TRUE;
}
开发者ID:aritger,项目名称:libglvnd,代码行数:27,代码来源:libglxmapping.c

示例7: consolidate_gpos_single

bool consolidate_gpos_single(otfcc_Font *font, table_OTL *table, otl_Subtable *_subtable,
                             const otfcc_Options *options) {
	subtable_gpos_single *subtable = &(_subtable->gpos_single);
	gpos_single_hash *h = NULL;
	for (glyphid_t k = 0; k < subtable->length; k++) {
		if (!GlyphOrder.consolidateHandle(font->glyph_order, &subtable->items[k].target)) {
			logWarning("[Consolidate] Ignored missing glyph /%s.\n", subtable->items[k].target.name);
			continue;
		}
		gpos_single_hash *s;
		int fromid = subtable->items[k].target.index;
		HASH_FIND_INT(h, &fromid, s);
		if (s) {
			logWarning("[Consolidate] Detected glyph double-mapping about /%s.\n", subtable->items[k].target.name);
		} else {
			NEW(s);
			s->fromid = subtable->items[k].target.index;
			s->fromname = sdsdup(subtable->items[k].target.name);
			s->v = subtable->items[k].value;
			HASH_ADD_INT(h, fromid, s);
		}
	}

	HASH_SORT(h, gpos_by_from_id);
	iSubtable_gpos_single.clear(subtable);

	gpos_single_hash *s, *tmp;
	HASH_ITER(hh, h, s, tmp) {
		iSubtable_gpos_single.push(subtable,
		                           ((otl_GposSingleEntry){
		                               .target = Handle.fromConsolidated(s->fromid, s->fromname), .value = s->v,
		                           }));
开发者ID:anthrotype,项目名称:otfcc,代码行数:32,代码来源:gpos-single.c

示例8: h3m_add_oa_by_def

int h3m_add_oa_by_def(h3mlib_ctx_t ctx, const char *def, int *oa_index)
{
    struct H3M_OA_ENTRY *oa_entry = NULL;
    struct META_OA_HASH_ENTRY *oa_hash_entry = NULL;
    const struct H3M_OA_BODY *body = NULL;
    int oa_body_index = 0;

    if (NULL == (body = h3m_get_def_body(def, &oa_body_index))) {
        return 1;
    }

    *oa_index = ctx->h3m.oa.count++;
    ctx->h3m.oa.entries = realloc(ctx->h3m.oa.entries,
        sizeof(struct H3M_OA_ENTRY) * ctx->h3m.oa.count);
    oa_entry = &ctx->h3m.oa.entries[ctx->h3m.oa.count - 1];

    oa_entry->header.def_size = strlen(def);
    oa_entry->header.def = (uint8_t *)strdup(def);
    memcpy(&oa_entry->body, body, sizeof(struct H3M_OA_BODY));

    oa_hash_entry = calloc(1, sizeof(*oa_hash_entry));
    oa_hash_entry->def = strdup(def);
    oa_hash_entry->oa_body_index = oa_body_index;
    oa_hash_entry->oa_index = *oa_index;
    HASH_ADD_INT(ctx->meta.oa_hash, oa_body_index, oa_hash_entry);

    return 0;
}
开发者ID:Dergash,项目名称:homm3tools,代码行数:28,代码来源:h3mlib.c

示例9: bufnew

caryll_buffer *caryll_write_gsub_ligature_subtable(otl_subtable *_subtable) {
	caryll_buffer *buf = bufnew();
	subtable_gsub_ligature *subtable = &(_subtable->gsub_ligature);
	ligature_aggerator *h = NULL, *s, *tmp;
	uint16_t nLigatures = subtable->to->numGlyphs;
	for (uint16_t j = 0; j < nLigatures; j++) {
		int sgid = subtable->from[j]->glyphs[0].gid;
		HASH_FIND_INT(h, &sgid, s);
		if (!s) {
			NEW(s);
			s->gid = sgid;
			s->ligid = HASH_COUNT(h);
			HASH_ADD_INT(h, gid, s);
		}
	}
	HASH_SORT(h, by_gid);

	otl_coverage *startCoverage;
	NEW(startCoverage);
	startCoverage->numGlyphs = HASH_COUNT(h);
	NEW_N(startCoverage->glyphs, startCoverage->numGlyphs);

	uint16_t jj = 0;
	foreach_hash(s, h) {
		s->ligid = jj;
		startCoverage->glyphs[jj].gid = s->gid;
		startCoverage->glyphs[jj].name = NULL;
		jj++;
	}
开发者ID:jojoblack,项目名称:otfcc,代码行数:29,代码来源:gsub-ligature.c

示例10: main

int main(int argc,char *argv[]) {
    int i;
    example_user_t *user, *users=NULL, *altusers=NULL;

    /* create elements */
    for(i=0;i<1000;i++) {
        if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1);
        user->id = i;
        user->cookie = i*i;
        if (i<10) HASH_ADD_INT(users,id,user);
        HASH_ADD(alth,altusers,id,sizeof(int),user);
    }

    printf("sorting users ascending\n");
    HASH_SRT(hh,users,ascending_sort);
    for(user=users; user; user=(example_user_t*)user->hh.next)
      printf("user %d\n", user->id);

    printf("sorting altusers descending\n");
    HASH_SRT(alth,altusers,descending_sort);
    for(user=altusers; user; user=(example_user_t*)user->alth.next)
      printf("altuser %d\n", user->id);

    /* HASH_FSCK(hh,users); */
    /* HASH_FSCK(alth,altusers); */
   return 0;
}
开发者ID:RichardOpenGL,项目名称:Bohge_Engine,代码行数:27,代码来源:test19.c

示例11: init_new_client

client_t * init_new_client(agent_t *agent, uuid_t * uuid) 
{
	client_t *new_client; 	
	new_client = calloc(sizeof(client_t),1); 
   if(new_client == NULL) 
   { 
      printf("Malloc failed!\n"); 
      exit(1); 
   } 
   new_client->buffered_packet_table = NULL; 
   new_client->allowed_connections = 0; 
	new_client->agent_sock = calloc(sizeof(int) , agent->options.num_parallel_connections); 
	new_client->agent_side_event_info = calloc(sizeof(struct event_info_struct) ,agent->options.num_parallel_connections); 
   new_client->send_seq = 0; 
   new_client->recv_seq = 0; 


   new_client->agent_fd_poll = calloc(sizeof(char) , agent->options.num_parallel_connections); 
   new_client->num_parallel_connections = 0; 


   new_client->client_hash.client =  new_client; 
   gettimeofday(&new_client->client_hash.accept_start, NULL);
   if(uuid == NULL)
   {
      uuid_generate(new_client->client_hash.id);  
   } 
   else 
   {
      memcpy(new_client->client_hash.id, *uuid, sizeof(uuid_t)); 
   } 
      HASH_ADD_INT(agent->clients_hashes, id, (&new_client->client_hash)); 

	return new_client; 
}
开发者ID:aaronorosen,项目名称:sos-agent,代码行数:35,代码来源:network.c

示例12: adtn_socket_base

static int adtn_socket_base(const char *data_path)
{
	static int UID = 1;
	int sock_id = -1;
	int len;
	bunsock_s *identifier;

	++UID;
	HASH_FIND_INT( sockStore, &sock_id, identifier);
	if (identifier == NULL) {
		sock_id = UID;
		identifier = (bunsock_s *)calloc(1, sizeof(bunsock_s));
		identifier->id = sock_id;
		identifier->sopt.proc_flags = H_DESS | H_NOTF;
		identifier->sopt.block_flags = B_DEL_NP;
		identifier->sopt.lifetime = 100000; //this time is in seconds
		len = strlen(data_path) + 1;
		identifier->data_path = (char *)calloc(len, sizeof(char));
		strncpy(identifier->data_path, data_path, len);
		identifier->bdata = NULL;

		HASH_ADD_INT( sockStore, id, identifier);
	} else {
		errno = EBUSY;
	}

	return sock_id;
}
开发者ID:SeNDA-UAB,项目名称:aDTN-platform,代码行数:28,代码来源:adtn.c

示例13: malloc

stored_object *create_object(size_t size)
{
    stored_object *obj = malloc(sizeof(stored_object));
    uint32_t page_id;

    // initialize to stored_object struct with size and initial pages
    obj->id = current_id++;
    obj->size = 0;
    obj->pages = NULL;

    // add the new object to the objects' hashtable
    HASH_ADD_INT(objects_table, id, obj); 

    while(size > obj->size)
    {
        if (GET_NEW_PAGE(VICTIM_OVERALL, EMPTY_TABLE_ENTRY_NB, &page_id) == FAIL)
        {
            // cleanup just in case we managed to do anything up until now
            remove_object(obj);
            return NULL;
        }

        if(!add_page(obj, page_id))
            return NULL;
        
        // mark new page as valid and used
        UPDATE_NEW_PAGE_MAPPING_NO_LOGICAL(page_id);
    }

    return obj;
}
开发者ID:bkreitch,项目名称:simulator,代码行数:31,代码来源:ftl_obj_strategy.c

示例14: _FTL_OBJ_COPYBACK

int _FTL_OBJ_COPYBACK(int32_t source, int32_t destination)
{
    page_node *source_p;
    
    source_p = lookup_page(source);
    
    // source_p can be NULL if the GC is working on some old pages that belonged to an object we deleted already
    if (source_p != NULL)
    {
        // invalidate the source page
        UPDATE_INVERSE_BLOCK_VALIDITY(CALC_FLASH(source), CALC_BLOCK(source), CALC_PAGE(source), INVALID);
        
        // mark new page as valid and used
        UPDATE_NEW_PAGE_MAPPING_NO_LOGICAL(destination);
        
        // change the object's page mapping to the new page
        HASH_DEL(global_page_table, source_p); 
        source_p->page_id = destination;
        HASH_ADD_INT(global_page_table, page_id, source_p); 
    }
#ifdef FTL_DEBUG
    else
    {
        printf("Warning[%s] %u copyback page not mapped to an object \n", __FUNCTION__, source);
    }
#endif

    return SUCCESS;
}
开发者ID:bkreitch,项目名称:simulator,代码行数:29,代码来源:ftl_obj_strategy.c

示例15: lru_cache_insert

void lru_cache_insert(lru_cache_t* lru,
                      DIR_handle_t handle,
                      struct giga_directory* entry) {
    ACQUIRE_MUTEX(&(lru->mutex_), "lru_cache_insert(%d)", handle);

    // printf("INSERT %d %d, length: %ld, cap: %ld\n", handle, entry->split_flag, lru->length_+1, lru->capacity_);

    struct giga_directory* old;
    HASH_FIND_INT(lru->table, &handle, old);
    if (old != NULL) {
        HASH_DEL(lru->table, old);
        double_list_remove(old);
        lru_cache_unref(old);
    } else {
        ++lru->length_;
    }

    HASH_ADD_INT(lru->table, handle, entry);
    double_list_append(&(lru->dummy), entry);
    entry->refcount = 2;

    while (lru->length_ > lru->capacity_ && lru->dummy.next != &(lru->dummy)) {
        struct giga_directory* old = lru->dummy.next;

        // printf("EVICT ENTRY %d\n", old->handle);

        HASH_DEL(lru->table, old);
        double_list_remove(old);
        lru_cache_unref(old);
        --lru->length_;
    }

    RELEASE_MUTEX(&(lru->mutex_), "lru_cache_insert(%d)", handle);
}
开发者ID:ifcharming,项目名称:mds_scaling,代码行数:34,代码来源:cache.c


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