| 1 | /* =============================================================== */ |
|---|
| 2 | /* */ |
|---|
| 3 | /* File : adhashtools.c */ |
|---|
| 4 | /* Purpose : convenience functions for hashes */ |
|---|
| 5 | /* */ |
|---|
| 6 | /* Coded by Ralf Westram (coder@reallysoft.de) in July 2007 */ |
|---|
| 7 | /* Institute of Microbiology (Technical University Munich) */ |
|---|
| 8 | /* http://www.arb-home.de/ */ |
|---|
| 9 | /* */ |
|---|
| 10 | /* =============================================================== */ |
|---|
| 11 | |
|---|
| 12 | #include <stdio.h> |
|---|
| 13 | #include "adlocal.h" |
|---|
| 14 | #include "arbdbt.h" |
|---|
| 15 | |
|---|
| 16 | #define ITEMS2HASHSIZE(entries) (2*(entries)) /* hash size = 2 * number of entries */ |
|---|
| 17 | |
|---|
| 18 | long GBT_get_species_hash_size(GBDATA *gb_main) { |
|---|
| 19 | return ITEMS2HASHSIZE(GBT_get_species_count(gb_main)); |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | void GBT_add_item_to_hash(GBDATA *gb_item, GB_HASH *item_hash) { |
|---|
| 23 | GBS_write_hash(item_hash, GBT_read_name(gb_item), (long)gb_item); |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | typedef GBDATA *(*item_iterator)(GBDATA *); |
|---|
| 27 | |
|---|
| 28 | static GB_HASH *create_item_hash(long size, GBDATA *gb_start, item_iterator getFirst, item_iterator getNext) { |
|---|
| 29 | GB_HASH *item_hash = GBS_create_hash(size, GB_IGNORE_CASE); |
|---|
| 30 | GBDATA *gb_item; |
|---|
| 31 | |
|---|
| 32 | for (gb_item = getFirst(gb_start); gb_item; gb_item = getNext(gb_item)) { |
|---|
| 33 | GBT_add_item_to_hash(gb_item, item_hash); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | return item_hash; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | GB_HASH *GBT_create_species_hash(GBDATA *gb_main) |
|---|
| 40 | { |
|---|
| 41 | return create_item_hash(GBT_get_species_hash_size(gb_main), |
|---|
| 42 | gb_main, GBT_first_species, GBT_next_species); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | GB_HASH *GBT_create_species_hash_sized(GBDATA *gb_main, long species_count) |
|---|
| 46 | { |
|---|
| 47 | return create_item_hash(ITEMS2HASHSIZE(species_count), |
|---|
| 48 | gb_main, GBT_first_species, GBT_next_species); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | GB_HASH *GBT_create_marked_species_hash(GBDATA *gb_main) |
|---|
| 52 | { |
|---|
| 53 | return create_item_hash(GBT_get_species_hash_size(gb_main), |
|---|
| 54 | gb_main, GBT_first_marked_species, GBT_next_marked_species); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | GB_HASH *GBT_create_SAI_hash(GBDATA *gb_main) |
|---|
| 58 | { |
|---|
| 59 | return create_item_hash(ITEMS2HASHSIZE(GBT_get_SAI_count(gb_main)), |
|---|
| 60 | gb_main, GBT_first_SAI, GBT_next_SAI); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | GB_HASH *GBT_create_organism_hash(GBDATA *gb_main) { |
|---|
| 64 | return create_item_hash(ITEMS2HASHSIZE(GEN_get_organism_count(gb_main)), |
|---|
| 65 | gb_main, GEN_first_organism, GEN_next_organism); |
|---|
| 66 | } |
|---|