int strm_var_set(strm_state* state, strm_string name, strm_value val) { strm_env *e; if (!state) { if (!globals) { globals = kh_init(env); } e = globals; } else { if (!state->env) { state->env = kh_init(env); } e = state->env; } return env_set(e, name, val); }
khash_t(ht) * mrb_hash_tbl(mrb_state *mrb, mrb_value hash) { khash_t(ht) *h = RHASH_TBL(hash); if (!h) { RHASH_TBL(hash) = kh_init(ht, mrb); } return h; }
void mrb_define_method_raw(mrb_state *mrb, struct RClass *c, mrb_sym mid, struct RProc *p) { khash_t(mt) *h = c->mt; khiter_t k; if (!h) h = c->mt = kh_init(mt, mrb); k = kh_put(mt, h, mid); kh_value(h, k) = p; }
int diffBed(int argc, char * argv[]) { int help = 0; char *out = 0; int n, i; while ((n = getopt(argc, argv, "o:h")) >= 0) { switch(n) { case 'o': out = optarg; break; case 'h': help = 1; break; default: diffHelp(); } if (help) diffHelp(); } n = argc - optind; if(n < 2) errabort("At least 2 files!"); regHash_t * reghash, * reghash1; reghash = kh_init(reg); reghash1 = kh_init(reg); int ret = 0; bedHand->read(argv[optind], (void *)reghash, 0, 0, &ret); bedHand->merge(reghash); for (i = 1; i < n; ++i) { bedHand->read(argv[optind+i], (void *)reghash1, 0, 0, &ret); } bedHand->merge(reghash1); bedHand->diff(reghash, reghash1); inf_t * inf = bedHand->stat(reghash); if (ret) { warnings("the input bed file might not be standard bed format 0-based, please make sure the input files is in same base system" "you can use '1to0' to trans the base systems first"); } writeout("There are %d bp in the first file but not in others.\n", inf->length); freemem(inf); bedHand->destroy(reghash1, destroy_void); if (out) bedHand->save(out, reghash); bedHand->destroy(reghash, destroy_void); return 1; }
mrb_value mrb_hash_new_capa(mrb_state *mrb, size_t capa) { struct RHash *h; h = (struct RHash*)mrb_obj_alloc(mrb, MRB_TT_HASH, mrb->hash_class); h->ht = kh_init(ht, mrb); kh_resize(ht, h->ht, capa); h->iv = 0; return mrb_obj_value(h); }
void parg_asset_onload(const char* name, parg_buffer* buf) { parg_token id = parg_token_from_string(name); parg_assert(buf, "Unable to load asset"); if (!_asset_registry) { _asset_registry = kh_init(assmap); } int ret; int iter = kh_put(assmap, _asset_registry, id, &ret); kh_value(_asset_registry, iter) = buf; }
static struct RClass* boot_defclass(mrb_state *mrb, struct RClass *super) { struct RClass *c; c = (struct RClass*)mrb_obj_alloc(mrb, MRB_TT_CLASS, mrb->class_class); c->super = super ? super : mrb->object_class; mrb_field_write_barrier(mrb, (struct RBasic*)c, (struct RBasic*)super); c->mt = kh_init(mt, mrb); return c; }
pic_value pic_make_weak(pic_state *pic) { struct weak *weak; weak = (struct weak *)pic_obj_alloc(pic, sizeof(struct weak), PIC_TYPE_WEAK); weak->prev = NULL; kh_init(weak, &weak->hash); return pic_obj_value(weak); }
/** Create an attack vector object * * @param corsaro The corsaro object associated with the vector * @return an empty attack vector object */ static attack_vector_t *attack_vector_init(corsaro_t *corsaro) { attack_vector_t *av = NULL; if((av = malloc_zero(sizeof(attack_vector_t))) == NULL) { corsaro_log(__func__, corsaro, "could not malloc memory for attack vector"); return NULL; } av->attack_ip_hash = kh_init(32xx); assert(av->attack_ip_hash != NULL); av->attack_port_hash = kh_init(32xx); assert(av->attack_port_hash != NULL); av->target_port_hash = kh_init(32xx); assert(av->target_port_hash != NULL); return av; }
/** Implements the init_output function of the plugin API */ int bgpcorsaro_pfxmonitor_init_output(bgpcorsaro_t *bgpcorsaro) { struct bgpcorsaro_pfxmonitor_state_t *state; bgpcorsaro_plugin_t *plugin = PLUGIN(bgpcorsaro); assert(plugin != NULL); if ((state = malloc_zero(sizeof(struct bgpcorsaro_pfxmonitor_state_t))) == NULL) { bgpcorsaro_log(__func__, bgpcorsaro, "could not malloc bgpcorsaro_pfxmonitor_state_t"); goto err; } bgpcorsaro_plugin_register_state(bgpcorsaro->plugin_manager, plugin, state); /* initialize state with default values */ state = STATE(bgpcorsaro); strncpy(state->metric_prefix, PFXMONITOR_DEFAULT_METRIC_PFX, PFXMONITOR_METRIC_PFX_LEN); strncpy(state->ip_space_name, PFXMONITOR_DEFAULT_IPSPACE_NAME, PFXMONITOR_METRIC_PFX_LEN); if ((state->poi = bgpstream_ip_counter_create()) == NULL) { goto err; } state->peer_asns_th = PFXMONITOR_DEFAULT_PEER_ASNS_THRESHOLD; state->more_specific = 0; /* parse the arguments */ if (parse_args(bgpcorsaro) != 0) { goto err; } graphite_safe(state->metric_prefix); graphite_safe(state->ip_space_name); /* create all the sets and maps we need */ if ((state->overlapping_pfx_cache = bgpstream_pfx_storage_set_create()) == NULL || (state->non_overlapping_pfx_cache = bgpstream_pfx_storage_set_create()) == NULL || (state->pfx_info = kh_init(pfx_info_map)) == NULL || (state->unique_origins = bgpstream_id_set_create()) == NULL || (state->peer_asns = bgpstream_id_set_create()) == NULL) { goto err; } /* defer opening the output file until we start the first interval */ return 0; err: bgpcorsaro_pfxmonitor_close_output(bgpcorsaro); return -1; }
void mrb_define_method_vm(mrb_state *mrb, struct RClass *c, mrb_sym name, mrb_value body) { khash_t(mt) *h = c->mt; khiter_t k; int ret; if (!h) h = c->mt = kh_init(mt, mrb); k = kh_put(mt, h, name, &ret); kh_value(h, k) = mrb_proc_ptr(body); }
void hw_http_add_route(char *route, http_request_callback callback) { if (routes == NULL) { /* routes = rxt_init(); */ routes = kh_init(string_hashmap); } /* rxt_put(route, callback, routes); */ set_route(routes, route, callback); printf("Added route %s\n", route); // TODO: Replace with logging instead. }
struct pic_reg * pic_make_reg(pic_state *pic) { struct pic_reg *reg; reg = (struct pic_reg *)pic_obj_alloc(pic, sizeof(struct pic_reg), PIC_TT_REG); reg->prev = NULL; kh_init(reg, ®->hash); return reg; }
static BGZF *bgzf_read_init(void) { BGZF *fp; fp = calloc(1, sizeof(BGZF)); fp->uncompressed_block_size = MAX_BLOCK_SIZE; fp->uncompressed_block = malloc(MAX_BLOCK_SIZE); fp->compressed_block_size = MAX_BLOCK_SIZE; fp->compressed_block = malloc(MAX_BLOCK_SIZE); fp->cache_size = 0; fp->cache = kh_init(cache); return fp; }
struct RClass* mrb_define_module_id(mrb_state *mrb, mrb_sym name) { struct RClass *m = mrb_module_new(mrb); m->mt = kh_init(mt, mrb); mrb_obj_iv_set(mrb, (struct RObject*)mrb->object_class, name, mrb_obj_value(m)); mrb_name_class(mrb, m, name); return m; }
int main(int argc, char *argv[]) { char* person_input_file = makepath(argv[1], "person", "csv"); char* interest_input_file = makepath(argv[1], "interest", "csv"); char* knows_input_file = makepath(argv[1], "knows", "csv"); char* person_output_file = makepath(argv[2], "person", "bin"); char* interest_output_file = makepath(argv[2], "interest", "bin"); char* knows_output_file = makepath(argv[2], "knows", "bin"); khiter_t k; int person_map_fd; struct stat st; if (argc < 3) { fprintf(stderr, "Usage: [csv input path] [output path]\n"); exit(-1); } if (stat(argv[2], &st) == -1) { if (mkdir(argv[2], 0700) != 0) { fprintf(stderr, "Unable to create output directory %s\n", argv[2]); exit(-1); } } // first pass person, parse person, write to binary and store bin offset in hash table person_offsets = kh_init(pht); person = malloc(sizeof(Person)); person->interest_n = person->knows_n = 0; person_out = open_binout(person_output_file); parse_csv(person_input_file, &person_line_handler); // mmap person.bin binary file for updates fclose(person_out); person_map_fd = open(person_output_file, O_RDWR); person_map = (Person *) mmap(0, person_offset * sizeof(Person), PROT_READ | PROT_WRITE, MAP_SHARED, person_map_fd, 0); if (person_map_fd == 0 || person_map == MAP_FAILED) { fprintf(stderr, "Failed to map person binary.\n"); exit(-1); } close(person_map_fd); // pass through interest and friends, write to binary, set offsets in person person_id = 0; interest_out = open_binout(interest_output_file); parse_csv(interest_input_file, &interest_line_handler); person_id = 0; knows_out = open_binout(knows_output_file); parse_csv(knows_input_file, &knows_line_handler); return 0; }
static BGZF *bgzf_read_init() { BGZF *fp; fp = calloc(1, sizeof(BGZF)); fp->is_write = 0; fp->uncompressed_block = malloc(BGZF_MAX_BLOCK_SIZE); fp->compressed_block = malloc(BGZF_MAX_BLOCK_SIZE); #ifdef BGZF_CACHE fp->cache = kh_init(cache); #endif return fp; }
ForwardIndex *NewForwardIndex(Document doc) { ForwardIndex *idx = malloc(sizeof(ForwardIndex)); idx->hits = kh_init(32); idx->docScore = doc.score; idx->docId = doc.docId; idx->totalFreq = 0; idx->maxFreq = 0; idx->stemmer = NewStemmer(SnowballStemmer, doc.language); return idx; }
khash_s2i *hash_s2i_create(void) { khash_s2i *h = calloc(1, sizeof(*h)); if (!h) return NULL; h->h = kh_init(s2i); if (!h->h) { free(h); return NULL; } return h; }
void *bcf_build_refhash(bcf_hdr_t *h) { khash_t(str2id) *hash; int i, ret; hash = kh_init(str2id); for (i = 0; i < h->n_ref; ++i) { khint_t k; k = kh_put(str2id, hash, h->ns[i], &ret); // FIXME: check ret kh_val(hash, k) = i; } return hash; }
hash_t * hash_new() { hash_t *hash; hash = malloc(sizeof(hash_t)); hash->table = kh_init(str); pthread_mutex_init(&hash->mutex, NULL); return hash; }
int trimBed(int argc, char *argv[]) { int help = 0; int n; int i; char *out = 0; int trim1 = 0; int trim2 = 0; while ((n = getopt(argc, argv, "o:r:l:h")) >= 0) { switch(n) { case 'o' : out = optarg; break; case 'l' : trim1 = atoi(optarg); break; case 'r' : trim2 = atoi(optarg); break; case 'h' : help = 1; break; default : errabort("%c : unknown option!", (char)n); break; } if (help) trimHelp(); } if (trim1 == 0 && trim2 == 0) errabort("You must set a trim size!"); if (trim1 < 0 || trim2 < 0) errabort("Trim size must be a postive int!"); n = argc - optind; if (n < 1) errabort("Sucker! Set the bed file(s)!"); regHash_t *rghsh = kh_init(reg); int ret = 0; for (i = 0; i < n; ++i) { bedHand->read(argv[optind+i], rghsh, 0, 0, &ret); } bedHand->merge(rghsh); if (ret) { warnings("the input bed file might not be standard bed format 0-based, please make sure the input files is in same base system" "you can use '1to0' to trans the base systems first"); } inf_t *itmp = bedHand->stat(rghsh); bedHand->trim(rghsh, trim1, trim2); inf_t *inf = bedHand->stat(rghsh); if (out) bedHand->save(out, rghsh); unsigned trim_length = itmp->length - inf->length; writeout("Trimmed %d bp\n" "The length of whole regions is %d bp\n" ,trim_length, inf->length); freemem(itmp); freemem(inf); bedHand->destroy(rghsh, destroy_void); return 1; }
/* program-wide initialization of sample information */ void bam_sample_info_init(const char *samples_file, const char *sample_pairs_file) { khash_t(remap_h) *sample_map = kh_init(remap_h); init_sample_attributes(samples_file, sample_map); init_sample_pairs(sample_pairs_file, sample_map); khiter_t k; for (k = kh_begin(sample_map); k != kh_end(sample_map); ++k) if (kh_exist(sample_map, k)) free((char *)kh_key(sample_map, k)); kh_destroy(remap_h, sample_map); }
PyMODINIT_FUNC PyInit_pyext(void){ PyObject *mod; mod = PyModule_Create(&pyext_module); if(mod == NULL){ return NULL; } pyep_ht = kh_init(ptr); return mod; }
void mrb_define_method_raw(mrb_state *mrb, struct RClass *c, mrb_sym mid, struct RProc *p) { khash_t(mt) *h = c->mt; khiter_t k; if (!h) h = c->mt = kh_init(mt, mrb); k = kh_put(mt, h, mid); kh_value(h, k) = p; if (p) { mrb_field_write_barrier(mrb, (struct RBasic *)c, (struct RBasic *)p); } }
void hw_http_add_route(char *route, http_request_callback callback, void* user_data) { hw_route_entry* route_entry = malloc(sizeof(hw_route_entry)); route_entry->callback = callback; route_entry->user_data = user_data; if (routes == NULL) { routes = kh_init(string_hashmap); } set_route(routes, route, route_entry); printf("Added route %s\n", route); // TODO: Replace with logging instead. }
void bgpstream_filter_mgr_rib_period_filter_add( bgpstream_filter_mgr_t *bs_filter_mgr, uint32_t period) { bgpstream_debug("\tBSF_MGR:: add_filter start"); assert(bs_filter_mgr != NULL); if (period != 0 && bs_filter_mgr->last_processed_ts == NULL) { if ((bs_filter_mgr->last_processed_ts = kh_init(collector_ts)) == NULL) { bgpstream_log_warn( "\tBSF_MGR: can't allocate memory for collectortype map"); } } bs_filter_mgr->rib_period = period; bgpstream_debug("\tBSF_MGR:: add_filter end"); }
static void load_hfile_plugins() { static const struct hFILE_scheme_handler data = { hopen_mem, hfile_always_local, "built-in", 80 }, file = { hopen_fd_fileuri, hfile_always_local, "built-in", 80 }, preload = { hopen_preload, is_preload_url_remote, "built-in", 80 }; schemes = kh_init(scheme_string); if (schemes == NULL) abort(); hfile_add_scheme_handler("data", &data); hfile_add_scheme_handler("file", &file); hfile_add_scheme_handler("preload", &preload); init_add_plugin(NULL, hfile_plugin_init_net, "knetfile"); init_add_plugin(NULL, hfile_plugin_init_mem, "mem"); #ifdef ENABLE_PLUGINS struct hts_path_itr path; const char *pluginname; hts_path_itr_setup(&path, NULL, NULL, "hfile_", 6, NULL, 0); while ((pluginname = hts_path_itr_next(&path)) != NULL) { void *obj; int (*init)(struct hFILE_plugin *) = (int (*)(struct hFILE_plugin *)) load_plugin(&obj, pluginname, "hfile_plugin_init"); if (init) { if (init_add_plugin(obj, init, pluginname) != 0) close_plugin(obj); } } #else #ifdef HAVE_LIBCURL init_add_plugin(NULL, hfile_plugin_init_libcurl, "libcurl"); #endif #ifdef ENABLE_GCS init_add_plugin(NULL, hfile_plugin_init_gcs, "gcs"); #endif #ifdef ENABLE_S3 init_add_plugin(NULL, hfile_plugin_init_s3, "s3"); #endif #endif // In the unlikely event atexit() fails, it's better to succeed here and // carry on; then eventually when the program exits, we'll merely close // down the plugins uncleanly, as if we had aborted. (void) atexit(hfile_exit); }
/** Create a new memoization data container structure and return a pointer to it @param[in] numContexts: Number of memoization contexts to store. @return: A new memoization data container, for storing and retreiving function calls by context */ MEMOIZATION_DATA_CONTAINER* newMemoizationContainer(unsigned int numContexts){ unsigned int i; MEMOIZATION_DATA_CONTAINER* container = malloc(sizeof(MEMOIZATION_DATA_CONTAINER)); container->numContexts = numContexts; container->contexts = calloc(numContexts, sizeof(khash_t(MEMO_CACHE)*)); container->isContextEnabled = calloc(numContexts, sizeof(int)); container->isCacheDirty = calloc(numContexts, sizeof(int)); for (i=0; i<numContexts; i++){ // All caches initially inactive by default. container->isContextEnabled[i] = 0; container->isCacheDirty[i] = 0; container->contexts[i] = kh_init(MEMO_CACHE); } return container; }
void mrb_define_method_vm(mrb_state *mrb, struct RClass *c, mrb_sym name, mrb_value body) { khash_t(mt) *h = c->mt; khiter_t k; struct RProc *p; if (!h) h = c->mt = kh_init(mt, mrb); k = kh_put(mt, h, name); p = mrb_proc_ptr(body); kh_value(h, k) = p; if (p) { mrb_field_write_barrier(mrb, (struct RBasic *)c, (struct RBasic *)p); } }