inline js_type_class_t *js_get_type_from_native(T* native_obj) { js_type_class_t *typeProxy; long typeId = cocos2d::getHashCodeByString(typeid(*native_obj).name()); HASH_FIND_INT(_js_global_type_ht, &typeId, typeProxy); if (!typeProxy) { cocos2d::TypeInfo *typeInfo = dynamic_cast<cocos2d::TypeInfo *>(native_obj); if (typeInfo) { typeId = typeInfo->getClassTypeInfo(); } else { typeId = cocos2d::getHashCodeByString(typeid(T).name()); } HASH_FIND_INT(_js_global_type_ht, &typeId, typeProxy); } return typeProxy; }
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; }
void CCActionManager::removeAllActionsFromTarget(CAObject *pTarget) { // explicit null handling if (pTarget == NULL) { return; } tHashElement *pElement = NULL; HASH_FIND_INT(m_pTargets, &pTarget, pElement); if (pElement) { if (ccArrayContainsObject(pElement->actions, pElement->currentAction) && (! pElement->currentActionSalvaged)) { pElement->currentAction->retain(); pElement->currentActionSalvaged = true; } ccArrayRemoveAllObjects(pElement->actions); if (m_pCurrentTarget == pElement) { m_bCurrentTargetSalvaged = true; } else { deleteHashElement(pElement); } } else { // CCLOG("CrossApp: removeAllActionsFromTarget: Target not found"); } }
struct mystruct *find_key(off_t st_size) { struct mystruct *s; HASH_FIND_INT(myfiles, &st_size, s); return s; }
void CCActionManager::removeActionByTag(int tag, CCObject *pTarget) { assert(tag != kCCActionTagInvalid); assert(pTarget != NULL); tHashElement *pElement = NULL; HASH_FIND_INT(m_pTargets, &pTarget, pElement); if (pElement) { unsigned int limit = pElement->actions->num; for (unsigned int i = 0; i < limit; ++i) { CCAction *pAction = (CCAction*)pElement->actions->arr[i]; if (pAction->getTag() == tag && pAction->getOriginalTarget() == pTarget) { return removeActionAtIndex(i, pElement); } } CCLOG("cocos2d: removeActionByTag: Action not found!"); } else { CCLOG("cocos2d: removeActionByTag: Target not found!"); } }
/** * 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; }
ETERM *space_delete(ETERM *fromp, ETERM *argp) { // get the args ETERM *space_refp = erl_element(1, argp); erlmunk_space *s; int space_id = ERL_REF_NUMBER(space_refp); HASH_FIND_INT(erlmunk_spaces, &space_id, s); // remove all subscribers for(erlmunk_subscriber *subscriber = s->subscribers; subscriber != NULL; subscriber = subscriber->hh.next) { space_remove_subscriber(s, subscriber); } // remove all bodies for(erlmunk_body *b = s->bodies; b != NULL; b = b->hh.next) { erlmunk_body_data *data = cpBodyGetUserData(b->body); if (data->term != NULL) erl_free_compound(data->term); free(data); cpSpaceRemoveBody(s->space, b->body); cpBodyDestroy(b->body); cpBodyFree(b->body); space_remove_body_hash(s, b); } return NULL; }
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, }));
void del_giga_fi(int fd) { giga_file_info_t *info; HASH_FIND_INT(_open_files, &fd, info); if(info != NULL) HASH_DEL(_open_files, info); }
struct fl_url_filter *find_filter(int url_id) { struct fl_url_filter *s; HASH_FIND_INT(filters, &url_id, s); /* s: output pointer */ return s; }
struct file_descriptor_table * allocate_file_descriptor_table(int pid) { struct file_descriptor_table * result_table; HASH_FIND_INT(file_descriptor_tables, &pid, result_table); if (result_table == NULL) { int i; struct file_descriptor_table * table = (struct file_descriptor_table *) malloc(sizeof(struct file_descriptor_table)); table->pid = pid; table->entries = (struct file_descriptor_entry *) malloc(8 * sizeof(struct file_descriptor_entry)); table->total_descriptors = 8; table->used_descriptors = 3; table->entries[0].fd = 0; table->entries[1].fd = 1; table->entries[2].fd = 2; for (i = 3; i < table->total_descriptors; i++) { table->entries[i].fd = FD_NOT_USED; } HASH_ADD_INT(file_descriptor_tables, pid, table); return table; } return NULL; }
bool sec_exists_entry(uint32_t secid) { struct secentry *se=NULL; HASH_FIND_INT(hash, &secid, se); if(!se) return false; return true; }
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; }
int adtn_setcodopt_base(int fd, code_type_e option, const char *code, int from_file, int replace) { int ret = -1; bunsock_s *identifier; HASH_FIND_INT(sockStore, &fd, identifier); if (!identifier) { errno = ENOTSOCK; goto end; } if (code == NULL || strcmp(code, "") == 0 || from_file < 0 || from_file > 1) { errno = EINVAL; goto end; } switch (option) { case ROUTING_CODE: if (identifier->opt.rcode) { if (replace) { free(identifier->opt.rcode); } else { errno = EOPNOTSUPP; goto end; } } identifier->opt.rcode = strdup(code); identifier->opt.r_fromfile = from_file; break; case LIFE_CODE: if (identifier->opt.lcode) { if (replace) { free(identifier->opt.lcode); } else { errno = EOPNOTSUPP; goto end; } } identifier->opt.lcode = strdup(code); identifier->opt.l_fromfile = from_file; break; case PRIO_CODE: if (identifier->opt.pcode) { if (replace) { free(identifier->opt.pcode); } else { errno = EOPNOTSUPP; goto end; } } identifier->opt.pcode = strdup(code); identifier->opt.p_fromfile = from_file; break; default: errno = EINVAL; goto end; } ret = 0; end: return ret; }
int swDataBuffer_clear(swDataBuffer *data_buffer, int fd) { swDataBuffer_item *item = NULL; HASH_FIND_INT(data_buffer->ht, &fd, item); if (item == NULL) { swTrace("buffer item not found\n"); return SW_ERR; } else { swDataBuffer_trunk *trunk = item->first; swDataBuffer_trunk *will_free_trunk; //保存trunk的指针,用于释放内存 while (trunk != NULL) { sw_free(trunk->data); will_free_trunk = trunk; trunk = trunk->next; sw_free(will_free_trunk); } HASH_DEL(data_buffer->ht, item); sw_free(item); } return SW_OK; }
CCAction* CCActionManager::getActionByTag(int tag, NSObject *pTarget) { assert(tag != kCCActionTagInvalid); tHashElement *pElement = NULL; HASH_FIND_INT(m_pTargets, &pTarget, pElement); if (pElement) { if (pElement->actions != NULL) { unsigned int limit = pElement->actions->num; for (unsigned int i = 0; i < limit; ++i) { CCAction *pAction = (CCAction*)pElement->actions->arr[i]; if (pAction->getTag() == tag) { return pAction; } } } CCLOG("cocos2d : getActionByTag: Action not found"); } else { CCLOG("cocos2d : getActionByTag: Target not found"); } return NULL; }
int h3m_object_add_by_def(h3mlib_ctx_t ctx, const char *def, int x, int y, int z, int *od_index) { struct META_OA_HASH_ENTRY *oa_hash_entry = NULL; int oa_index = 0; int oa_body_index = 0; // Currently oa_body_index is used as key in the // oa hash... The current code is a bit unoptimal as if this function // ends up calling h3m_add_oa_by_def below, an additional // hash lookup for this hash inside that function will be performed. if (NULL == h3m_get_def_body(def, &oa_body_index)) { return 1; } // if oa for this object has not yet been added to map, add it, // otherwise use the existing oa_index for the oa HASH_FIND_INT(ctx->meta.oa_hash, &oa_body_index, oa_hash_entry); if (NULL == oa_hash_entry) { h3m_add_oa_by_def(ctx, def, &oa_index); } else { oa_index = oa_hash_entry->oa_index; } return h3m_add_od(ctx, oa_index, x, y, z, od_index); }
// Read a value from an 16-bit area of memory uint16_t read_memory_16(gb_mem16_t* hash, int addr) { gb_mem16_t *s; HASH_FIND_INT(hash, &addr, s); return s->value; }
ETERM *space_add_body(ETERM *fromp, ETERM *argp) { // get the args ETERM *space_refp = erl_element(1, argp); ETERM *idp = erl_element(2, argp); ETERM *massp = erl_element(3, argp); // ETERM *inertiap = erl_element(4, argp); erlmunk_space *s; int space_id = ERL_REF_NUMBER(space_refp); HASH_FIND_INT(erlmunk_spaces, &space_id, s); int object_id = ERL_INT_VALUE(idp); cpBody *body = cpSpaceAddBody(s->space, cpBodyNew(ERL_FLOAT_VALUE(massp), INFINITY)); // the body is created inactive, it is explicitly activated // when all it's values have been set. cpBodySleep(body); erlmunk_body_data *data = malloc(sizeof(erlmunk_body_data)); data->id = object_id; data->term = NULL; cpBodySetUserData(body, (cpDataPointer) data); space_add_body_hash(s, object_id, body); return NULL; }
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); }
JSBool js_cocos2dx_GLNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) { if (argc == 0) { GLNode* cobj = new GLNode(); #ifdef COCOS2D_JAVASCRIPT cocos2d::Object *_ccobj = dynamic_cast<cocos2d::Object *>(cobj); if (_ccobj) { _ccobj->autorelease(); } #endif TypeTest<GLNode> t; js_type_class_t *typeClass; uint32_t typeId = t.s_id(); HASH_FIND_INT(_js_global_type_ht, &typeId, typeClass); assert(typeClass); JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t *p = jsb_new_proxy(cobj, obj); #ifdef COCOS2D_JAVASCRIPT JS_AddNamedObjectRoot(cx, &p->obj, "cocos2d::GLNode"); #endif return JS_TRUE; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0); return JS_FALSE; }
// XXX: Passing "const O *" instead of "const O&" because HASH_FIND_IT requries the address of a pointer // and, it is not possible to get the address of a reference Action* ActionManager::getActionByTag(unsigned int tag, const Object *target) const { CCASSERT((int)tag != kActionTagInvalid, ""); tHashElement *pElement = NULL; HASH_FIND_INT(_targets, &target, pElement); if (pElement) { if (pElement->actions != NULL) { unsigned int limit = pElement->actions->num; for (unsigned int i = 0; i < limit; ++i) { Action *pAction = (Action*)pElement->actions->arr[i]; if (pAction->getTag() == (int)tag) { return pAction; } } } CCLOG("cocos2d : getActionByTag(tag = %d): Action not found", tag); } else { // CCLOG("cocos2d : getActionByTag: Target not found"); } return NULL; }
tEffectElement* SoundDataManager::getSoundData(int nSoundID) { tEffectElement* pElement = NULL; HASH_FIND_INT(m_pEffects, &nSoundID, pElement); return pElement; }
void CCActionManager::removeAction(CCAction *pAction) { // explicit null handling // 确定处理, null if (pAction == NULL) { return; } tHashElement *pElement = NULL; CCObject *pTarget = pAction->getOriginalTarget(); HASH_FIND_INT(m_pTargets, &pTarget, pElement); if (pElement) { unsigned int i = ccArrayGetIndexOfObject(pElement->actions, pAction); if (UINT_MAX != i) { removeActionAtIndex(i, pElement); } } else { CCLOG("cocos2d: removeAction: Target not found"); } }
int main(int argc,char *argv[]) { int i; example_user_t *user, *tmp, *users=NULL; /* create elements */ for(i=0;i<10;i++) { if ( (user = (example_user_t*)malloc(sizeof(example_user_t))) == NULL) exit(-1); user->id = i; user->cookie = i*i; HASH_ADD_INT(users,id,user); } /* delete each even ID */ for(i=0;i<10;i+=2) { HASH_FIND_INT(users,&i,tmp); if (tmp) { HASH_DEL(users,tmp); free(tmp); } else printf("user id %d not found\n", i); } /* show the hash */ for(user=users; user != NULL; user=(example_user_t*)(user->hh.next)) { printf("user %d, cookie %d\n", user->id, user->cookie); } return 0; }
hash_token_t *uq_tokenize_to_hash(const char *str, const char *delimiters) { unsigned int hash; hash_token_t *s, *table = NULL; char *tok; char tmp[strlen(str) + 1]; strcpy(tmp, str); tok = strtok(tmp, delimiters); while(tok != NULL) { hash = str_hash(tok); HASH_FIND_INT(table, &hash, s); if(s == NULL) { s = malloc(sizeof(hash_token_t)); s->key = str_hash(tok); s->value = strdup(tok); HASH_ADD_INT(table, key, s); } tok = strtok(NULL, delimiters); } return (table); }
void CCActionManager::addAction(CCAction *pAction, CAView *pTarget, bool paused) { CCAssert(pAction != NULL, ""); CCAssert(pTarget != NULL, ""); tHashElement *pElement = NULL; // we should convert it to CAObject*, because we save it as CAObject* CAObject *tmp = pTarget; HASH_FIND_INT(m_pTargets, &tmp, pElement); if (! pElement) { pElement = (tHashElement*)calloc(sizeof(*pElement), 1); pElement->paused = paused; pTarget->retain(); pElement->target = pTarget; HASH_ADD_INT(m_pTargets, target, pElement); } actionAllocWithHashElement(pElement); CCAssert(! ccArrayContainsObject(pElement->actions, pAction), ""); ccArrayAppendObject(pElement->actions, pAction); pAction->startWithTarget(pTarget); }
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++; }
CCAction* CCActionManager::getActionByTag(unsigned int tag, CAObject *pTarget) { CCAssert((int)tag != kCCActionTagInvalid, ""); tHashElement *pElement = NULL; HASH_FIND_INT(m_pTargets, &pTarget, pElement); if (pElement) { if (pElement->actions != NULL) { unsigned int limit = pElement->actions->num; for (unsigned int i = 0; i < limit; ++i) { CCAction *pAction = (CCAction*)pElement->actions->arr[i]; if (pAction->getTag() == (int)tag) { return pAction; } } } CCLOG("CrossApp : getActionByTag(tag = %d): Action not found", tag); } else { // CCLOG("CrossApp : getActionByTag: Target not found"); } return NULL; }
JSBool js_cocos2dx_extension_HttpRequest_constructor(JSContext *cx, uint32_t argc, jsval *vp){ if(argc == 0){ HttpRequest* cobj = new HttpRequest(); cocos2d::CCObject *_ccobj = dynamic_cast<cocos2d::CCObject *>(cobj); if (_ccobj) { _ccobj->autorelease(); } TypeTest<cocos2d::extension::CCHttpRequest> t; js_type_class_t *typeClass; uint32_t typeId = t.s_id(); HASH_FIND_INT(_js_global_type_ht, &typeId, typeClass); assert(typeClass); JSObject *obj = JS_NewObject(cx, typeClass->jsclass, typeClass->proto, typeClass->parentProto); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(obj)); // link the native object with the javascript object js_proxy_t *p; JS_NEW_PROXY(p, cobj, obj); JS_AddNamedObjectRoot(cx, &p->obj, "HttpRequest"); return JS_TRUE; } JS_ReportError(cx, "wrong number of arguments: %d, was expecting %d", argc, 0); return JS_FALSE; }