1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : adhashtools.cxx // |
---|
4 | // Purpose : convenience functions for hashes // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // =============================================================== // |
---|
10 | |
---|
11 | #include "gb_local.h" |
---|
12 | #include "arbdbt.h" |
---|
13 | |
---|
14 | static void GBT_add_item_to_hash(GBDATA *gb_item, GB_HASH *item_hash) { |
---|
15 | const char *name = GBT_get_name(gb_item); |
---|
16 | if (name) GBS_write_hash(item_hash, name, (long)gb_item); |
---|
17 | } |
---|
18 | |
---|
19 | typedef GBDATA *(*item_iterator)(GBDATA *); |
---|
20 | |
---|
21 | static GB_HASH *create_item_hash(long size, GBDATA *gb_start, item_iterator getFirst, item_iterator getNext) { |
---|
22 | GB_HASH *item_hash = GBS_create_hash(size, GB_IGNORE_CASE); |
---|
23 | GBDATA *gb_item; |
---|
24 | |
---|
25 | for (gb_item = getFirst(gb_start); gb_item; gb_item = getNext(gb_item)) { |
---|
26 | GBT_add_item_to_hash(gb_item, item_hash); |
---|
27 | } |
---|
28 | |
---|
29 | return item_hash; |
---|
30 | } |
---|
31 | |
---|
32 | GB_HASH *GBT_create_species_hash_sized(GBDATA *gb_main, long species_count) { |
---|
33 | return create_item_hash(species_count, gb_main, GBT_first_species, GBT_next_species); |
---|
34 | } |
---|
35 | |
---|
36 | GB_HASH *GBT_create_species_hash(GBDATA *gb_main) { |
---|
37 | return GBT_create_species_hash_sized(gb_main, GBT_get_species_count(gb_main)); |
---|
38 | } |
---|
39 | |
---|
40 | GB_HASH *GBT_create_marked_species_hash(GBDATA *gb_main) { |
---|
41 | return create_item_hash(GBT_get_species_count(gb_main), gb_main, GBT_first_marked_species, GBT_next_marked_species); |
---|
42 | } |
---|
43 | |
---|
44 | GB_HASH *GBT_create_SAI_hash(GBDATA *gb_main) { |
---|
45 | return create_item_hash(GBT_get_SAI_count(gb_main), gb_main, GBT_first_SAI, GBT_next_SAI); |
---|
46 | } |
---|
47 | |
---|
48 | GB_HASH *GBT_create_organism_hash(GBDATA *gb_main) { |
---|
49 | return create_item_hash(GEN_get_organism_count(gb_main), gb_main, GEN_first_organism, GEN_next_organism); |
---|
50 | } |
---|
51 | |
---|