xt_str2u64(3)

NAME
xt_str2u64() - Hash a string of up to 8 characters to a 64-bit integer

LIBRARY
#include <xtend/string.h>
-lxtend

SYNOPSIS
uint64_t    xt_str2u64(const char *str)

ARGUMENTS
str     String to convert

DESCRIPTION
xt_str2u64() is a super-fast hash function that converts a string of 8 or fewer characters to a 64-bit integer. Strings of more than 8 characters may also be hashed, though collisions will occur (same hash value for more than one string) if the first 8 characters are the same. This sort of hashing is useful for storing lists of very short strings, as it eliminates the need to use strdup(), strlcpy(), and strcmp() for processing. Strings can be compared for equality using a straight integer comparison. Strings of 7 or fewer characters can still be accessed as a string by simply casting to char * for output, then using lexical comparison with strcmp(), etc. A string of 8 characters will not have a null-terminator. The value returned varies depending on endianness. Hence, hash values generated on one architecture will need to be byte swapped before comparison to values generated under a different endianness.

RETURN VALUES
uint64_t integer containing the characters in str

EXAMPLES
char        *s1 = "hello!", s2 = "Hello!";
uint64_t    v1, v2;
v1 = xt_str2u64(s1);
v2 = xt_str2u64(s2);
if ( v1 != v2 )
    printf("%s and %s are different.n", (char *)&v1, (char *)&v2);

SEE ALSO
strdup(3), strcmp(3), strlcpy(3)