From 9bbbfbc94aead4518e17eb6304451f6ad2ca2db2 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 6 Dec 2010 20:50:04 -0800 Subject: [PATCH] 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. --- src/libpspp/hash-functions.c | 18 +++++++++++++----- src/libpspp/hash-functions.h | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) 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); -- 2.30.2