GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
str2u64(3) FreeBSD Library Functions Manual str2u64(3)

#include <xtend/string.h>
-lxtend

uint64_t    str2u64(const char *str)

str     String to convert

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.

uint64_t integer containing the characters in str

char        *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);

strdup(3), strcmp(3), strlcpy(3)


Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.