nTM *nTM_new(const char *filename, double alpha, double beta, double gamma) { nTM *model = (nTM *)malloc(sizeof(nTM)); model->filename = filename; model->corpus = line_corpus_new(filename); nTM_save_wordmap(model); model->interval = 200; model->alpha = alpha; model->beta = beta; model->gamma = gamma; model->nzws = count_list_new(); model->ndzs = count_list_new(); model->nzs = SparseCounts_new(100); model->unique_words = hash_new(20000); model->assignments = unsigned_array_new(1000); model->topics = 0; model->documents = 0; model->words = 0; return model; }
/* This function is called once, at assembler startup time. It should set up all the tables, etc. that the MD part of the assembler will need. */ void md_begin( void) { const char *retval = NULL; int lose = 0; register unsigned int i = 0; op_hash = hash_new(); if (op_hash == NULL) as_fatal("Virtual memory exhausted"); while (i < NUMOPCODES) { const char *name = pa_opcodes[i].name; retval = hash_insert(op_hash, (char *)name, (char *)&pa_opcodes[i]); if(retval != NULL && *retval != '\0') { as_fatal("Internal error: can't hash `%s': %s\n", pa_opcodes[i].name, retval); lose = 1; } ++i; } if (lose) as_fatal ("Broken assembler. No assembly attempted."); }
int emp_init() { config_add_stanza(&emp_stanza); phl_exempt_list = hash_new(64, NULL, NULL, NULL); return 0; }
int main() { struct hash *my_hash; int pot; int i; char *dummy; pot = 16; my_hash = hash_new( pot ); for ( i = 1; i <= ( 1 << pot ); i++ ) { sprintf( dummy, "dummy_%d", i ); hash_add( my_hash, dummy, "FOO" ); } hash_collision_stats( my_hash ); // if ( ( val = ( char * ) hash_get( my_hash, key ) ) != NULL ) { // printf( "Key: %s, Val: %s\n", key, val ); // } else { // printf( "Key: %s, Val: Not Found\n", key ); // } hash_destroy( my_hash ); return 0; }
static int test_hash_new(const struct test *t) { struct hash *h = hash_new(8, NULL); assert_return(h != NULL, EXIT_FAILURE); hash_free(h); return 0; }
struct harbor * harbor_create(void) { struct harbor * h = skynet_malloc(sizeof(*h)); memset(h,0,sizeof(*h)); h->map = hash_new(); return h; }
/* split key, value pairs into a hash */ static hash_t *_parse_digest_challenge(xmpp_ctx_t *ctx, const char *msg) { hash_t *result; unsigned char *text; char *key, *value; unsigned char *s, *t; text = (unsigned char *)xmpp_base64_decode_str(ctx, msg, strlen(msg)); if (text == NULL) { xmpp_error(ctx, "SASL", "couldn't Base64 decode challenge!"); return NULL; } result = hash_new(ctx, 10, xmpp_free); if (result != NULL) { s = text; while (*s != '\0') { /* skip any leading commas and spaces */ while ((*s == ',') || (*s == ' ')) s++; /* accumulate a key ending at '=' */ t = s; while ((*t != '=') && (*t != '\0')) t++; if (*t == '\0') break; /* bad string */ key = _make_string(ctx, (char *)s, (t-s)); if (key == NULL) break; /* advance our start pointer past the key */ s = t + 1; t = s; /* if we see quotes, grab the string in between */ if ((*s == '\'') || (*s == '"')) { t++; while ((*t != *s) && (*t != '\0')) t++; value = _make_string(ctx, (char *)s+1, (t-s-1)); if (*t == *s) { s = t + 1; } else { s = t; } /* otherwise, accumulate a value ending in ',' or '\0' */ } else { while ((*t != ',') && (*t != '\0')) t++; value = _make_string(ctx, (char *)s, (t-s)); s = t; } if (value == NULL) { xmpp_free(ctx, key); break; } /* TODO: check for collisions per spec */ hash_add(result, key, value); /* hash table now owns the value, free the key */ xmpp_free(ctx, key); } } xmpp_free(ctx, text); return result; }
int main() { struct hash * h = hash_new(); test(h); search(h); hash_delete(h); return 0; }
ct_hash *hash_intersection(ct_hash *a, ct_hash *b) { ct_hash *intersect = hash_new(a->size > b->size ? a->size : b->size); static_hash_intersect_other = b; static_hash_intersection = intersect; hash_foreach(a,&hash_intersection_helper); return intersect; }
void __objc_init_selector_tables() { __objc_selector_array = sarray_new (SELECTOR_HASH_SIZE, 0); __objc_selector_names = sarray_new (SELECTOR_HASH_SIZE, 0); __objc_selector_hash = hash_new (SELECTOR_HASH_SIZE, (hash_func_type) hash_string, (compare_func_type) compare_strings); }
void shell_run(tree_t e, struct tree_rd_ctx *ctx) { const int ndecls = tree_decls(e); hash_t *decl_hash = hash_new(ndecls * 2, true); for (int i = 0; i < ndecls; i++) { tree_t d = tree_decl(e, i); hash_put(decl_hash, tree_ident(d), d); } Tcl_Interp *interp = Tcl_CreateInterp(); bool have_quit = false; Tcl_CreateExitHandler(shell_exit_handler, &have_quit); shell_cmd_t shell_cmds[] = { CMD(quit, &have_quit, "Exit simulation"), CMD(run, ctx, "Start or resume simulation"), CMD(restart, NULL, "Restart simulation"), CMD(show, decl_hash, "Display simulation objects"), CMD(help, shell_cmds, "Display this message"), CMD(copyright, NULL, "Display copyright information"), CMD(signals, e, "Find signal objects in the design"), CMD(now, NULL, "Display current simulation time"), CMD(watch, decl_hash, "Trace changes to a signal"), CMD(unwatch, decl_hash, "Stop tracing signals"), { NULL, NULL, NULL, NULL} }; qsort(shell_cmds, ARRAY_LEN(shell_cmds) - 1, sizeof(shell_cmd_t), compare_shell_cmd); for (shell_cmd_t *c = shell_cmds; c->name != NULL; c++) Tcl_CreateObjCommand(interp, c->name, c->fn, c->cd, NULL); show_banner(); slave_post_msg(SLAVE_RESTART, NULL, 0); char *line; while (!have_quit && (line = shell_get_line())) { switch (Tcl_Eval(interp, line)) { case TCL_OK: break; case TCL_ERROR: errorf("%s", Tcl_GetStringResult(interp)); break; default: assert(false); } free(line); } Tcl_Exit(EXIT_SUCCESS); }
void viewTasksMemory(void){ pTable *tasksmemory; tasksmemory = hash_new((void *)free_task); getTasksMemory(tasksmemory); simpleViewTasks(tasksmemory); hash_delete(tasksmemory); }
/** Copy a stanza and its children. * This function copies a stanza along with all its children and returns * the new stanza and children with a reference count of 1. The returned * stanza will have no parent and no siblings. This function is useful * for extracting a child stanza for inclusion in another tree. * * @param stanza a Strophe stanza object * * @return a new Strophe stanza object * * @ingroup Stanza */ xmpp_stanza_t *xmpp_stanza_copy(const xmpp_stanza_t * const stanza) { xmpp_stanza_t *copy, *child, *copychild, *tail; hash_iterator_t *iter; const char *key; void *val; copy = xmpp_stanza_new(stanza->ctx); if (!copy) goto copy_error; copy->type = stanza->type; if (stanza->data) { copy->data = xmpp_strdup(stanza->ctx, stanza->data); if (!copy->data) goto copy_error; } if (stanza->attributes) { copy->attributes = hash_new(stanza->ctx, 8, xmpp_free); if (!copy->attributes) goto copy_error; iter = hash_iter_new(stanza->attributes); if (!iter) { printf("DEBUG HERE\n"); goto copy_error; } while ((key = hash_iter_next(iter))) { val = xmpp_strdup(stanza->ctx, (char *)hash_get(stanza->attributes, key)); if (!val) goto copy_error; if (hash_add(copy->attributes, key, val)) goto copy_error; } hash_iter_release(iter); } tail = copy->children; for (child = stanza->children; child; child = child->next) { copychild = xmpp_stanza_copy(child); if (!copychild) goto copy_error; copychild->parent = copy; if (tail) { copychild->prev = tail; tail->next = copychild; } else copy->children = copychild; tail = copychild; } return copy; copy_error: /* release all the hitherto allocated memory */ if (copy) xmpp_stanza_release(copy); return NULL; }
static struct stab_scope *stab_scope_new() { struct stab_scope *sc = M(struct stab_scope); sc->vars = hash_new(1 << 8, (HASH_FUNC) hash_string, (COMPARE_FUNC) streq, (FREE_FUNC) dummy_free, (FREE_FUNC) dummy_free); sc->funcs = hash_new(1 << 8, (HASH_FUNC) hash_string, (COMPARE_FUNC) streq, (FREE_FUNC) dummy_free, (FREE_FUNC) dummy_free); sc->types = hash_new(1 << 8, (HASH_FUNC) hash_string, (COMPARE_FUNC) streq, (FREE_FUNC) dummy_free, (FREE_FUNC) dummy_free); /* sc->expr_ty_cache = hash_new(1 << 8, (HASH_FUNC) hash_expr, (COMPARE_FUNC) ptreq, (FREE_FUNC) dummy_free, (FREE_FUNC) dummy_free); sc->path_ty_cache = hash_new(1 << 8, (HASH_FUNC) hash_path, (COMPARE_FUNC) patheq, (FREE_FUNC) dummy_free, (FREE_FUNC) dummy_free); */ return sc; }
void md_begin () { h8500_opcode_info *opcode; char prev_buffer[100]; int idx = 0; register relax_typeS *table; opcode_hash_control = hash_new (); prev_buffer[0] = 0; /* Insert unique names into hash table */ for (opcode = h8500_table; opcode->name; opcode++) { if (idx != opcode->idx) { hash_insert (opcode_hash_control, opcode->name, (char *) opcode); idx++; } } /* Initialize the relax table. We use a local variable to avoid warnings about modifying a supposedly const data structure. */ table = (relax_typeS *) md_relax_table; table[C (BRANCH, BYTE_DISP)].rlx_forward = BYTE_F; table[C (BRANCH, BYTE_DISP)].rlx_backward = BYTE_B; table[C (BRANCH, BYTE_DISP)].rlx_length = 2; table[C (BRANCH, BYTE_DISP)].rlx_more = C (BRANCH, WORD_DISP); table[C (BRANCH, WORD_DISP)].rlx_forward = WORD_F; table[C (BRANCH, WORD_DISP)].rlx_backward = WORD_B; table[C (BRANCH, WORD_DISP)].rlx_length = 3; table[C (BRANCH, WORD_DISP)].rlx_more = 0; table[C (SCB_F, BYTE_DISP)].rlx_forward = BYTE_F; table[C (SCB_F, BYTE_DISP)].rlx_backward = BYTE_B; table[C (SCB_F, BYTE_DISP)].rlx_length = 3; table[C (SCB_F, BYTE_DISP)].rlx_more = C (SCB_F, WORD_DISP); table[C (SCB_F, WORD_DISP)].rlx_forward = WORD_F; table[C (SCB_F, WORD_DISP)].rlx_backward = WORD_B; table[C (SCB_F, WORD_DISP)].rlx_length = 8; table[C (SCB_F, WORD_DISP)].rlx_more = 0; table[C (SCB_TST, BYTE_DISP)].rlx_forward = BYTE_F; table[C (SCB_TST, BYTE_DISP)].rlx_backward = BYTE_B; table[C (SCB_TST, BYTE_DISP)].rlx_length = 3; table[C (SCB_TST, BYTE_DISP)].rlx_more = C (SCB_TST, WORD_DISP); table[C (SCB_TST, WORD_DISP)].rlx_forward = WORD_F; table[C (SCB_TST, WORD_DISP)].rlx_backward = WORD_B; table[C (SCB_TST, WORD_DISP)].rlx_length = 10; table[C (SCB_TST, WORD_DISP)].rlx_more = 0; }
void macro_init (int alternate, int mri, int strip_at, size_t (*exp) (const char *, size_t, sb *, offsetT *)) { macro_hash = hash_new (); macro_defined = 0; macro_alternate = alternate; macro_mri = mri; macro_strip_at = strip_at; macro_expr = exp; }
void symbol_begin( void) { symbol_lastP = NULL; symbol_rootP = NULL; /* In case we have 0 symbols (!!) */ sy_hash = hash_new(); memset((char *)(&abs_symbol), '\0', sizeof(abs_symbol)); abs_symbol.sy_type = N_ABS; /* Can't initialise a union. Sigh. */ fb_label_init (); }
void viewVFS(char *file){ pTable *vfs; vfs = hash_new((void *)free_sops); getVFSMemory(vfs, file); simpleViewVFS(vfs); hash_delete(vfs); }
void macro_init (int alternate, int mri, int strip_at, int (*expr) (const char *, int, sb *, int *)) { macro_hash = hash_new (); macro_defined = 0; macro_alternate = alternate; macro_mri = mri; macro_strip_at = strip_at; macro_expr = expr; }
int hna_global_init(struct bat_priv *bat_priv) { if (bat_priv->hna_global_hash) return 1; bat_priv->hna_global_hash = hash_new(128, compare_orig, choose_orig); if (!bat_priv->hna_global_hash) return 0; return 1; }
int hna_global_init(void) { if (hna_global_hash) return 1; hna_global_hash = hash_new(128, compare_orig, choose_orig); if (!hna_global_hash) return 0; return 1; }
void md_begin () { sh_opcode_info *opcode; char *prev_name = ""; opcode_hash_control = hash_new (); /* Insert unique names into hash table */ for (opcode = sh_table; opcode->name; opcode++) { if (strcmp (prev_name, opcode->name)) { prev_name = opcode->name; hash_insert (opcode_hash_control, opcode->name, (char *) opcode); } else { /* Make all the opcodes with the same name point to the same string */ opcode->name = prev_name; } } /* Initialize the relax table */ md_relax_table[C (COND_JUMP, COND8)].rlx_forward = COND8_F; md_relax_table[C (COND_JUMP, COND8)].rlx_backward = COND8_M; md_relax_table[C (COND_JUMP, COND8)].rlx_length = COND8_LENGTH; md_relax_table[C (COND_JUMP, COND8)].rlx_more = C (COND_JUMP, COND12); md_relax_table[C (COND_JUMP, COND12)].rlx_forward = COND12_F; md_relax_table[C (COND_JUMP, COND12)].rlx_backward = COND12_M; md_relax_table[C (COND_JUMP, COND12)].rlx_length = COND12_LENGTH; md_relax_table[C (COND_JUMP, COND12)].rlx_more = C (COND_JUMP, COND32); md_relax_table[C (COND_JUMP, COND32)].rlx_forward = COND32_F; md_relax_table[C (COND_JUMP, COND32)].rlx_backward = COND32_M; md_relax_table[C (COND_JUMP, COND32)].rlx_length = COND32_LENGTH; md_relax_table[C (COND_JUMP, COND32)].rlx_more = 0; md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_forward = UNCOND12_F; md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_backward = UNCOND12_M; md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_length = UNCOND12_LENGTH; md_relax_table[C (UNCOND_JUMP, UNCOND12)].rlx_more = C (UNCOND_JUMP, UNCOND32); md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_forward = UNCOND32_F; md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_backward = UNCOND32_M; md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_length = UNCOND32_LENGTH; md_relax_table[C (UNCOND_JUMP, UNCOND32)].rlx_more = 0; }
libconf_t * libconf_init( const char * global_config_filename, const char * local_config_filename, const libconf_opt_t ** options, const libconf_optparam_t ** defaults, int argc, const char ** argv) { int i; libconf_opt_t ** t_options; libconf_t * retval = (libconf_t *)malloc(sizeof(libconf_t)); memset(retval, 0, sizeof(libconf_t)); if (global_config_filename != NULL) retval->global_config_filename = strdup(global_config_filename); if (local_config_filename != NULL) retval->local_config_filename = strdup(local_config_filename); retval->options = hash_new(0, hash_hlp_string_hash, hash_hlp_string_cmp); t_options = libconf_defaultopts(); for (i = 0; t_options[i]; i++) { hash_put(retval->options, strdup(t_options[i]->co_name), t_options[i]); } free(t_options); // note: shallow free because the contents is in the hash t_options = libconf_optdup(options); for (i = 0; t_options[i]; i++) { hash_put(retval->options, strdup(t_options[i]->co_name), t_options[i]); } free(t_options); // note: shallow free because the contents is in the hash retval->option_hash = hash_new(0, hash_hlp_string_hash, hash_hlp_string_cmp); retval->tmp_hash = hash_new(0, hash_hlp_string_hash, hash_hlp_string_cmp); retval->argc = argc; retval->argv = (char**)calloc(argc + 1, sizeof(char*)); for (i = 0; i < argc; i++) retval->argv[i] = strdup(argv[i]); if (defaults) retval->defaults = libconf_optparams_dup(defaults); return retval; }
void viewHiddenTasks(void){ pTable *tasksmemory; pTable *tasksproc; pTable *tasksprocforce; pTable *tasksps; pTable *taskskill; pTable *taskscheck; tasksmemory = hash_new((void *)free_task); tasksproc = hash_new((void *)free_task); tasksprocforce = hash_new((void *)free_task); tasksps = hash_new((void *)free_task); taskskill = hash_new((void *)free_task); taskscheck = hash_new((void *)free_task); getTasksMemory(tasksmemory); getTasksProc(tasksproc); getTasksProcForce(tasksprocforce); getTasksPS(tasksps); getTasksKill(taskskill); checkTasks(tasksproc, tasksps, taskscheck); checkTasks(tasksprocforce, tasksproc, taskscheck); checkTasks(tasksmemory, tasksproc, taskscheck); checkTasks(taskskill, tasksproc, taskscheck); viewCheckTasks(taskscheck); hash_delete(tasksmemory); hash_delete(tasksproc); hash_delete(tasksprocforce); hash_delete(tasksps); hash_delete(taskskill); hash_delete(taskscheck); }
int main( int argc, char * argv[] ) { TreeNode * syntaxTree; char pgm[120]; /* source code file name */ hash_new(&h); if (argc < 2) { fprintf(stderr,"usage: %s <filename>\n",argv[0]); exit(1); } if (argc == 3) { if(strcmp(argv[2], "-a") == 0) { TraceScan = FALSE; TraceAnalyze = FALSE; } else if(strcmp(argv[2], "-s") == 0) { TraceScan = FALSE; TraceParse = FALSE; } } strcpy(pgm,argv[1]) ; if (strchr (pgm, '.') == NULL) strcat(pgm,".cm"); source = fopen(pgm,"r"); if (source==NULL) { fprintf(stderr,"File %s not found\n",pgm); exit(1); } listing = stdout; /* send listing to screen */ fprintf(listing,"\nC Minus compilation: %s\n",pgm); #if NO_PARSE //if(a_flag == 0) while( (ttype=getToken())!= 0 ) printToken( ttype, tokenString ); #else syntaxTree = parse(); if (TraceParse) { fprintf(listing,"\nSyntax tree:\n"); printTree(syntaxTree); } if(TraceAnalyze) { fprintf(listing, "\nSymbol Table:\n"); print_hash(h); } list_kill(l); hash_kill(&h); #endif fclose(source); return 0; }
sql_exp * exps_bind_column( list *exps, char *cname, int *ambiguous ) { sql_exp *e = NULL; if (exps && cname) { node *en; if (exps && !exps->ht && list_length(exps) > HASH_MIN_SIZE) { exps->ht = hash_new(exps->sa, list_length(exps), (fkeyvalue)&exp_key); for (en = exps->h; en; en = en->next ) { sql_exp *e = en->data; if (e->name) { int key = exp_key(e); hash_add(exps->ht, key, e); } } } if (exps && exps->ht) { int key = hash_key(cname); sql_hash_e *he = exps->ht->buckets[key&(exps->ht->size-1)]; for (; he; he = he->chain) { sql_exp *ce = he->value; if (ce->name && strcmp(ce->name, cname) == 0) { if (e) { if (ambiguous) *ambiguous = 1; return NULL; } e = ce; } } return e; } for (en = exps->h; en; en = en->next ) { sql_exp *ce = en->data; if (ce->name && strcmp(ce->name, cname) == 0) { if (e) { if (ambiguous) *ambiguous = 1; return NULL; } e = ce; } } } return e; }
int handleCounter( void* userData, uint64_t time, uint32_t process, uint32_t counter, uint64_t value ) { uint64_t i = 0; double valueDif = 0.0; double timeDif = 0.0; double rate = 0.0; mapInfoProcessT *currentElement = NULL; definitionInfoT *info = (definitionInfoT*)userData; while( (i < info->counterCounterDefinition) && (info->counters[i].id != counter)) { i++; } if( i >= info->counterCounterDefinition ) return OTF_RETURN_ABORT; /*for the counter type*/ if( ((info->counters[i].properties) & OTF_COUNTER_TYPE_BITS) == OTF_COUNTER_TYPE_ACC ) { if( (info->counters)[i].processMap == NULL ) (info->counters)[i].processMap = hash_new(); /*calculate the current counter rate*/ currentElement = hash_search( info->counters[i].processMap, process ); if( !currentElement ) { currentElement = hash_add( info->counters[i].processMap, process ); } else { valueDif = value - currentElement->lastValue; timeDif = time - currentElement->lastTime; if( timeDif > 0 ) { rate = (valueDif / timeDif) * (double)(info->timerResolution); } if( rate > currentElement->highestRate ) currentElement->highestRate = rate; } currentElement->lastValue = value; currentElement->lastTime = time; } return OTF_RETURN_OK; }
static const where * get_where( int line, const char *file ) { static int init_done = 0; static hash *cache = NULL; static buffer work; where *w; int err; size_t sz; if ( !file ) { return NULL; } if ( !init_done ) { if ( err = buffer_init( &work, 256, 64 ), ERR_None != err ) { nomem( ); } if ( err = hash_new( 1000, &cache ), ERR_None != err ) { nomem( ); } init_done = 1; } sz = sizeof( where ) + strlen( file ) + 1; if ( err = buffer_ensure( &work, sz ), ERR_None != err ) { nomem( ); } w = ( where * ) work.buf; w->line = line; strcpy( ( char * ) ( w + 1 ), file ); /* Already got it? */ if ( w = ( where * ) hash_get( cache, w, sz ), NULL != w ) { return w; } if ( w = malloc( sz ), !w ) { nomem( ); } memcpy( w, work.buf, sz ); /* Add it to cache */ if ( err = hash_put( cache, w, sz, w ), ERR_None != err ) { nomem( ); } return w; }
alist_t * alist_xnew(int nbuckets, void (*namefree)(void *), void (*valfree)(void *), int (*hashfn)(int, void *), int (*cmpfn)(void *, void *)) { alist_t *alist; alist = xcalloc(sizeof (alist_t)); alist->al_elements = hash_new(nbuckets, hashfn, cmpfn); alist->al_namefree = namefree; alist->al_valfree = valfree; return (alist); }
user_t * user_get(char *user) { user_t *u; if(users == NULL) { users = hash_new(hash_str_cmp, hash_str_hash, 8); } u = hash_get(users, user); if(u) return u; return user_new(user); }