Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
xt_str2u64_hash(3)	   Library Functions Manual	    xt_str2u64_hash(3)

NAME
       xt_str2u64_hash() - Hash	a string of up to 8 characters to a 64-bit in-
       teger

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

SYNOPSIS
       uint64_t	   xt_str2u64_hash(const char *str)

ARGUMENTS
       str     String to convert

DESCRIPTION
       xt_str2u64_hash()  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 in-
       teger comparison.  Strings of 7 or fewer	characters can	still  be  ac-
       cessed  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  com-
       parison 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_hash(s1);
       v2 = xt_str2u64_hash(s2);
       if ( v1 != v2 )
	   printf("%s and %s are different.n", (char *)&v1, (char *)&v2);

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

							    xt_str2u64_hash(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=xt_str2u64_hash&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help