void xref(const char *name, FILE *fp, Table_T identifiers){ char buf[128]; if (name == NULL) name = ""; name = Atom_string(name); linenum = 1; while (getword(fp, buf, sizeof buf, first, rest)) { Set_T set; Table_T files; const char *id = Atom_string(buf); files = Table_get(identifiers, id); if (files == NULL) { files = Table_new(0, NULL, NULL); Table_put(identifiers, id, files); } set = Table_get(files, name); if (set == NULL) { set = Set_new(0, intcmp, inthash); Table_put(files, name, set); } { int *p = &linenum; if (!Set_member(set, p)) { NEW(p); *p = linenum; Set_put(set, p); } } } }
void cref(char *name, FILE *fp, Table_T identifiers) { char buf[512]; Text_T filename = { 0, "" }; int linenum; if (name) filename = Text_put(name); for (linenum = 1; fgets(buf, sizeof buf, fp) != NULL; linenum++) { Text_T id, line = Text_put(buf); while ((id = getword(&line, first, rest)).len > 0) { Ring_T ring; Table_T files; files = Table_get(identifiers, &id); if (files == NULL) { files = Table_new(0, textcmp, texthash); Table_put(identifiers, copy(id), files); } ring = Table_get(files, &filename); if (ring == NULL) { ring = Ring_new(); Table_put(files, copy(filename), ring); Ring_addlo(ring, Integer_new(linenum)); } else if (Integer_get(Ring_get(ring, 0)) != linenum) Ring_addlo(ring, Integer_new(linenum)); } } }
void kref(char *name, FILE *fp, Table_T identifiers) { char buf[512], *filename = ""; int linenum; if (name) filename = name; for (linenum = 1; fgets(buf, sizeof buf, fp) != NULL; linenum++) { int i, j; for (i = 0; (j = getword(buf, &i, first, rest)) > 0; i = j) { char *id = Str_sub(buf, j, i); const char *ln = Atom_int(linenum); Seq_T seq; Table_T files; files = Table_get(identifiers, id); if (files == NULL) { files = Table_new(0, (int (*)(const void *, const void *))strcmp, strhash); Table_put(identifiers, id, files); } else FREE(id); seq = Table_get(files, filename); if (seq == NULL) { seq = Seq_new(0); Table_put(files, Str_dup(filename, 1, 0, 1), seq); Seq_addlo(seq, (void *)ln); } else if (Seq_get(seq, 0) != ln) Seq_addlo(seq, (void *)ln); } } }
/* x is really a char ** */ static int bysegmentpos_compare_alpha (const void *x, const void *y) { char *acc1 = * (char **) x; char *acc2 = * (char **) y; Segmentpos_T a = (Segmentpos_T) Table_get(current_accsegmentpos_table,(void *) acc1); Segmentpos_T b = (Segmentpos_T) Table_get(current_accsegmentpos_table,(void *) acc2); return Segmentpos_compare_alpha(&a,&b); }
void wf(char *name, FILE *fp) { Table_T table = Table_new(0, NULL, NULL); char buf[128]; while (getword(fp, buf, sizeof buf, first, rest)) { const char *word; int i, *count; for (i = 0; buf[i] != '\0'; i++) buf[i] = tolower(buf[i]); word = Atom_string(buf); count = Table_get(table, word); if (count) (*count)++; else { NEW(count); *count = 1; Table_put(table, word, count); } } if (name) printf("%s:\n", name); { int i; void **array = Table_toArray(table, NULL); qsort(array, Table_length(table), 2*sizeof (*array), compare); for (i = 0; array[i]; i += 2) printf("%d\t%s\n", *(int *)array[i+1], (char *)array[i]); FREE(array); } Table_map(table, vfree, NULL); Table_free(&table); }
int exponent_table_get(exponent_table *E, const exponent expon) /* Returns the value associated to 'expon', returning zero, if 'expon' is not in the table */ { table_nvars = E->nvars; return (int) Table_get(E->table,expon); }
static int bysegmentpos_compare (const void *x, const void *y) { char *acc1 = * (char **) x; char *acc2 = * (char **) y; Segmentpos_T a = (Segmentpos_T) Table_get(current_accsegmentpos_table,(void *) acc1); Segmentpos_T b = (Segmentpos_T) Table_get(current_accsegmentpos_table,(void *) acc2); if (divsort == ALPHA_SORT) { return Segmentpos_compare_alpha(&a,&b); } else if (divsort == NUMERIC_ALPHA_SORT) { return Segmentpos_compare_numeric_alpha(&a,&b); } else if (divsort == CHROM_SORT) { return Segmentpos_compare_chrom(&a,&b); } else { abort(); } }
// for each fld in item, get the list from items and test each member in items against item static void _process(Table_T items, item_ *item) { for (int i = 0; item->object[i]; i++) { const oe_scalar key = item->object[i]; Set_T s = (Set_T) Table_get(items, key); if (!s) continue; bool done = _processSet( items, s, item, i ); if (done) break; } }
static void cApply(void** x, void* cl) { Position* p = (Position*) *x; struct applyStruct* e = (struct applyStruct*) cl; double vol = e->vol; if(e->volTable) vol = * (double*) Table_get(e->volTable, p->Contract); e->total += Contract_Price(p->Contract, e->evalTime, e->price, e->riskFree, vol) * p->Quantity; }
END_TEST START_TEST(test_get) { /* Table_get() with non-existant key returns NULL */ Table_T *table = Table_new(0, cmpatom, hashatom); Table_put(table, (void*)0x12, (void*)0x34); fail_unless( Table_length(table) == 1 ); fail_unless( Table_get(table, (void*)0x12) == (void*)0x34); /* non-existant key */ fail_unless( Table_get(table, (void*)0x34) == NULL); Table_remove(table, (void*)0x12); Table_free(&table); }
static int ssl_ctx_callback_impl(void* pvCurl, void* ctx, void* pvThis) { // locate the delegates FARPROC fpSslCtxDel; unsigned int* pnDelegates = (unsigned int*)Table_get(g_delegateTable, pvThis); if (!pnDelegates) return 0; fpSslCtxDel = (FARPROC)pnDelegates[5]; return fpSslCtxDel(ctx, pvThis); }
void addToTableHelp( Table_T fpTable, fpPair pair ) { List_T names = NULL; const char * fpAtom = Atom_string(pair.fp); // if the key does exist in the table // get the list already stored if( Table_get( fpTable, fpAtom ) != NULL ) { names = Table_get( fpTable, fpAtom ); } // pushes the the list names = List_push( names, pair.name); Table_put( fpTable, fpAtom, names ); free(pair.fp); // List_map( names , applyFree, NULL ); }
static int ioctl_callback_impl(void* pvCurl, int cmd, void* pvThis) { // locate the delegates FARPROC fpIoctlDel; unsigned int* pnDelegates = (unsigned int*)Table_get(g_delegateTable, pvThis); if (!pnDelegates) return 0; fpIoctlDel = (FARPROC)pnDelegates[6]; return fpIoctlDel(cmd, pvThis); }
void xref(const char *name, FILE *fp, Table_T identifiers){ char buf[128]; if (name == NULL){ name = ""; } name = Atom_string(name); linenum = 1; while (getword(fp, buf, sizeof(buf), first, rest)){ Set_T set; Table_T files; const char *id = Atom_string(buf); // files <- file table in identifiers associated with id files = Table_get(identifiers, id); if (files == NULL){ files = Table_new(0, NULL, NULL); Table_put(identifiers, id, files); } // set <- set in files associated with name set = Table_get(files, name); if (set == NULL){ set = Set_new(0, intcmp, inthash); Table_put(files, name, set); } // add linenum to set, if necessary { int *p = &linenum; if (!Set_member(set, p)){ NEW(p); *p = linenum; Set_put(set, p); } } } }
static int debug_callback_impl(void* pvCurl, int infoType, char* szMsg, size_t msgSize, void* pvThis) { // locate the delegates FARPROC fpDebugDel; unsigned int* pnDelegates = (unsigned int*)Table_get(g_delegateTable, pvThis); if (!pnDelegates) return 0; fpDebugDel = (FARPROC)pnDelegates[3]; return fpDebugDel(infoType, szMsg, msgSize, pvThis); }
static int progress_callback_impl(void* pvThis, double dlTotal, double dlNow, double ulTotal, double ulNow) { // locate the delegates FARPROC fpProgDel; unsigned int* pnDelegates = (unsigned int*)Table_get(g_delegateTable, pvThis); if (!pnDelegates) return 0; fpProgDel = (FARPROC)pnDelegates[2]; return fpProgDel(pvThis, dlTotal, dlNow, ulTotal, ulNow); }
static size_t header_callback_impl(char* szptr, size_t sz, size_t nmemb, void* pvThis) { // locate the delegates FARPROC fpHeaderDel; unsigned int* pnDelegates = (unsigned int*)Table_get(g_delegateTable, pvThis); if (!pnDelegates) return 0; fpHeaderDel = (FARPROC)pnDelegates[4]; return fpHeaderDel(szptr, sz, nmemb, pvThis); }
END_TEST START_TEST(test_put_in_same_bucket) { /* Our hash function always places key/vals in the same bucket - * assert that multiple items can be placed and retreived from * the same bucket */ Table_T *table = Table_new(0, cmpatom, hashatom); Table_put(table, (void*)0x12, (void*)0x34); Table_put(table, (void*)0x56, (void*)0x78); fail_unless( Table_length(table) == 2 ); fail_unless( Table_get(table, (void*)0x12) == (void*)0x34); fail_unless( Table_get(table, (void*)0x56) == (void*)0x78); Table_remove(table, (void*)0x12); Table_remove(table, (void*)0x56); Table_free(&table); }
static void unlock_callback_impl(void* pvHandle, int data, void* pvThis) { // locate the delegates FARPROC fpUnlockDel; unsigned int* pnDelegates = (unsigned int*)Table_get(g_shareDelegateTable, pvThis); if (pnDelegates) { fpUnlockDel = (FARPROC)pnDelegates[1]; fpUnlockDel(data, pvThis); } }
/* stabfend - called at end end of compiling a function */ static void stabfend(Symbol cfunc, int lineno) { int count = Seq_length(locals); for ( ; count > 0; count--) { Symbol p = Seq_remlo(locals); sym_symbol_ty sym = Table_get(uidTable, p); p->x.offset -= tos->x.offset; assert(sym); switch (sym->kind) { case sym_LOCAL_enum: sym->v.sym_LOCAL.offset = p->x.offset; break; case sym_PARAM_enum: sym->v.sym_PARAM.offset = p->x.offset; break; default: assert(0); } } tos = NULL; }
unsigned test_table() { Table_T tbl = Table_new(10, NULL, NULL); struct Test t1 = { 10, "Luca"}; char* s1 = TestToStr(&t1); const char* a1 = Atom_string(s1); char * result; Table_put(tbl, a1, "Luca"); result = (char*) Table_get(tbl, a1); test_assert(strcmp(result, "Luca") == 0); Table_free(&tbl); FREE(s1); Atom_freeAll(); return TEST_SUCCESS; }
/* symboluid - returns sym's uid, adding the symbol, if necessary */ static int symboluid(const Symbol p) { int uid; sym_symbol_ty sym; if (p == NULL) return 0; sym = Table_get(uidTable, p); if (sym != NULL) return sym->uid; uid = pickle->nuids++; switch (p->sclass) { case ENUM: sym = sym_ENUMCONST(p->name, uid, uname, NULL, 0, 0, p->u.value); sym->type = typeuid(inttype); break; case TYPEDEF: sym = sym_TYPEDEF(p->name, uid, uname, NULL, 0, 0); sym->type = typeuid(p->type); break; default: if (p->sclass == STATIC) { sym = sym_STATIC(p->name, uid, uname, NULL, 0, 0, Seq_length(statics)); Seq_addhi(statics, p); } else if (p->scope == GLOBAL || p->sclass == EXTERN) { sym = sym_GLOBAL(p->name, uid, uname, NULL, 0, 0, Seq_length(statics)); Seq_addhi(statics, p); } else if (p->scope == PARAM) sym = sym_PARAM(p->name, uid, uname, NULL, 0, 0, p->x.offset); else { assert(p->scope >= LOCAL); sym = sym_LOCAL(p->name, uid, uname, NULL, 0, 0, p->x.offset); } sym->type = typeuid(p->type); } Table_put(uidTable, p, sym); Seq_addhi(pickle->items, sym_Symbol(uid, sym)); sym->src = sym_coordinate(p->src.file ? p->src.file : string(""), p->src.x, p->src.y); sym->uplink = symboluid(up(p->up)); return sym->uid; }
END_TEST START_TEST(test_put_replace) { /* New values replace old values with the same key. */ Table_T *table = Table_new(0, cmpatom, hashatom); Table_put(table, (void*)0x12, (void*)0x34); Table_put(table, (void*)0x12, (void*)0x56); fail_unless( Table_length(table) == 1 ); fail_unless( Table_get(table, (void*)0x12) == (void*)0x56); Table_remove(table, (void*)0x12); Table_free(&table); }
/*Inserts the value into the table under the corresponding fingerprint*/ void insert_atom(Table_T* table, char* fingerprint, char* name) { const char *key; const char *value; Set_T old_set; /*Turns fingerprint and name strings into Hanson atoms*/ key = Atom_string(fingerprint); value = Atom_string(name); old_set = Table_get(*table, key); if (old_set == NULL) { Set_T new_set = Set_new(1, NULL, NULL); Set_put(new_set, value); Table_put(*table, key, new_set); } else { Set_put(old_set, value); } }
//calculate the most unique fld in item against the map of lists of templates //put the tuple in that list associated with the most unique key static int _add_template(T _this_, item_ *item) { Table_T items = _this_->items; //calc most unique key oe_scalar key = NULL; int key_idx = 0; int set_size = 0; Set_T curset = NULL; for ( int i = 0; item->object[i]; i++ ) { oe_scalar tmpkey = item->object[i]; if (strcmp("_", tmpkey) == 0) continue; //don't index by wildcard Set_T s = (Set_T) Table_get( items, tmpkey ); if (s) { int size = Set_length( s ); if ( !key || size < set_size ) { key = tmpkey; key_idx = i; set_size = size; curset = s; } } else { //found an unused key key = tmpkey; key_idx = i; set_size = 0; curset = Set_new( 10, _itemcmp, _itemhash ); Table_put( items, key, curset ); break; } } if (!curset) { OE_ERR(0, "Dispatcher can not add template, make sure it is not all '_' fields\n"); //i18n return -1; } item->items = curset; item->key_idx = key_idx; //for self remove of empty sets Set_put( curset, item ); return 0; }
terminal *terminalTable(Table_T termtable, subBoard state) { int player; int i; int w; int *canon = canonBoard(state); terminal *terms; if ((terms = Table_get(termtable, canon)) != 0) { free(canon); return terms; } terms = (terminal *) calloc(1, sizeof(terminal)); if ((w = win(state)) != 0) { terms->max = (w == 1) ? 1 : 0; terms->min = (w == -1) ? 1 : 0; } else if (countOpen(state) == 0) { terms->max = 0; terms->min = 0; } else { int childState[9]; memcpy(childState, state, 9*sizeof(int)); for (i = 0; i < 9; ++i) { if (childState[i] == 0) { for (player = 0; player < 2; ++player) { childState[i] = (2*player) - 1; terminal *childterm = terminalTable(termtable, childState); terms->max += childterm->max; terms->min += childterm->min; } childState[i] = 0; } } } Table_put(termtable, canon, terms); return terms; }
void store_name(char* fprint_buffer, char* name_buf, T* table, L* name_list) { const char* fprint = Atom_string(fprint_buffer); const char* name = Atom_string(name_buf); char **name_arr = (char**) List_toArray(*name_list, NULL); for(int z = 0; name_arr[z]; z++) { if(name_arr[z] == name) { fprintf(stderr, "Duplicate name detected: Ignoring input\n"); free (name_arr); return; } } free(name_arr); *name_list = List_push(*name_list, (void*) name); L list = (L) Table_get(*table, fprint); if (list == NULL) { list = List_list((char*) name, NULL); } else { list = List_push(list, (void*) name); } Table_put(*table, fprint, list); }
static void write_contig_file (char *genomesubdir, char *fileroot, Table_T accsegmentpos_table, Tableint_T chrlength_table, List_T contigtypelist) { FILE *textfp; char *textfile, *iitfile, *annot; int naccessions, i; char **accessions, *divstring; Segmentpos_T segmentpos; Chrom_T chrom; Genomicpos_T chroffset, universalpos1, universalpos2; List_T divlist = NULL, intervallist = NULL, labellist = NULL, annotlist = NULL, p; Table_T intervaltable, labeltable, annottable; Interval_T interval; #if 0 void **keys; int *values, ntypes; #endif if (divsort == NO_SORT) { accessions = (char **) Table_keys_by_timeindex(accsegmentpos_table,NULL); naccessions = Table_length(accsegmentpos_table); } else { /* Get accessions in order */ accessions = (char **) Table_keys(accsegmentpos_table,NULL); naccessions = Table_length(accsegmentpos_table); current_accsegmentpos_table = accsegmentpos_table; qsort(accessions,naccessions,sizeof(char *),bysegmentpos_compare); } #if 0 /* Get types in order */ keys = Tableint_keys(contigtype_table,NULL); values = Tableint_values(contigtype_table,0); ntypes = Tableint_length(contigtype_table); contigtypes = (char **) CALLOC(ntypes+1,sizeof(char *)); /* Add 1 for type 0 */ contigtypes[0] = ""; for (j = 0; j < ntypes; j++) { contigtypes[values[j]] = keys[j]; } FREE(values); FREE(keys); #endif /* Write contig text file */ textfile = (char *) CALLOC(strlen(genomesubdir)+strlen("/")+ strlen(fileroot)+strlen(".contig")+1,sizeof(char)); sprintf(textfile,"%s/%s.contig",genomesubdir,fileroot); /* Use binary, not text, so files are Unix-compatible */ if ((textfp = FOPEN_WRITE_BINARY(textfile)) == NULL) { fprintf(stderr,"Can't write to file %s\n",textfile); exit(9); } FREE(textfile); for (i = 0; i < naccessions; i++) { segmentpos = (Segmentpos_T) Table_get(accsegmentpos_table,(void *) accessions[i]); chrom = Segmentpos_chrom(segmentpos); chroffset = (Genomicpos_T) Tableint_get(chrlength_table,chrom); universalpos1 = chroffset + Segmentpos_chrpos1(segmentpos); universalpos2 = chroffset + Segmentpos_chrpos2(segmentpos); /* Print as 1-based, inclusive [a,b] */ if (Segmentpos_revcompp(segmentpos) == true) { fprintf(textfp,"%s\t%u..%u\t%s:%u..%u\t%u", accessions[i],universalpos2+1U,universalpos1, Chrom_string(chrom),Segmentpos_chrpos2(segmentpos)+1U,Segmentpos_chrpos1(segmentpos), Segmentpos_length(segmentpos)); } else { fprintf(textfp,"%s\t%u..%u\t%s:%u..%u\t%u", accessions[i],universalpos1+1U,universalpos2, Chrom_string(chrom),Segmentpos_chrpos1(segmentpos)+1U,Segmentpos_chrpos2(segmentpos), Segmentpos_length(segmentpos)); } #if 0 if (Segmentpos_type(segmentpos) > 0) { fprintf(textfp,"\t%s",contigtypes[Segmentpos_type(segmentpos)]); } #endif fprintf(textfp,"\n"); /* Store as 0-based, inclusive [a,b] */ labellist = List_push(labellist,(void *) accessions[i]); if (Segmentpos_revcompp(segmentpos) == true) { /* The negative sign in the interval is the indication that the contig was reverse complement */ intervallist = List_push(intervallist, (void *) Interval_new(universalpos2-1U,universalpos1, Segmentpos_type(segmentpos))); } else { intervallist = List_push(intervallist, (void *) Interval_new(universalpos1,universalpos2-1U, Segmentpos_type(segmentpos))); } #if 0 /* IIT version 1 */ sprintf(seglength,"%u",Segmentpos_length(segmentpos)); annot = (char *) CALLOC(strlen(seglength)+1,sizeof(char)); strcpy(annot,seglength); #else /* IIT versions >= 2 */ annot = (char *) CALLOC(1,sizeof(char)); annot[0] = '\0'; #endif annotlist = List_push(annotlist,(void *) annot); } fclose(textfp); #if 0 FREE(contigtypes); #endif FREE(accessions); intervallist = List_reverse(intervallist); /* contigtypelist = List_reverse(contigtypelist); -- Done by caller */ labellist = List_reverse(labellist); annotlist = List_reverse(annotlist); /* Write contig IIT file */ divstring = (char *) CALLOC(1,sizeof(char)); divstring[0] = '\0'; divlist = List_push(NULL,divstring); intervaltable = Table_new(65522,Table_string_compare,Table_string_hash); labeltable = Table_new(65522,Table_string_compare,Table_string_hash); annottable = Table_new(65522,Table_string_compare,Table_string_hash); Table_put(intervaltable,(void *) divstring,intervallist); Table_put(labeltable,(void *) divstring,labellist); Table_put(annottable,(void *) divstring,annotlist); iitfile = (char *) CALLOC(strlen(genomesubdir)+strlen("/")+ strlen(fileroot)+strlen(".contig.iit")+1,sizeof(char)); sprintf(iitfile,"%s/%s.contig.iit",genomesubdir,fileroot); #if 0 debug( for (p = contigtypelist; p != NULL; p = List_next(p)) { printf("Type %s\n",(char *) List_head(p)); } );
/* * Returns the internal sparse matrix from global table, or NULL if * not found. * */ SPBLASI_Matrix* SPBLASI_table_get(int i) { return (SPBLASI_Matrix *) Table_get(SPBLASI_Table, i); }