MRB_API mrb_value mrb_hash_delete_key(mrb_state *mrb, mrb_value hash, mrb_value key) { khash_t(ht) *h = RHASH_TBL(hash); khiter_t k; mrb_value delVal; mrb_int n; if (h) { k = kh_get(ht, mrb, h, key); if (k != kh_end(h)) { delVal = kh_value(h, k).v; n = kh_value(h, k).n; kh_del(ht, mrb, h, k); for (k = kh_begin(h); k != kh_end(h); k++) { if (!kh_exist(h, k)) continue; if (kh_value(h, k).n > n) kh_value(h, k).n--; } return delVal; } } /* not found */ return mrb_nil_value(); }
static PyObject* pyext_epoll_unregister(PyObject *self,PyObject *args){ khiter_t hit; int epfd; int fd; struct pyep_data *pyep; struct ev_header *evhdr; if(!PyArg_ParseTuple(args,"ii",&epfd,&fd)){ PyErr_BadArgument(); return NULL; } if((pyep = pyep_getby_epfd(epfd)) == NULL){ PyErr_SetString(PyExc_KeyError,"epoll file descriptor not found"); return NULL; } if((evhdr = evhdr_getby_fd(pyep->evhdr_ht,fd)) == NULL){ PyErr_SetString(PyExc_KeyError,"file descriptor not found"); return NULL; } if(ev_del(&pyep->evdata,evhdr)){ PyErr_SetString(PyExc_SystemError,"unregister event failed"); return NULL; } hit = kh_get(ptr,pyep->evhdr_ht,fd); kh_del(ptr,pyep->evhdr_ht,hit); free(evhdr); Py_INCREF(Py_None); return Py_None; }
void gl4es_glBeginQuery(GLenum target, GLuint id) { if(target!=GL_SAMPLES_PASSED) { errorShim(GL_INVALID_ENUM); return; } if (glstate->list.pending) flush(); khint_t k; int ret; glquery_t *query; khash_t(queries) *list = glstate->queries; if (! list) { list = glstate->queries = kh_init(queries); // segfaults if we don't do a single put kh_put(queries, list, 1, &ret); kh_del(queries, list, 1); } k = kh_get(queries, list, id); if (k != kh_end(list)) { query = kh_value(list, k); } else { k = kh_put(queries, list, id, &ret); query = kh_value(list, k) = malloc(sizeof(glquery_t)); } query->target = target; query->num = 0; active_samples_passed = query; noerrorShim(); }
void gl4es_glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint* params) { khint_t k; int ret; if (glstate->list.pending) flush(); glquery_t *query = NULL; khash_t(queries) *list = glstate->queries; if (! list) { list = glstate->queries = kh_init(queries); // segfaults if we don't do a single put kh_put(queries, list, 1, &ret); kh_del(queries, list, 1); } k = kh_get(queries, list, id); if (k != kh_end(list)) { query = kh_value(list, k); } if(!query) { errorShim(GL_INVALID_OPERATION); return; } noerrorShim(); switch (pname) { case GL_QUERY_RESULT_AVAILABLE: *params = GL_FALSE; break; case GL_QUERY_RESULT: *params = query->num; break; default: errorShim(GL_INVALID_ENUM); break; } }
// This is called when the headers are received so we can look for a message waiting for // this person, or leave them connected until one comes, or time them out after 50s maybe? void receivedHeaders(clientStatus *thisClient) { printf ("Connected by >%s<\r\n", thisClient->clientId); // Check to see if there's a message queued for this person // if so, send it and drop the connection khiter_t q = kh_get(queue, queue, (char*)thisClient->clientId); if (q != kh_end(queue)) { char *queuedMessage; kl_shift(messages, kh_value(queue,q), &queuedMessage); // Now send the message to the person and close snprintf(httpResponse, HTTP_RESPONSE_SIZE, HTTP_TEMPLATE, (int)strlen(queuedMessage), queuedMessage); // Compose the response message free(queuedMessage); write(thisClient->io.fd, httpResponse, strlen(httpResponse)); // Send it closeConnectionSkipHash((ev_io*)thisClient); // If that was the last one, free the list and remove it from the hash if (!kh_value(queue, q)->head->next) { kl_destroy(messages, kh_value(queue, q)); // Free the list free((void*)kh_key(queue, q)); // Free the key (the client id) kh_del(queue, queue, q); // Remove this client id from the hash } } else { // If there's no message, then add their client id to the hash for later int ret; khiter_t k = kh_put(clientStatuses, clientStatuses, thisClient->clientId, &ret); kh_value(clientStatuses, k) = thisClient; } }
void h2o_http2_conn_unregister_stream(h2o_http2_conn_t *conn, h2o_http2_stream_t *stream) { khiter_t iter = kh_get(h2o_http2_stream_t, conn->open_streams, stream->stream_id); assert(iter != kh_end(conn->open_streams)); kh_del(h2o_http2_stream_t, conn->open_streams, iter); switch (stream->state) { case H2O_HTTP2_STREAM_STATE_RECV_PSUEDO_HEADERS: case H2O_HTTP2_STREAM_STATE_RECV_HEADERS: case H2O_HTTP2_STREAM_STATE_RECV_BODY: assert(! h2o_http2_conn_stream_is_linked(stream)); break; case H2O_HTTP2_STREAM_STATE_REQ_PENDING: if (h2o_http2_conn_stream_is_linked(stream)) { unlink_stream(&conn->_pending_reqs, stream); } break; case H2O_HTTP2_STREAM_STATE_SEND_HEADERS: case H2O_HTTP2_STREAM_STATE_SEND_BODY: case H2O_HTTP2_STREAM_STATE_END_STREAM: --conn->num_responding_streams; if (h2o_http2_conn_stream_is_linked(stream)) { unlink_stream( h2o_http2_stream_has_pending_data(stream) ? &conn->_write.streams_with_pending_data : &conn->_write.streams_without_pending_data, stream); } break; } if (conn->state != H2O_HTTP2_CONN_STATE_IS_CLOSING) run_pending_requests(conn); }
void h2o_http2_conn_unregister_stream(h2o_http2_conn_t *conn, h2o_http2_stream_t *stream) { khiter_t iter = kh_get(h2o_http2_stream_t, conn->streams, stream->stream_id); assert(iter != kh_end(conn->streams)); kh_del(h2o_http2_stream_t, conn->streams, iter); assert(h2o_http2_scheduler_is_open(&stream->_refs.scheduler)); h2o_http2_scheduler_close(&stream->_refs.scheduler); switch (stream->state) { case H2O_HTTP2_STREAM_STATE_IDLE: case H2O_HTTP2_STREAM_STATE_RECV_HEADERS: case H2O_HTTP2_STREAM_STATE_RECV_BODY: assert(!h2o_linklist_is_linked(&stream->_refs.link)); break; case H2O_HTTP2_STREAM_STATE_REQ_PENDING: assert(h2o_linklist_is_linked(&stream->_refs.link)); h2o_linklist_unlink(&stream->_refs.link); break; case H2O_HTTP2_STREAM_STATE_SEND_HEADERS: case H2O_HTTP2_STREAM_STATE_SEND_BODY: case H2O_HTTP2_STREAM_STATE_END_STREAM: if (h2o_linklist_is_linked(&stream->_refs.link)) h2o_linklist_unlink(&stream->_refs.link); break; } if (stream->state != H2O_HTTP2_STREAM_STATE_END_STREAM) h2o_http2_stream_set_state(conn, stream, H2O_HTTP2_STREAM_STATE_END_STREAM); if (conn->state < H2O_HTTP2_CONN_STATE_IS_CLOSING) { run_pending_requests(conn); update_idle_timeout(conn); } }
int merge_remaining_interval(kh_pos_t* positions_read, vcf_file_t **files, shared_options_data_t *shared_options_data, merge_options_data_t *options_data, list_t *output_list) { int num_entries = 0; #pragma omp parallel for num_threads(shared_options_data->num_threads) reduction(+:num_entries) for (int k = kh_begin(positions_read); k < kh_end(positions_read); k++) { if (kh_exist(positions_read, k)) { array_list_t *records_in_position = kh_value(positions_read, k); assert(records_in_position); // Launch merge int err_code = 0; vcf_record_t *merged = merge_position((vcf_record_file_link **) records_in_position->items, records_in_position->size, files, options_data->num_files, options_data, &err_code); if (!err_code) { list_item_t *item = list_item_new(k, MERGED_RECORD, merged); list_insert_item(item, output_list); num_entries += 1; } // Free empty nodes (lists of records in the same position) array_list_free(records_in_position, vcf_record_file_link_free); kh_del(pos, positions_read, k); } } return num_entries; }
static void gc_sweep_phase(pic_state *pic) { struct heap_page *page; int it; khash_t(weak) *h; khash_t(oblist) *s = &pic->oblist; struct symbol *sym; struct object *obj; size_t total = 0, inuse = 0; /* weak maps */ while (pic->heap->weaks != NULL) { h = &pic->heap->weaks->hash; for (it = kh_begin(h); it != kh_end(h); ++it) { if (! kh_exist(h, it)) continue; obj = kh_key(h, it); if (! is_alive(obj)) { kh_del(weak, h, it); } } pic->heap->weaks = pic->heap->weaks->prev; } /* symbol table */ for (it = kh_begin(s); it != kh_end(s); ++it) { if (! kh_exist(s, it)) continue; sym = kh_val(s, it); if (sym && ! is_alive((struct object *)sym)) { kh_del(oblist, s, it); } } page = pic->heap->pages; while (page) { inuse += gc_sweep_page(pic, page); total += PAGE_UNITS; page = page->next; } if (PIC_PAGE_REQUEST_THRESHOLD(total) <= inuse) { heap_morecore(pic); } }
void hash_internal_remove(hash_t *hash, const char *key, array_t *array) { khint_t k; k = kh_get(str, hash->table, key); kh_del(str, hash->table, k); free((char *) key); array_free(array); }
static void ucp_ep_delete_from_hash(ucp_ep_h ep) { khiter_t hash_it; hash_it = kh_get(ucp_worker_ep_hash, &ep->worker->ep_hash, ep->dest_uuid); if (hash_it != kh_end(&ep->worker->ep_hash)) { kh_del(ucp_worker_ep_hash, &ep->worker->ep_hash, hash_it); } }
int HashMap_remove(HashMap* map, bstring key) { int value = -1; khint_t k = kh_get(str, map->h, bdata(key)); if (kh_exist(map->h, k)) { value = kh_value(map->h, k); kh_del(str, map->h, k); } return value; }
Var* freg_binding(Env *env, Var *var) { khiter_t k; int ret; khash_t(str) *h=env->h_locals; k=kh_put(str, h, var->name, &ret); if (!ret){ kh_del(str, h, k); } kh_val(h, k) = var; return var; }
char* enterCriticalPart(int procid){ printf("Process %d entered critical part.\n", procid); sleep(10); votes = 0; selected = false; kh_del(16, h, procid); fprintf(stderr, "Process %d left critical part.\n", procid); state = "RELEASED"; return "RELEASE."; }
void pic_dict_del(pic_state *pic, struct pic_dict *dict, pic_sym *key) { khash_t(dict) *h = &dict->hash; khiter_t it; it = kh_get(dict, h, key); if (it == kh_end(h)) { pic_errorf(pic, "no slot named ~s found in dictionary", pic_obj_value(key)); } kh_del(dict, h, it); }
void pic_weak_del(pic_state *pic, pic_value weak, pic_value key) { khash_t(weak) *h = &pic_weak_ptr(pic, weak)->hash; int it; it = kh_get(weak, h, pic_obj_ptr(key)); if (it == kh_end(h)) { pic_error(pic, "element not found for given key", 1, key); } kh_del(weak, h, it); }
static inline void release_from_cache(h2o_filecache_t *cache, khiter_t iter) { const char *path = kh_key(cache->hash, iter); h2o_filecache_ref_t *ref = H2O_STRUCT_FROM_MEMBER(h2o_filecache_ref_t, _path, path); /* detach from list */ kh_del(opencache_set, cache->hash, iter); h2o_linklist_unlink(&ref->_lru); /* and close */ h2o_filecache_close_file(ref); }
static void erase_ref(h2o_cache_t *cache, khiter_t iter, int reuse) { h2o_cache_ref_t *ref = kh_key(cache->table, iter); if (!reuse) kh_del(cache, cache->table, iter); h2o_linklist_unlink(&ref->_lru_link); h2o_linklist_unlink(&ref->_age_link); cache->size -= ref->value.len; h2o_cache_release(cache, ref); }
void pic_reg_del(pic_state *pic, struct pic_reg *reg, void *key) { khash_t(reg) *h = ®->hash; khiter_t it; it = kh_get(reg, h, key); if (it == kh_end(h)) { pic_errorf(pic, "no slot named ~s found in register", pic_obj_value(key)); } kh_del(reg, h, it); }
// Close a connection and free the memory associated and remove from hash void closeConnection(ev_io *watcher) { ev_io_stop(libEvLoop, watcher); // Tell libev to stop following it close(watcher->fd); // Close the socket // Remove the client status from the hash if it's a waiting connection if (((clientStatus*)watcher)->readStatus==1000) { // Only ones waiting a message (1000) are in the hash khiter_t k = kh_get(clientStatuses, clientStatuses, ((clientStatus*)watcher)->clientId); // Find it in the hash if (k != kh_end(clientStatuses)) { // Was it in the hash? kh_del(clientStatuses, clientStatuses, k); // Remove it from the hash } } kmp_free(csPool, csPool, (clientStatus*)watcher); // Free the clientstatus/watcher (this is last because the fd is used above, after ev_io_stop) }
ERR_VALUE kmer_table_delete(PKMER_TABLE Table, const PKMER KMer) { khiter_t it; ERR_VALUE ret = ERR_INTERNAL_ERROR; it = kh_get(vertexTable, Table->KHashTable, KMer); if (it != kh_end(Table->KHashTable)) { Table->Callbacks.OnDelete(Table, kh_val(Table->KHashTable, it), Table->Callbacks.Context); kh_del(vertexTable, Table->KHashTable, it); ret = ERR_SUCCESS; } else ret = ERR_NOT_FOUND; return ret; }
void HashMap_put(HashMap* map, bstring key, int value) { int ret; khint_t k = kh_put(str, map->h, bdata(key), &ret); if (!ret) { printf("Failed to insert: %s (%d)\n", bdata(key), value); kh_del(str, map->h, k); return; } kh_key(map->h, k) = bdata(key); kh_value(map->h, k) = value; }
int destroy(int id) { khint_t key = kh_get(m32, states, id); if (key != kh_end(states)) // check thet key exists { struct instance* inst = kh_val(states, key); kh_del(m32, states, key); instance_destroy(inst); return 1; } else { return 0; } }
void * htable_ptrs_remove(htable_ptrs_t *ptr_ht, void *key) { void *val; khiter_t k; k = kh_get(ptrs,ptr_ht->ht, key); if (k == kh_end(ptr_ht->ht)){ return (NULL); } val = kh_value(ptr_ht->ht, k); kh_del(ptrs,ptr_ht->ht,k); return (val); }
int main() { int ret, is_missing; khiter_t k; khash_t(32) *h = kh_init(32); k = kh_put(32, h, 5, &ret); kh_value(h, k) = 10; k = kh_get(32, h, 10); is_missing = (k == kh_end(h)); k = kh_get(32, h, 5); kh_del(32, h, k); for (k = kh_begin(h); k != kh_end(h); ++k) if (kh_exist(h, k)) kh_value(h, k) = 1; kh_destroy(32, h); return 0; }
char* relinguished(int procid){ printf("Process: %d received relinguish.\n", procid); int ret; khiter_t k = kh_put(16, h, candidateID, &ret); kh_value(h, k) = candidateLamport; int process = findProcessWithLowestTimeStamp(); int minTimeStamp = kh_value(h, process); kh_del(16, h, process); candidateID = process; candidateLamport = minTimeStamp; inquired = false; char back[30]; sprintf(back, "%d, LOCKED.", candidateID); return strdup(back); }
void ForwardIndexFree(ForwardIndex *idx) { khiter_t k; for (k = kh_begin(idx->hits); k != kh_end(idx->hits); ++k) { if (kh_exist(idx->hits, k)) { ForwardIndexEntry *ent = kh_value(idx->hits, k); // free((void *)ent->term); kh_del(32, idx->hits, k); VVW_Free(ent->vw); free(ent); } } kh_destroy(32, idx->hits); free(idx); // TODO: check if we need to free each entry separately }
static mrb_bool iv_del(mrb_state *mrb, iv_tbl *t, mrb_sym sym, mrb_value *vp) { khash_t(iv) *h = &t->h; khiter_t k; if (h) { k = kh_get(iv, h, sym); if (k != kh_end(h)) { mrb_value val = kh_value(h, k); kh_del(iv, h, k); if (vp) *vp = val; return TRUE; } } return FALSE; }
static void write_pair_help(struct writer_control *p, struct pic_pair *pair) { pic_state *pic = p->pic; khash_t(l) *lh = &p->labels; khash_t(v) *vh = &p->visited; khiter_t it; int ret; write_core(p, pair->car); if (pic_nil_p(pair->cdr)) { return; } else if (pic_pair_p(pair->cdr)) { /* shared objects */ if ((it = kh_get(l, lh, pic_ptr(pair->cdr))) != kh_end(lh) && kh_val(lh, it) != -1) { xfprintf(pic, p->file, " . "); kh_put(v, vh, pic_ptr(pair->cdr), &ret); if (ret == 0) { /* if exists */ xfprintf(pic, p->file, "#%d#", kh_val(lh, it)); return; } xfprintf(pic, p->file, "#%d=", kh_val(lh, it)); } else { xfprintf(pic, p->file, " "); } write_pair_help(p, pic_pair_ptr(pair->cdr)); if (p->op == OP_WRITE) { if ((it = kh_get(l, lh, pic_ptr(pair->cdr))) != kh_end(lh) && kh_val(lh, it) != -1) { it = kh_get(v, vh, pic_ptr(pair->cdr)); kh_del(v, vh, it); } } return; } else { xfprintf(pic, p->file, " . "); write_core(p, pair->cdr); } }
ERR_VALUE kmer_edge_table_delete(PKMER_EDGE_TABLE Table, const PKMER Source, const PKMER Dest) { ERR_VALUE ret = ERR_INTERNAL_ERROR; khiter_t it; KMER_EDGE_TABLE_KEY key; key.Source = Source; key.Dest = Dest; it = kh_get(edgeTable, Table->KHashTable, key); if (it != kh_end(Table->KHashTable)) { Table->Callbacks.OnDelete(Table, kh_val(Table->KHashTable, it), Table->Callbacks.Context); kh_del(edgeTable, Table->KHashTable, it); ret = ERR_SUCCESS; } else ret = ERR_NOT_FOUND; return ret; }