| 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 | GBS_write_hash(item_hash, GBT_read_name(gb_item), (long)gb_item); |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | typedef GBDATA *(*item_iterator)(GBDATA *); |
|---|
| 19 | |
|---|
| 20 | static GB_HASH *create_item_hash(long size, GBDATA *gb_start, item_iterator getFirst, item_iterator getNext) { |
|---|
| 21 | GB_HASH *item_hash = GBS_create_hash(size, GB_IGNORE_CASE); |
|---|
| 22 | GBDATA *gb_item; |
|---|
| 23 | |
|---|
| 24 | for (gb_item = getFirst(gb_start); gb_item; gb_item = getNext(gb_item)) { |
|---|
| 25 | GBT_add_item_to_hash(gb_item, item_hash); |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | return item_hash; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | GB_HASH *GBT_create_species_hash_sized(GBDATA *gb_main, long species_count) { |
|---|
| 32 | return create_item_hash(species_count, gb_main, GBT_first_species, GBT_next_species); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | GB_HASH *GBT_create_species_hash(GBDATA *gb_main) { |
|---|
| 36 | return GBT_create_species_hash_sized(gb_main, GBT_get_species_count(gb_main)); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | GB_HASH *GBT_create_marked_species_hash(GBDATA *gb_main) { |
|---|
| 40 | return create_item_hash(GBT_get_species_count(gb_main), gb_main, GBT_first_marked_species, GBT_next_marked_species); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | GB_HASH *GBT_create_SAI_hash(GBDATA *gb_main) { |
|---|
| 44 | return create_item_hash(GBT_get_SAI_count(gb_main), gb_main, GBT_first_SAI, GBT_next_SAI); |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | GB_HASH *GBT_create_organism_hash(GBDATA *gb_main) { |
|---|
| 48 | return create_item_hash(GEN_get_organism_count(gb_main), gb_main, GEN_first_organism, GEN_next_organism); |
|---|
| 49 | } |
|---|
| 50 | |
|---|