]> git.donarmstrong.com Git - samtools.git/blob - bcftools/bcfutils.c
move bcftools to samtools
[samtools.git] / bcftools / bcfutils.c
1 #include "bcf.h"
2 #include "khash.h"
3 KHASH_MAP_INIT_STR(str2id, int)
4
5 void *bcf_build_refhash(bcf_hdr_t *h)
6 {
7         khash_t(str2id) *hash;
8         int i, ret;
9         hash = kh_init(str2id);
10         for (i = 0; i < h->n_ref; ++i) {
11                 khint_t k;
12                 k = kh_put(str2id, hash, h->ns[i], &ret); // FIXME: check ret
13                 kh_val(hash, k) = i;
14         }
15         return hash;
16 }
17
18 void bcf_str2id_destroy(void *_hash)
19 {
20         khash_t(str2id) *hash = (khash_t(str2id)*)_hash;
21         if (hash) kh_destroy(str2id, hash); // Note that strings are not freed.
22 }
23
24 int bcf_str2id(void *_hash, const char *str)
25 {
26         khash_t(str2id) *hash = (khash_t(str2id)*)_hash;
27         khint_t k;
28         if (!hash) return -1;
29         k = kh_get(str2id, hash, str);
30         return k == kh_end(hash)? -1 : kh_val(hash, k);
31 }
32