diff --git a/meson.build b/meson.build index 086c3118852c8e3aca4925c8854252cd7d156258..fcd71a4718f7352fdacd4c2d149a90d31580cac3 100644 --- a/meson.build +++ b/meson.build @@ -538,7 +538,7 @@ _i = ' '.join(my_incdirs) # features which are converted into preprocessor flags (-D) # -############ +############# # ieee754.h # # if compiler.has_header('ieee754.h', @@ -569,6 +569,24 @@ else message('drand48 disabled') endif +################## +# hash functions # +# +if compiler.has_header('search.h', + args: cflags, + include_directories: include_directories(incdirs)\ + ) and \ + compiler.sizeof('struct hsearch_data', + prefix : ''' +#define __USE_GNU +#include <search.h> +''') > 0 + cflags += '-D__HAVE_HSEARCH_DATA__' + message('hsearch_data is available') +else + message('hsearch_data is not available') +endif + ############ # malloc.h # # @@ -578,8 +596,6 @@ if compiler.has_header('malloc.h', cflags += '-D__HAVE_MALLOC_H__' endif - - ############ # setitimer # diff --git a/src/nucsyn/nucsyn_element_to_atomic_number.c b/src/nucsyn/nucsyn_element_to_atomic_number.c index a9e6aac8a7828848cb027599bfa2164bf5a348a9..dd091b0a01c3fc55270db4e6fa1541884ce1a8b3 100644 --- a/src/nucsyn/nucsyn_element_to_atomic_number.c +++ b/src/nucsyn/nucsyn_element_to_atomic_number.c @@ -8,7 +8,9 @@ */ #ifdef NUCSYN +#ifdef __HAVE_HSEARCH_DATA__ #define USEHASH +#endif // __HAVE_HSEARCH_DATA__ /* hash debugging */ //#define HDEBUG @@ -60,7 +62,7 @@ Atomic_number nucsyn_element_to_atomic_number(struct store_t * RESTRICT const st #ifdef HDEBUG printf("Set element info Z=%d from %d\n", store->element_info[Z].Z,Z); -#endif +#endif//HDEBUG /* set the hash item */ ENTRY item; @@ -82,7 +84,7 @@ Atomic_number nucsyn_element_to_atomic_number(struct store_t * RESTRICT const st printf("found %p with Z=%d\n",found_item, ((struct element_info_t*)(found_item->data))->Z ); -#endif +#endif//HDEBUG } } @@ -103,43 +105,45 @@ Atomic_number nucsyn_element_to_atomic_number(struct store_t * RESTRICT const st { Atomic_number Z = ((struct element_info_t*)(found_item->data))->Z; #ifdef HDEBUG - printf("element %s gave Z=%d\n",element,Z; + printf("element %s gave Z=%d\n",element,Z); #endif - return Z; - } + return Z; } -#else + } +#else + /* + * Non-hashed version + */ - if(element!=NULL) + if(element!=NULL) + { + /* + * Simple array search. + */ + Atomic_number Z = -1,i; + for(i=0;i<NUMBER_OF_ELEMENTS;i++) { - /* - * Simple array search. - */ - Atomic_number Z = -1,i; - for(i=0;i<NUMBER_OF_ELEMENTS;i++) + if(strncmp(element_strings[i],element,3)==0) { - if(strncmp(element_strings[i],element,3)==0) - { - Z = i; - break; - } - } - - if(Z==-1) - { - Exit_binary_c_no_stardata(BINARY_C_OUT_OF_RANGE, - "Element %s failed to match any element in nature... please check!\n", - element); - } - else - { - return Z; + Z = i; + break; } } + if(Z==-1) + { + Exit_binary_c_no_stardata(BINARY_C_OUT_OF_RANGE, + "Element %s failed to match any element in nature... please check!\n", + element); + } + else + { + return Z; + } } #endif //USEHASH + return 0; }