X-Git-Url: https://code.citadel.org/?p=citadel.git;a=blobdiff_plain;f=libcitadel%2Flib%2Fhash.c;fp=libcitadel%2Flib%2Fhash.c;h=665e39b304cd43bf81127a26a9f2d9106b14bfa0;hp=c1e8d4d422bc16b81295b2802257d9f29a8b45d2;hb=0b309a2b8cf939c7a0f5c765a2ab64f8df23c511;hpb=0831c47bc784ea659fff3fba8f537df61f1d36b1 diff --git a/libcitadel/lib/hash.c b/libcitadel/lib/hash.c index c1e8d4d42..665e39b30 100644 --- a/libcitadel/lib/hash.c +++ b/libcitadel/lib/hash.c @@ -657,6 +657,29 @@ long lFlathash(const char *str, long len) else return *(long*)str; } +/** + * @ingroup HashListAlgorithm + * @brief another hashing algorithm; accepts exactly 4 characters, convert it to a hash key. + * @param str Our pointer to the long value + * @param len the length of the data pointed to; needs to be sizeof long, else we won't use it! + * @return the calculated hash value + */ +long FourHash(const char *key, long length) +{ + int i; + int ret = 0; + const unsigned char *ptr = (const unsigned char*)key; + + for (i = 0; i < 4; i++, ptr ++) + ret = (ret << 8) | + ( ((*ptr >= 'a') && + (*ptr <= 'z'))? + *ptr - 'a' + 'A': + *ptr); + + return ret; +} + /** * @ingroup HashListPrivate * @brief private abstract wrapper around the hashing algorithm