From: Ben Pfaff Date: Tue, 7 Dec 2010 04:50:04 +0000 (-0800) Subject: hash-functions: New function hash_case_bytes(). X-Git-Tag: v0.7.7~26 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9bbbfbc94aead4518e17eb6304451f6ad2ca2db2;p=pspp-builds.git hash-functions: New function hash_case_bytes(). This is useful for hashing an arbitrary byte sequence case-insensitively. Obviously most uses would be better off working with Unicode but we aren't there yet. --- diff --git a/src/libpspp/hash-functions.c b/src/libpspp/hash-functions.c index 96ff282c..c4301731 100644 --- a/src/libpspp/hash-functions.c +++ b/src/libpspp/hash-functions.c @@ -102,13 +102,12 @@ hash_string (const char *s, unsigned int basis) return hash_bytes (s, strlen (s), basis); } -/* Returns a hash value for null-terminated string S, with - lowercase and uppercase letters treated as equal, starting - from BASIS. */ +/* Returns a hash value for the N bytes at S, with lowercase and uppercase + letters treated as equal, starting from BASIS. */ unsigned int -hash_case_string (const char *s, unsigned int basis) +hash_case_bytes (const void *s_, size_t n, unsigned int basis) { - size_t n = strlen (s); + const char *s = s_; uint32_t a, b, c; uint32_t tmp[3]; int i; @@ -141,6 +140,15 @@ hash_case_string (const char *s, unsigned int basis) return c; } +/* Returns a hash value for null-terminated string S, with + lowercase and uppercase letters treated as equal, starting + from BASIS. */ +unsigned int +hash_case_string (const char *s, unsigned int basis) +{ + return hash_case_bytes (s, strlen (s), basis); +} + /* Returns a hash value for integer X, starting from BASIS. */ unsigned int hash_int (int x, unsigned int basis) diff --git a/src/libpspp/hash-functions.h b/src/libpspp/hash-functions.h index bdf3da31..86414fb1 100644 --- a/src/libpspp/hash-functions.h +++ b/src/libpspp/hash-functions.h @@ -21,6 +21,7 @@ unsigned int hash_bytes (const void *, size_t, unsigned int basis); unsigned int hash_string (const char *, unsigned int basis); +unsigned int hash_case_bytes (const void *, size_t, unsigned int basis); unsigned int hash_case_string (const char *, unsigned int basis); unsigned int hash_int (int, unsigned int basis); unsigned int hash_double (double, unsigned int basis);