void gt_type_graph_add_stanza(GtTypeGraph *type_graph, const GtOBOStanza *stanza) { const char *id_value, *name_value; GtUword i, size; GtTypeNode *node; GtStr *buf; gt_assert(type_graph && stanza && !type_graph->ready); gt_assert(gt_obo_stanza_size(stanza, "id") == 1); gt_assert(gt_obo_stanza_size(stanza, "name") == 1); id_value = gt_symbol(gt_obo_stanza_get_value(stanza, "id", 0)); name_value = gt_symbol(gt_obo_stanza_get_value(stanza, "name", 0)); gt_assert(id_value); gt_assert(name_value); gt_assert(!gt_hashmap_get(type_graph->nodemap, id_value)); node = gt_type_node_new(gt_array_size(type_graph->nodes), id_value); gt_hashmap_add(type_graph->name2id, (char*) name_value, (char*) id_value); gt_hashmap_add(type_graph->id2name, (char*) id_value, (char*) name_value); gt_hashmap_add(type_graph->nodemap, (char*) id_value, node); gt_array_add(type_graph->nodes, node); buf = gt_str_new(); /* store is_a entries in node, if necessary */ if ((size = gt_obo_stanza_size(stanza, "is_a"))) { for (i = 0; i < size; i++) { const char *id = gt_obo_stanza_get_value(stanza, "is_a", i); gt_str_reset(buf); gt_str_append_cstr_nt(buf, id, strcspn(id, " \n")); gt_type_node_is_a_add(node, gt_symbol(gt_str_get(buf))); } } /* store part_of entries in node, if necessary */ if ((size = gt_obo_stanza_size(stanza, "relationship"))) { for (i = 0; i < size; i++) { const char *rel = gt_obo_stanza_get_value(stanza, "relationship", i); gt_str_reset(buf); /* match part_of */ if (!strncmp(rel, PART_OF, strlen(PART_OF))) { const char *part_of = rel + strlen(PART_OF) + 1; gt_str_append_cstr_nt(buf, part_of, strcspn(part_of, " \n")); gt_type_node_part_of_add(node, gt_symbol(gt_str_get(buf))); continue; } /* match member_of */ if (!strncmp(rel, MEMBER_OF, strlen(MEMBER_OF))) { const char *member_of = rel + strlen(MEMBER_OF) + 1; gt_str_append_cstr_nt(buf, member_of, strcspn(member_of, " \n")); gt_type_node_part_of_add(node, gt_symbol(gt_str_get(buf))); continue; } /* match integral_part_of */ if (!strncmp(rel, INTEGRAL_PART_OF, strlen(INTEGRAL_PART_OF))) { const char *integral_part_of = rel + strlen(INTEGRAL_PART_OF) + 1; gt_str_append_cstr_nt(buf, integral_part_of, strcspn(integral_part_of, " \n")); gt_type_node_part_of_add(node, gt_symbol(gt_str_get(buf))); } } } gt_str_delete(buf); }
void gt_feature_info_add(GtFeatureInfo *fi, const char *id, GtFeatureNode *fn) { gt_assert(fi && id && fn); gt_assert(!gt_feature_node_is_pseudo((GtFeatureNode*) fn)); gt_hashmap_add(fi->id_to_genome_node, gt_cstr_dup(id), gt_genome_node_ref((GtGenomeNode*) fn)); }
static void* fileopen_generic(FA *fa, const char *path, const char *mode, GtFileMode genfilemode, bool x, const char *filename, int line, GtError *err) { void *fp = NULL; FAFileInfo *fileinfo; gt_error_check(err); gt_assert(fa && path && mode); fileinfo = gt_malloc(sizeof (FAFileInfo)); fileinfo->filename = filename; fileinfo->line = line; switch (genfilemode) { case GFM_UNCOMPRESSED: fp = x ? gt_xfopen(path, mode) : gt_efopen(path, mode, err); break; case GFM_GZIP: fp = x ? gt_xgzopen(path, mode) : gt_egzopen(path, mode, err); break; case GFM_BZIP2: fp = x ? gt_xbzopen(path, mode) : gt_ebzopen(path, mode, err); break; default: gt_assert(0); } if (fp) gt_hashmap_add(fa->file_pointer, fp, fileinfo); else gt_free(fileinfo); return fp; }
void* gt_realloc_mem(void *ptr, size_t size, const char *src_file, int src_line) { MAInfo *mainfo; void *mem; gt_assert(ma); if (ma->bookkeeping) { gt_mutex_lock(bookkeeping_lock); ma->mallocevents++; if (ptr) { mainfo = gt_hashmap_get(ma->allocated_pointer, ptr); gt_assert(mainfo); subtract_size(ma, mainfo->size); gt_hashmap_remove(ma->allocated_pointer, ptr); } mainfo = xmalloc(sizeof *mainfo, ma->current_size, src_file, src_line); mainfo->size = size; mainfo->src_file = src_file; mainfo->src_line = src_line; mem = xrealloc(ptr, size, ma->current_size, src_file, src_line); gt_hashmap_add(ma->allocated_pointer, mem, mainfo); add_size(ma, size); gt_mutex_unlock(bookkeeping_lock); return mem; } return xrealloc(ptr, size, ma->current_size, src_file, src_line); }
static void include_feature(GtDlist *trees, GtHashmap *target_to_elem, GtFeatureNode *feature, GtStr *key) { gt_dlist_add(trees, feature); gt_hashmap_add(target_to_elem, gt_cstr_dup(gt_str_get(key)), gt_dlist_last(trees)); }
GtFeatureIndex *agn_import_simple(int numfiles, const char **filenames, char *type, AgnLogger *logger) { GtFeatureIndex *features = gt_feature_index_memory_new(); GtNodeStream *gff3 = gt_gff3_in_stream_new_unsorted(numfiles, filenames); gt_gff3_in_stream_check_id_attributes((GtGFF3InStream *)gff3); gt_gff3_in_stream_enable_tidy_mode((GtGFF3InStream *)gff3); GtHashmap *typestokeep = gt_hashmap_new(GT_HASH_STRING, NULL, NULL); gt_hashmap_add(typestokeep, type, type); GtNodeStream *filterstream = agn_filter_stream_new(gff3, typestokeep); GtNodeStream *featstream = gt_feature_out_stream_new(filterstream, features); GtError *error = gt_error_new(); int result = gt_node_stream_pull(featstream, error); if(result == -1) { agn_logger_log_error(logger, "error processing node stream: %s", gt_error_get(error)); } gt_error_delete(error); if(agn_logger_has_error(logger)) { gt_feature_index_delete(features); features = NULL; } gt_node_stream_delete(gff3); gt_node_stream_delete(filterstream); gt_node_stream_delete(featstream); return features; }
void gt_feature_info_add_pseudo_parent(GtFeatureInfo *fi, const char *id, GtFeatureNode *pseudo_parent) { gt_assert(fi && id && pseudo_parent); gt_assert(gt_feature_node_is_pseudo((GtFeatureNode*) pseudo_parent)); gt_hashmap_add(fi->id_to_pseudo_parent, gt_cstr_dup(id), gt_genome_node_ref((GtGenomeNode*) pseudo_parent)); }
void gt_toolbox_add(GtToolbox *tb, const char *toolname, GtToolfunc toolfunc) { GtToolinfo *toolinfo; gt_assert(tb && tb->tools); toolinfo = gt_toolinfo_new(); toolinfo->toolfunc = toolfunc; gt_hashmap_add(tb->tools, (char*) toolname, toolinfo); }
static void gv_test_calc_integrity(AgnUnitTest *test) { const char *filename = "data/gff3/gaeval-stream-unit-test-2.gff3"; GtNodeStream *align_in = gt_gff3_in_stream_new_unsorted(1, &filename); AgnGaevalParams params = { 0.6, 0.3, 0.05, 0.05, 400, 200, 100 }; GtNodeVisitor *nv = agn_gaeval_visitor_new(align_in, params); AgnGaevalVisitor *gv = gaeval_visitor_cast(nv); gt_node_stream_delete(align_in); GtNodeStream *gff3in = gt_gff3_in_stream_new_unsorted(1, &filename); GtHashmap *typestokeep = gt_hashmap_new(GT_HASH_STRING, NULL, NULL); gt_hashmap_add(typestokeep, "mRNA", "mRNA"); GtNodeStream *filtstream = agn_filter_stream_new(gff3in, typestokeep); GtLogger *logger = gt_logger_new(true, "", stderr); GtNodeStream *ics = agn_infer_cds_stream_new(filtstream, NULL, logger); GtNodeStream *ies = agn_infer_exons_stream_new(ics, NULL, logger); GtError *error = gt_error_new(); GtArray *feats = gt_array_new( sizeof(GtFeatureNode *) ); GtNodeStream *featstream = gt_array_out_stream_new(ies, feats, error); int result = gt_node_stream_pull(featstream, error); if(result == -1) { fprintf(stderr, "[AgnGaevalVisitor::gv_test_calc_integrity] error " "processing GFF3: %s\n", gt_error_get(error)); return; } gt_node_stream_delete(gff3in); gt_node_stream_delete(filtstream); gt_node_stream_delete(featstream); gt_node_stream_delete(ics); gt_node_stream_delete(ies); gt_logger_delete(logger); gt_hashmap_delete(typestokeep); agn_assert(gt_array_size(feats) == 2); GtFeatureNode *g1 = *(GtFeatureNode **)gt_array_get(feats, 0); GtFeatureNode *g2 = *(GtFeatureNode **)gt_array_get(feats, 1); double cov1 = gaeval_visitor_calculate_coverage(gv, g1, error); double cov2 = gaeval_visitor_calculate_coverage(gv, g2, error); double int1 = gaeval_visitor_calculate_integrity(gv, g1, cov1, NULL, error); double int2 = gaeval_visitor_calculate_integrity(gv, g2, cov2, NULL, error); bool test1 = fabs(cov1 - 1.000) < 0.001 && fabs(cov2 - 0.997) < 0.001 && fabs(int1 - 0.850) < 0.001 && fabs(int2 - 0.863) < 0.001; agn_unit_test_result(test, "calculate integrity", test1); gt_error_delete(error); gt_array_delete(feats); gt_genome_node_delete((GtGenomeNode *)g1); gt_genome_node_delete((GtGenomeNode *)g2); gt_node_visitor_delete(nv); }
void gt_xrf_abbr_entry_add(GtXRFAbbrEntry *abbr_entry, const char *tag, const char *value) { GtStr *s; gt_assert(abbr_entry && tag && value); if (!(s = gt_hashmap_get(abbr_entry->content, tag))) { s = gt_str_new_cstr(value); gt_hashmap_add(abbr_entry->content, gt_cstr_dup(tag), s); } }
static void build_md5map(GtMD5Tab *md5_tab) { GtUword i; gt_assert(md5_tab); md5_tab->md5map = gt_hashmap_new(GT_HASH_STRING, NULL, NULL); for (i = 0; i < md5_tab->num_of_md5s; i++) { gt_hashmap_add(md5_tab->md5map, (void*) gt_md5_tab_get(md5_tab, i), (void*) (i + 1)); } }
void gt_toolbox_add_hidden_tool(GtToolbox *tb, const char *toolname, GtTool *tool) { GtToolinfo *toolinfo; gt_assert(tb && tb->tools); toolinfo = gt_toolinfo_new(); toolinfo->tool= tool; toolinfo->hidden = true; gt_hashmap_add(tb->tools, (char*) toolname, toolinfo); }
static int handle_description(GtSeqid2SeqnumMapping *mapping, const char *desc, GtUword seqnum, GtUword filenum, GtError *err) { GtRange descrange; GtUword j; int had_err = 0; SeqidInfo *seqid_info; if (gt_parse_description_range(desc, &descrange)) { /* no offset could be parsed -> store description as sequence id */ descrange.start = 1; descrange.end = GT_UNDEF_UWORD; if ((seqid_info = gt_hashmap_get(mapping->map, desc))) { had_err = seqid_info_add(seqid_info, seqnum, filenum, &descrange, mapping->filename, desc, err); gt_assert(had_err); /* adding a seqid without range should fail */ } else { seqid_info = seqid_info_new(seqnum, filenum, &descrange); gt_hashmap_add(mapping->map, gt_cstr_dup(desc), seqid_info); } } else { char *dup; /* offset could be parsed -> store description up to ':' as sequence id */ j = 0; while (desc[j] != ':') j++; dup = gt_malloc((j + 1) * sizeof *dup); strncpy(dup, desc, j); dup[j] = '\0'; if ((seqid_info = gt_hashmap_get(mapping->map, dup))) { had_err = seqid_info_add(seqid_info, seqnum, filenum, &descrange, mapping->filename, dup, err); gt_free(dup); } else { seqid_info = seqid_info_new(seqnum, filenum, &descrange); gt_hashmap_add(mapping->map, dup, seqid_info); } } return had_err; }
static GtStr* get_seqid(GtBEDParser *bed_parser) { GtStr *seqid = gt_hashmap_get(bed_parser->seqid_to_str_mapping, gt_str_get(bed_parser->word)); if (!seqid) { seqid = gt_str_new_cstr(gt_str_get(bed_parser->word)); gt_hashmap_add(bed_parser->seqid_to_str_mapping, gt_str_get(seqid), seqid); } gt_assert(seqid); return seqid; }
void gt_seq_info_cache_add(GtSeqInfoCache *sic, const char *key, const GtSeqInfo *si) { GtSeqInfo *si_dup; gt_assert(sic && key && si); gt_assert(!gt_seq_info_cache_get(sic, key)); si_dup = gt_malloc(sizeof *si_dup); si_dup->filenum = si->filenum; si_dup->seqnum = si->seqnum; gt_hashmap_add(sic->cache, gt_cstr_dup(key), si_dup); }
static NodeInfoElement* nodeinfo_get(GtDiagram *d, GtFeatureNode *node) { NodeInfoElement *ni; gt_assert(d && node); if (!(ni = gt_hashmap_get(d->nodeinfo, node))) { ni = gt_calloc(1, sizeof (NodeInfoElement)); ni->type_index = gt_hashmap_new(GT_HASH_STRING, NULL, gt_free_func); ni->types = gt_str_array_new(); gt_hashmap_add(d->nodeinfo, node, ni); } return ni; }
int main(int argc, char **argv) { if(argc != 2) { fputs("usage: vang schema.file\n", stderr); return 1; } gt_lib_init(); char *schemafile = argv[1]; FILE *schema = fopen(schemafile, "r"); if(schema == NULL) { fprintf(stderr, "error: unable to open schema file '%s'\n", schemafile); return 1; } GtArray *entry_datatypes = gt_array_new( sizeof(char *) ); GtHashmap *entries = gt_hashmap_new( GT_HASH_STRING, NULL, (GtFree)vang_schema_entry_delete ); VangSchemaEntry *entry; while( (entry = vang_schema_entry_next(schema)) != NULL ) { char *datatype = (char *)vang_schema_entry_get_datatype(entry); VangSchemaEntry *testentry = gt_hashmap_get(entries, datatype); if(testentry != NULL) { fprintf( stderr, "warning: already have an entry for data type '%s'; " "replacing\n", datatype ); vang_schema_entry_delete(testentry); } gt_hashmap_add(entries, datatype, entry); gt_array_add(entry_datatypes, datatype); } unsigned long i; for(i = 0; i < gt_array_size(entry_datatypes); i++) { const char *type = *(const char **)gt_array_get(entry_datatypes, i); VangSchemaEntry *entry = gt_hashmap_get(entries, type); vang_schema_entry_to_string(entry, stdout); puts(""); } gt_array_delete(entry_datatypes); gt_hashmap_delete(entries); gt_lib_clean(); return 0; }
static int add_id(GtFeatureNode *fn, void *data, GT_UNUSED GtError *err) { AddIDInfo *info = (AddIDInfo*) data; GtArray *parent_features = NULL; gt_error_check(err); gt_assert(fn && info && info->gt_feature_node_to_id_array && info->id); parent_features = gt_hashmap_get(info->gt_feature_node_to_id_array, fn); if (!parent_features) { parent_features = gt_array_new(sizeof (char*)); gt_hashmap_add(info->gt_feature_node_to_id_array, fn, parent_features); } gt_array_add(parent_features, info->id); return 0; }
static int gt_regioncov_visitor_region_node(GtNodeVisitor *nv, GtRegionNode *rn, GT_UNUSED GtError *err) { GtRegionCovVisitor *regioncov_visitor; GtArray *rangelist; gt_error_check(err); regioncov_visitor = gt_regioncov_visitor_cast(nv); rangelist = gt_array_new(sizeof (GtRange)); gt_hashmap_add(regioncov_visitor->region2rangelist, gt_cstr_dup(gt_str_get(gt_genome_node_get_seqid((GtGenomeNode*) rn))), rangelist); return 0; }
static void nodeinfo_add_block(NodeInfoElement *ni, const char *gft, GtFeatureNode *rep, GtBlock *block) { GtBlockTuple *bt; PerTypeInfo *type_struc = NULL; gt_assert(ni); bt = blocktuple_new(gft, rep, block); if (!(ni->type_index)) { ni->type_index = gt_hashmap_new(GT_HASH_STRING, NULL, gt_free_func); } if (!(type_struc = gt_hashmap_get(ni->type_index, gft))) { type_struc = gt_calloc(1, sizeof (PerTypeInfo)); type_struc->rep_index = gt_hashmap_new(GT_HASH_DIRECT, NULL, NULL); type_struc->blocktuples = gt_array_new(sizeof (GtBlockTuple*)); gt_hashmap_add(ni->type_index, (char*) gft, type_struc); gt_str_array_add_cstr(ni->types, gft); } gt_hashmap_add(type_struc->rep_index, rep, bt); if (rep != GT_UNDEF_REPR) type_struc->must_merge = true; gt_array_add(type_struc->blocktuples, bt); }
static int check_cds_phases_if_necessary(GtFeatureNode *fn, GtCDSCheckVisitor *v, bool second_pass, GtError *err) { GtFeatureNodeIterator *fni; GtFeatureNode *node; GtArray *cds_features = NULL; GtHashmap *multi_features = NULL; int had_err = 0; gt_error_check(err); gt_assert(fn); fni = gt_feature_node_iterator_new_direct(fn); while ((node = gt_feature_node_iterator_next(fni))) { if (gt_feature_node_has_type(node, gt_ft_CDS)) { if (gt_feature_node_is_multi(node)) { GtArray *features; if (!multi_features) multi_features = gt_hashmap_new(GT_HASH_DIRECT, NULL, (GtFree) gt_array_delete); if ((features = gt_hashmap_get(multi_features, gt_feature_node_get_multi_representative(node)))) { gt_array_add(features, node); } else { GtFeatureNode *representative; features = gt_array_new(sizeof (GtFeatureNode*)); representative = gt_feature_node_get_multi_representative(node); gt_array_add(features, representative); gt_hashmap_add(multi_features, representative, features); } } else { if (!cds_features) cds_features = gt_array_new(sizeof (GtFeatureNode*)); gt_array_add(cds_features, node); } } } if (cds_features) had_err = check_cds_phases(cds_features, v, false, second_pass, err); if (!had_err && multi_features) had_err = gt_hashmap_foreach(multi_features, check_cds_phases_hm, v, err); gt_array_delete(cds_features); gt_hashmap_delete(multi_features); gt_feature_node_iterator_delete(fni); return had_err; }
static int store_ids(GtFeatureNode *fn, void *data, GtError *err) { GtGFF3Visitor *gff3_visitor = (GtGFF3Visitor*) data; AddIDInfo add_id_info; int had_err = 0; GtStr *id; gt_error_check(err); gt_assert(fn && gff3_visitor); if (gt_feature_node_has_children(fn) || gt_feature_node_is_multi(fn) || (gff3_visitor->retain_ids && gt_feature_node_get_attribute(fn, "ID"))) { if (gt_feature_node_is_multi(fn)) { id = gt_hashmap_get(gff3_visitor->feature_node_to_unique_id_str, gt_feature_node_get_multi_representative(fn)); if (!id) { /* the representative does not have its own id yet -> create it */ if (gff3_visitor->retain_ids) { id = make_id_unique(gff3_visitor, gt_feature_node_get_multi_representative(fn)); } else { id = create_unique_id(gff3_visitor, gt_feature_node_get_multi_representative(fn)); } } /* store id for feature, if the feature was not the representative */ if (gt_feature_node_get_multi_representative(fn) != fn) { gt_hashmap_add(gff3_visitor->feature_node_to_unique_id_str, fn, gt_str_ref(id)); } } else { if (gff3_visitor->retain_ids) id = make_id_unique(gff3_visitor, fn); else id = create_unique_id(gff3_visitor, fn); } /* for each child -> store the parent feature in the hash map */ add_id_info.gt_feature_node_to_id_array = gff3_visitor->feature_node_to_id_array, add_id_info.id = gt_str_get(id); had_err = gt_feature_node_traverse_direct_children(fn, &add_id_info, add_id, err); } return had_err; }
static int layout_tracks(void *key, void *value, void *data, GT_UNUSED GtError *err) { unsigned long i, max; GtTrack *track; GtLayoutTraverseInfo *lti = (GtLayoutTraverseInfo*) data; GtArray *list = (GtArray*) value; GtStr *gt_track_key; const char *type = key; GtBlock *block; bool split; double tmp; gt_assert(type && list); /* to get a deterministic layout, we sort the GtBlocks for each type */ gt_array_sort_stable(list, blocklist_block_compare); block = *(GtBlock**) gt_array_get(list, 0); gt_track_key = gt_str_new_cstr((char*) key); if (!gt_style_get_bool(lti->layout->style, "format", "split_lines", &split, NULL)) split = true; if (split) if (!gt_style_get_bool(lti->layout->style, type, "split_lines", &split, NULL)) split = true; if (gt_style_get_num(lti->layout->style, type, "max_num_lines", &tmp, NULL)) max = tmp; else max = 50; track = gt_track_new(gt_track_key, max, split, gt_line_breaker_captions_new(lti->layout, lti->layout->width, lti->layout->style)); lti->layout->nof_tracks++; for (i = 0; i < gt_array_size(list); i++) { block = *(GtBlock**) gt_array_get(list, i); gt_track_insert_block(track, block); } gt_hashmap_add(lti->layout->tracks, gt_cstr_dup(gt_str_get(gt_track_key)), track); gt_str_delete(gt_track_key); return 0; }
static int get_caption_display_status(GtDiagram *d, const char *gft, bool *result, GtError *err) { bool *status; gt_assert(d && gft); status = (bool*) gt_hashmap_get(d->caption_display_status, gft); if (!status) { GtUword threshold = GT_UNDEF_UWORD; double tmp = GT_UNDEF_DOUBLE; status = gt_malloc(sizeof (bool)); *status = true; if (gt_style_get_bool(d->style, "format", "show_block_captions", status, NULL, err) == GT_STYLE_QUERY_ERROR) { gt_free(status); return -1; } if (*status) { GtStyleQueryStatus rval; rval = gt_style_get_num(d->style, gft, "max_capt_show_width", &tmp, NULL, err); switch (rval) { case GT_STYLE_QUERY_ERROR: gt_free(status); return -1; break; /* should never reach this */ case GT_STYLE_QUERY_NOT_SET: *status = true; break; default: gt_assert(tmp != GT_UNDEF_DOUBLE); threshold = tmp; gt_assert(tmp != GT_UNDEF_UWORD); *status = (gt_range_length(&d->range) <= threshold); break; } *status = (gt_range_length(&d->range) <= threshold); } gt_hashmap_add(d->caption_display_status, (void*) gft, status); } *result = *status; return 0; }
void gt_line_breaker_bases_register_block(GtLineBreaker *lb, GtLine *line, GtBlock *block) { GtLineBreakerBases *lbb; GtIntervalTree *t; GtIntervalTreeNode *new_node; GtRange *rng; gt_assert(lb && block && line); lbb = gt_line_breaker_bases_cast(lb); rng = gt_block_get_range_ptr(block); new_node = gt_interval_tree_node_new(rng, rng->start, rng->end); if (!(t = gt_hashmap_get(lbb->itrees, line))) { t = gt_interval_tree_new(NULL); gt_hashmap_add(lbb->itrees, line, t); } gt_interval_tree_insert(t, new_node); }
static GtStr* create_unique_id(GtGFF3Visitor *gff3_visitor, GtFeatureNode *fn) { const char *type; GtStr *id; gt_assert(gff3_visitor && fn); type = gt_feature_node_get_type(fn); /* increase id counter */ gt_string_distri_add(gff3_visitor->id_counter, type); /* build id string */ id = gt_str_new_cstr(type); gt_str_append_ulong(id, gt_string_distri_get(gff3_visitor->id_counter, type)); /* store (unique) id */ gt_hashmap_add(gff3_visitor->feature_node_to_unique_id_str, fn, id); return id; }
static void gt_kmer_database_add_to_hash(GtHashmap *hash, GtCodetype kmercode, GtUword position) { GtArrayGtUword *arr = (GtArrayGtUword *) gt_hashmap_get(hash, (void *) kmercode); if (arr == NULL) { arr = gt_malloc(sizeof (*arr)); GT_INITARRAY(arr, GtUword); gt_hashmap_add(hash, (void *) kmercode, (void *) arr); } if (arr->allocatedGtUword == 0) GT_STOREINARRAY(arr, GtUword, (GtUword) 20, position); else GT_STOREINARRAY(arr, GtUword, arr->allocatedGtUword * 0.1, position); }
static GtStr* make_id_unique(GtGFF3Visitor *gff3_visitor, GtFeatureNode *fn) { GtUword i = 1; GtStr *id = gt_str_new_cstr(gt_feature_node_get_attribute(fn, "ID")); if (gt_cstr_table_get(gff3_visitor->used_ids, gt_str_get(id))) { GtStr *buf = gt_str_new(); while (!id_string_is_unique(id, buf, gff3_visitor->used_ids, i++)); gt_warning("feature ID \"%s\" not unique: changing to %s", gt_str_get(id), gt_str_get(buf)); gt_str_set(id, gt_str_get(buf)); gt_str_delete(buf); } /* update table with the new id */ gt_cstr_table_add(gff3_visitor->used_ids, gt_str_get(id)); /* store (unique) id */ gt_hashmap_add(gff3_visitor->feature_node_to_unique_id_str, fn, id); return id; }
void* gt_calloc_mem(size_t nmemb, size_t size, const char *src_file, int src_line) { MAInfo *mainfo; void *mem; gt_assert(ma); if (ma->bookkeeping) { gt_mutex_lock(bookkeeping_lock); ma->mallocevents++; mainfo = xmalloc(sizeof *mainfo, ma->current_size, src_file, src_line); mainfo->size = nmemb * size; mainfo->src_file = src_file; mainfo->src_line = src_line; mem = xcalloc(nmemb, size, ma->current_size, src_file, src_line); gt_hashmap_add(ma->allocated_pointer, mem, mainfo); add_size(ma, nmemb * size); gt_mutex_unlock(bookkeeping_lock); return mem; } return xcalloc(nmemb, size, ma->current_size, src_file, src_line); }
int gt_line_breaker_captions_register_block(GtLineBreaker *lb, GtLine *line, GtBlock *block, GtError *err) { GtDrawingRange dr; GtLineBreakerCaptions *lbcap; int had_err = 0; double *num; gt_assert(lb && block && line); lbcap = gt_line_breaker_captions_cast(lb); if (!(num = gt_hashmap_get(lbcap->linepositions, line))) { num = gt_calloc(1, sizeof (double)); gt_hashmap_add(lbcap->linepositions, line, num); } had_err = calculate_drawing_range(lbcap, &dr, block, err); if (!had_err) *num = floor(dr.end); return had_err; }