ECC-1820: Accessor hash

This commit is contained in:
shahramn 2024-05-08 13:05:36 +01:00
parent e0f2213627
commit f0b68e4b15
1 changed files with 11 additions and 13 deletions

View File

@ -51,8 +51,7 @@ struct accessor_class_hash { const char *name; grib_accessor_class **cclass;};
#endif #endif
#endif #endif
static unsigned int static unsigned int grib_accessor_classes_get_id (const char *str, size_t len)
grib_accessor_classes_get_id (const char *str, size_t len)
{ {
static const unsigned short asso_values[] = static const unsigned short asso_values[] =
{ {
@ -622,20 +621,19 @@ static const struct accessor_class_hash classes[] =
{"g1verificationdate", &grib_accessor_class_g1verificationdate} {"g1verificationdate", &grib_accessor_class_g1verificationdate}
}; };
const struct accessor_class_hash * static const struct accessor_class_hash* grib_accessor_classes_hash(const char *str, size_t len)
grib_accessor_classes_hash (const char *str, size_t len)
{
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{ {
unsigned int key = grib_accessor_classes_get_id (str, len); unsigned int key = grib_accessor_classes_get_id (str, len);
if (key <= MAX_HASH_VALUE) #ifdef DEBUG
{ {
const char *s = classes[key].name; const char *s;
Assert( len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH );
if (*str == *s && !strcmp (str + 1, s + 1)) Assert( key <= MAX_HASH_VALUE );
return &classes[key]; s = classes[key].name;
} Assert( *str == *s && strcmp(str + 1, s + 1)==0 );
} }
return 0; #endif
return &classes[key];
} }