int rdis_remove_function (struct _rdis * rdis, uint64_t address) { map_remove(rdis->functions, address); map_remove(rdis->labels, address); struct _graph * family = graph_family(rdis->graph, address); if (family == NULL) return -1; struct _graph_it * it; for (it = graph_iterator(family); it != NULL; it = graph_it_next(it)) { struct _graph_node * node = graph_it_node(it); printf("rdis_remove_function %p %p %p %llx\n", node, node->data, node->edges, (unsigned long long) node->index); graph_remove_node(rdis->graph, node->index); } object_delete(family); rdis_callback(rdis, RDIS_CALLBACK_GRAPH | RDIS_CALLBACK_FUNCTION | RDIS_CALLBACK_LABEL); return 0; }
void bimap_remove_by_key_2(bimap_t bimap, const key_type * k2) { size_t * idx = map_lookup(bimap->key_2_map, k2); if (idx == NULL) return; const key_type * k1 = bimap->datas + *idx * bimap->storage_size + bimap->data_size; map_remove(bimap->key_1_map, k1); map_remove(bimap->key_2_map, k2); /// \todo rm data bimap->count--; }
/* A function that given an integer (obtained from above function) and a process id REMOVE the file from a list. Should return NULL if the specified process did not insert the file or already removed it. */ value_t flist_remove_file(int fd, struct thread* t) { value_t v = map_remove(&(t->open_files), fd); return v; }
DIRECT_FN STATIC int gnix_av_remove(struct fid_av *av, fi_addr_t *fi_addr, size_t count, uint64_t flags) { struct gnix_fid_av *int_av = NULL; int ret = FI_SUCCESS; GNIX_TRACE(FI_LOG_AV, "\n"); if (!av) { ret = -FI_EINVAL; goto err; } int_av = container_of(av, struct gnix_fid_av, av_fid); if (!int_av) { ret = -FI_EINVAL; goto err; } switch (int_av->type) { case FI_AV_TABLE: ret = table_remove(int_av, fi_addr, count, flags); break; case FI_AV_MAP: ret = map_remove(int_av, fi_addr, count, flags); break; default: ret = -FI_EINVAL; break; } err: return ret; }
static void tls_specific_dtor(void *value) { int kvindex; mapkey_t keys[32]; void *values[32]; tls_base_t *base; if (!value) return; base = (tls_base_t *)value; while ((kvindex = map_get_values(&base->kvmap, keys, values, DTOR_KV_CAPACITY))) { while (kvindex--) { tls_entry_t *entry = (tls_entry_t *)(values[kvindex]); map_remove(&base->kvmap, keys[kvindex]); if (entry->dtor != NULL) entry->dtor(keys[kvindex], entry->value); com_free(g_tls_allocator, entry); } } map_destroy(&base->kvmap); com_free(g_tls_allocator, base); }
int queue_remove(QUEUE* queue, char* value) { QNODE* qnode; qnode = map_get(queue->map, value); if (qnode != NULL) { if (qnode->prev != NULL) { qnode->prev->next = qnode->next; } else { queue->head = qnode->next; } if (qnode->next != NULL) { qnode->next->prev = qnode->prev; } else { queue->tail = qnode->prev; } map_remove(queue->map, value); free(qnode->value); free(qnode); return 0; } return -1; }
/** * Remove cached entry for key, optionally disposing of the whole structure. * Cached entry is flushed if it was dirty and flush is set. * * @return the reusable cached entry if dispose was FALSE and the key was * indeed cached, NULL otherwise. */ static struct cached * remove_entry(dbmw_t *dw, gconstpointer key, gboolean dispose, gboolean flush) { struct cached *old; gpointer old_key; gboolean found; found = map_lookup_extended(dw->values, key, &old_key, (gpointer) &old); if (!found) return NULL; g_assert(old != NULL); if (old->dirty && flush) write_back(dw, key, old); hash_list_remove(dw->keys, key); map_remove(dw->values, key); wfree(old_key, dbmw_keylen(dw, old_key)); if (!dispose) return old; /* * Dispose of the cache structure. */ free_value(dw, old, TRUE); WFREE(old); return NULL; }
int lrucache_remove(LRUCACHE* lrucache, char* key) { queue_remove(lrucache->queue, key); map_remove(lrucache->map, key); return 0; }
void struct_maps() { // here we have a custom type which has a LIST_HEADER and a string key // `true` indicates that we should use string ordering. Map *map = map_new_node(true); // since the key is part of the data we don't use `map_put`. `map_put_struct` is used // for inserting single values. map_put_structs(map, Data_new("bob",22,1), Data_new("alice",21,0), Data_new("roger",40,1), Data_new("liz",16,0), NULL ); printf("size was %d\n",map_size(map)); // you can now look up data using the key dump(D map_get(map,"alice")); dump(D map_get(map,"roger")); Data *rog = (Data*)map_remove(map,"roger"); printf("size was %d\n",map_size(map)); FOR_MAP(iter,map) { printf("[%s]=%d,",(char*)iter->key,((Data*)(iter->value))->age ); }
int map_resize(struct map *m, size_t size) { //DEBUGPRINT("map_resize\n"); struct map newtbl; size_t n; struct hash_node *node,*next; newtbl.size = size; newtbl.hash_func = m->hash_func; if ((newtbl.nodes = (struct hash_node**)calloc(size, sizeof(struct hash_node*))) == NULL) return -1; for (n = 0; n<m->size; ++n) { for(node = m->nodes[n]; node; node = next) { next = node->next; map_insert(&newtbl, node->key, node->data); map_remove(m, node->key); } } free(m->nodes); m->size = newtbl.size; m->nodes = newtbl.nodes; return 0; }
void *k_receive_message(int *sender_id) { // blocks void *env; msg_metadata *metadata = NULL; while (list_empty(&gp_current_process->msg_queue)) { gp_current_process->state = BLOCKED_ON_RECEIVE; k_release_processor(); } __disable_irq(); env = list_front(&gp_current_process->msg_queue); if (sender_id) { if (map_is_in(&metadata_map, env)) { metadata = get_message_metadata(env); *sender_id = metadata->sender_pid; } else { *sender_id = -1; } } list_shift(&gp_current_process->msg_queue); __enable_irq(); if (map_is_in(&metadata_map, env)) { map_remove(&metadata_map, env); // map is used in delayed send. no-op if not in map } return env; }
static void test_map_remove(void *o, sha1_t *keys, size_t count) { size_t i; map_t *m = o; for (i = 0; i < count; i++) map_remove(m, &keys[i]); }
map_t map_remove(map_t map, key_t key){ if (map == NULL) printf("The map is already empty!"); else { if (string_less(key,map->key)) map->leftnode = map_remove(map->leftnode, key); else if (string_less(map->key, key)) map->rightnode = map_remove(map->rightnode, key); else { if(map->leftnode == NULL && map->rightnode == NULL){ string_destroy(map->key); string_destroy(map->value); free(map); map = NULL; } else if (map->leftnode == NULL){ map_t mapaux = map; map = map->rightnode; string_destroy(mapaux->key); string_destroy(mapaux->value); free(mapaux); mapaux = NULL; } else if (map->rightnode == NULL){ map_t mapaux = map; map = map->leftnode; string_destroy(mapaux->key); string_destroy(mapaux->value); free(mapaux); mapaux = NULL; } else { map_t mapmin = map_min(map->rightnode); map_t mapaux = map; string_destroy(map->value); string_destroy(map->key); mapmin->leftnode = map->leftnode; map = map->rightnode; free(mapaux); } } } return map; }
void su_unreg_reference(su_state *s, void *ref) { value_t key; unsigned hash; su_assert(s, s->main_state == s, MAIN_STATE_ONLY_MSG); key.type = SU_NATIVEPTR; key.obj.ptr = ref; hash = hash_value(&key); s->stack[SU_REGISTRY_INDEX] = map_remove(s, s->stack[SU_REGISTRY_INDEX].obj.m, &key, hash); s->stack_top--; }
void sys_close(int fd) { struct file* close_file = map_find(get_filemap(), fd); if(close_file != NULL) { filesys_close(close_file); map_remove(get_filemap(), fd); // important to remove from file hEHE } }
void acc_sqlite_close(sqlite3 * db) { assert(acc_sqlite != NULL); char * filename = *(char**)map_lookup(acc_sqlite->db_files_map, &db); if (filename != NULL) { acc_sqlite_load_or_save_db(db, filename, 1); free(filename); } map_remove(acc_sqlite->db_files_map, &db); sqlite3_close(db); }
void kv_del(map_t _store, const str* _key) { int_str_t *val; val = (int_str_t *)map_remove(_store, *_key); if (!val) return; if (val->is_str) shm_free(val->s.s); }
TEST(UniqueMap, MapRemove) { struct UniqueMap* map = create_unique_map(0, 10); int values[] = {1,2,3}; int k[3]; k[0] = map_put_unique(map, &values[0]); k[1] = map_put_unique(map, &values[1]); k[2] = map_put_unique(map, &values[2]); TEST_ASSERT_TRUE(map_contains(map, k[2])); // hit cache TEST_ASSERT_TRUE(map_remove(map, k[2]) == &values[2]); TEST_ASSERT_FALSE(map_contains(map, k[2])); TEST_ASSERT_TRUE(map_remove(map, k[0]) == &values[0]); // uncached TEST_ASSERT_FALSE(map_contains(map, k[0])); TEST_ASSERT_NULL(map_remove(map, k[0])); // superfluous remove destroy_unique_map(map); }
/* * str_remove -- hs_remove wrapper which works on strings */ static void str_remove(const char *str) { uint64_t key; if (sscanf(str, "%lu", &key) > 0) { int l = map_lookup(mapc, map, key); if (l) map_remove(mapc, map, key); else fprintf(stderr, "no such value\n"); } else fprintf(stderr, "remove: invalid syntax\n"); }
// a - b struct map *map_minus(struct map *a, const struct map *b) { if ((a == NULL) || (b == NULL)) return a; struct array *keys = map_keys(b); for (int i=0; i<keys->length; i++) { const void *key = array_get(keys, i); if (map_has(a, key)) { map_remove(a, key); } } array_del(keys); return a; }
void freed(void* ptr) { debug_free_count++; if(is_debug) { is_debug = false; Trace* trace = map_remove(tracing, ptr); if(!trace) { printf("ERROR: freeing never alloced pointer: %p from: %p\n", ptr, ((void**)read_rbp())[1]); uint64_t* v = ptr; for(int i = 0; i < 16; i++) { printf("[%d] %p\n", i, v[i]); } while(1) asm("hlt"); } Stat* stat = map_get(statistics, trace->caller); if(stat == NULL) { printf("ERROR: freeing not alloced pointer from: %p\n", ((void**)read_rbp())[1]); while(1) asm("hlt"); } stat->count--; stat->size -= trace->size; if(stat->count == 0 && stat->size == 0) { map_remove(statistics, trace->caller); free(stat); } else if(stat->count == 0 && stat->size != 0) { printf("ERROR: malloc/free mismatching: count: %ld, size: %ld\n", stat->count, stat->size); while(1) asm("hlt"); } free(trace); is_debug = true; } }
/* >> INITALIZING MAP ... >> ADDING ENTRIES PASSED >> ***---DUPLICATE KEY FAILED **** >> GETTING VALID KEY PASSED >> GETTING INVALID KEY PASSED >> ***CHECKING SIZE (4) FAILED **** >> REMOVING KEY PASSED >> ***GETTING INVALID KEY FAILED **** >> GETTING VALID KEY PASSED >> ***REMOVING INVALID KEY FAILED **** >> REMOVING KEY PASSED >> REMOVING KEY PASSED >> SERIALIZING PASSED */ int main(int argc,char *argv[]) { map_t cool_map; printf("INITIALIZING MAP ...\r\n"); map_init(&cool_map); printf("ADDING ENTRIES\t"); map_put(&cool_map,"bom","bom"); map_put(&cool_map,"bam","bam"); printf("PASSED\r\nDUPLICATE KEY\t"); printf("%d\r\n",map_put(&cool_map,"bom","bom")); printf("%d\r\n",map_size(&cool_map)); printf("%d\r\n",map_remove(&cool_map,"fkkka")); printf("%s\r\n",map_get(&cool_map,"f**k")); }
int lrucache_set(LRUCACHE* lrucache, char* key, char* value) { char* k; while (map_length(lrucache->map) >= lrucache->size) { k = queue_peek(lrucache->queue); if (k == NULL) { break; } else { map_remove(lrucache->map, k); } } queue_insert(lrucache->queue, key); return map_set(lrucache->map, key, value); }
int task_free(task_id tid) { task_t f = { tid }; do { lc_spin_lock(lock); task_t *t = map_find(tasks, &f); if (t) { if (atomic_int_dec(&t->ref_count) > 0) break; map_remove(tasks, t); lc_free(t); //printf("Freed task <%f>\n",tid); } } while (0); lc_spin_unlock(lock); return SUCCESS; }
bool socket_remove(NetworkInterface* ni, uint32_t ip, uint16_t port) { Map* sockets = ni_config_get(ni, SOCKETS); if(!sockets) return false; uint64_t key = (uint64_t)ip << 32 | (uint64_t)port; Socket* socket = map_remove(sockets, (void*)key); if(!socket) return false; socket_delete(ni, socket); if(map_is_empty(sockets)) { map_destroy(sockets); ni_config_remove(ni, SOCKETS); } return true; }
static void test_map(void) { Map *m = make_map(NULL); assert_null(map_get(m, "abc")); // Insert 10000 values for (int i = 0; i < 10000; i++) { char *k = format("%d", i); map_put(m, k, (void *)(intptr_t)i); assert_int(i, (int)(intptr_t)map_get(m, k)); } // Insert again for (int i = 0; i < 1000; i++) { char *k = format("%d", i); map_put(m, k, (void *)(intptr_t)i); assert_int(i, (int)(intptr_t)map_get(m, k)); } // Verify that the iterator iterates over all the elements { bool x[10000]; for (int i = 0; i < 10000; i++) x[i] = 0; MapIter *iter = map_iter(m); void *v; char *k = map_next(iter, &v); for (; k; k = map_next(iter, &v)) { int i = (intptr_t)v; x[i] = 1; } for (int i = 0; i < 10000; i++) assert_true(x[i] == 1); } // Remove them for (int i = 0; i < 10000; i++) { char *k = format("%d", i); assert_int(i, (intptr_t)map_get(m, k)); map_remove(m, k); assert_null(map_get(m, k)); } }
/** * Remove cached entry for key, optionally disposing of the whole structure. * Cached entry is flushed if it was dirty and flush is set. * * @return the reusable cached entry if dispose was FALSE and the key was * indeed cached, NULL otherwise. */ static struct cached * remove_entry(dbmw_t *dw, const void *key, bool dispose, bool flush) { struct cached *old; void *old_key; bool found; found = map_lookup_extended(dw->values, key, &old_key, (void *) &old); if (!found) return NULL; g_assert(old != NULL); if (dbg_ds_debugging(dw->dbg, 3, DBG_DSF_CACHING)) { dbg_ds_log(dw->dbg, dw, "%s: %s key=%s (%s)", G_STRFUNC, old->dirty ? "dirty" : "clean", dbg_ds_keystr(dw->dbg, key, (size_t) -1), flush ? "flushing" : " discarding"); } if (old->dirty && flush) write_back(dw, key, old); hash_list_remove(dw->keys, key); map_remove(dw->values, key); wfree(old_key, dbmw_keylen(dw, old_key)); if (!dispose) return old; /* * Dispose of the cache structure. */ free_value(dw, old, TRUE); WFREE(old); return NULL; }
struct variable *sys_disconnect(struct context *context) { struct variable *arguments = (struct variable*)stack_pop(context->operand_stack); if (arguments->list->length < 2) { struct variable *sockets = (struct variable *)array_get(arguments->list, 1); assert_message(sockets->type == VAR_LST, "non list of sockets"); for (int i=0; i<sockets->list->length; i++) { struct thread_argument *tc = (struct thread_argument *)array_get(sockets->list, i); close(tc->fd); CyaSSL_free(tc->ssl); } } else { const int32_t fd = param_int(arguments, 1); close(fd); map_remove(socket_listeners, (void*)(VOID_INT)fd); } return NULL; }
char* queue_peek(QUEUE* queue) { char* value; QNODE* qnode; if (queue->head == NULL) { return NULL; } value = queue->head->value; qnode = queue->head->next; qnode->prev = NULL; free(queue->head); queue->head = qnode; if (queue->head == NULL) { queue->tail = NULL; } map_remove(queue->map, value); return value; }
void rdis_remove_callback (struct _rdis * rdis, uint64_t identifier) { map_remove(rdis->callbacks, identifier); }