|
LIBRARY#include <xtend/string.h> -lxtend SYNOPSISuint64_t str2u64(const char *str) ARGUMENTSstr String to convert DESCRIPTIONstr2u64() 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 VALUESuint64_t integer containing the characters in strEXAMPLESchar *s1 = "hello!", s2 = "Hello!"; uint64_t v1, v2; v1 = str2u64(s1); v2 = str2u64(s2); if ( v1 != v2 ) printf("%s and %s are different.n", (char *)&v1, (char *)&v2); SEE ALSOstrdup(3), strcmp(3), strlcpy(3) Visit the GSP FreeBSD Man Page Interface. |