void case_dict_pop() { struct dict *dict = dict(); char *key = "key", *val = "val"; size_t len = strlen(key); assert(dict_set(dict, key, len, val) == DICT_OK); assert(dict_len(dict) == 1); assert(dict_pop(dict, key, len) == val); assert(dict_len(dict) == 0); assert(dict_pop(dict, key, len) == NULL); assert(dict_len(dict) == 0); dict_free(dict); }
void remove_vnode_from_name_tree(struct fuse *f, struct fuse_vnode *vn) { struct fuse_vn_head *vn_head; struct fuse_vnode *v; struct fuse_vnode *lastv; vn_head = dict_get(&f->name_tree, vn->path); if (vn_head == NULL) return; lastv = NULL; SIMPLEQ_FOREACH(v, vn_head, node) { if (v->parent == vn->parent) break; lastv = v; } if (v == NULL) return; /* if we found the vnode remove it */ if (v == SIMPLEQ_FIRST(vn_head)) SIMPLEQ_REMOVE_HEAD(vn_head, node); else SIMPLEQ_REMOVE_AFTER(vn_head, lastv, node); /* if the queue is empty we need to remove it from the dict */ if (SIMPLEQ_EMPTY(vn_head)) { vn_head = dict_pop(&f->name_tree, vn->path); free(vn_head); } }
void *find_register(const char *target,const char *name) { t_context *C=ctx_get(); t_node *node_dict=scene_get_node_by_type_name( C->scene, dt_dict, target); if(node_dict) { t_dict *dict_register = ( t_dict *) node_dict->data; t_symbol *symbol=dict_pop(dict_register,name); if(symbol) { return symbol->data; } else { printf("[ERROR app_data_get] Can't get symbol %s\n",name); } } else { printf("[ERROR app_data_get] Can't get dict %s\n",target); } printf("[ERROR app_data_get] Unknown target %s\n",name); return NULL; }
void case_dict_pop(struct bench_ctx *ctx) { struct dict *dict = dict(); /* suite */ int i; char keys[ctx->n][4]; for (i = 0; i < ctx->n; i++) { sprintf(keys[i], "%d", i & 999); dict_set(dict, keys[i], "val"); } /* bench */ bench_ctx_reset_start_at(ctx); for (i = 0; i < ctx->n; i++) { dict_pop(dict, keys[i]); } bench_ctx_reset_end_at(ctx); dict_free(dict); }