| 1 | // =============================================================== // |
|---|
| 2 | // // |
|---|
| 3 | // File : gb_hashindex.h // |
|---|
| 4 | // Purpose : // |
|---|
| 5 | // // |
|---|
| 6 | // Institute of Microbiology (Technical University Munich) // |
|---|
| 7 | // http://www.arb-home.de/ // |
|---|
| 8 | // // |
|---|
| 9 | // =============================================================== // |
|---|
| 10 | |
|---|
| 11 | #ifndef GB_HASHINDEX_H |
|---|
| 12 | #define GB_HASHINDEX_H |
|---|
| 13 | |
|---|
| 14 | #ifndef GB_LOCAL_H |
|---|
| 15 | #include "gb_local.h" |
|---|
| 16 | #endif |
|---|
| 17 | |
|---|
| 18 | // ------------------------------- |
|---|
| 19 | // hash index calculation |
|---|
| 20 | |
|---|
| 21 | extern const uint32_t crctab[]; |
|---|
| 22 | |
|---|
| 23 | #define GB_CALC_HASH_INDEX_CASE_SENSITIVE(string, index, size) do { \ |
|---|
| 24 | const char *local_ptr = (string); \ |
|---|
| 25 | int local_i; \ |
|---|
| 26 | (index) = 0xffffffffL; \ |
|---|
| 27 | while ((local_i=(*(local_ptr++)))) { \ |
|---|
| 28 | (index) = crctab[((int)(index)^local_i) & 0xff] ^ ((index) >> 8); \ |
|---|
| 29 | } \ |
|---|
| 30 | (index) = (index) % (size); \ |
|---|
| 31 | } while (0) |
|---|
| 32 | |
|---|
| 33 | #define GB_CALC_HASH_INDEX_CASE_IGNORED(string, index, size) do { \ |
|---|
| 34 | const char *local_ptr = (string); \ |
|---|
| 35 | int local_i; \ |
|---|
| 36 | (index) = 0xffffffffL; \ |
|---|
| 37 | while ((local_i = *(local_ptr++))) { \ |
|---|
| 38 | (index) = crctab[((int) (index) ^ toupper(local_i)) & 0xff] ^ ((index) >> 8); \ |
|---|
| 39 | } \ |
|---|
| 40 | (index) = (index) % (size); \ |
|---|
| 41 | } while (0) |
|---|
| 42 | |
|---|
| 43 | #define GB_CALC_HASH_INDEX(string, index, size, caseSens) do { \ |
|---|
| 44 | if ((caseSens) == GB_IGNORE_CASE) \ |
|---|
| 45 | GB_CALC_HASH_INDEX_CASE_IGNORED(string, index, size); \ |
|---|
| 46 | else \ |
|---|
| 47 | GB_CALC_HASH_INDEX_CASE_SENSITIVE(string, index, size); \ |
|---|
| 48 | } while (0) |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | #else |
|---|
| 53 | #error gb_hashindex.h included twice |
|---|
| 54 | #endif // GB_HASHINDEX_H |
|---|