pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 08/18] hash-functions: New function hash_case_bytes().


From: Ben Pfaff
Subject: [PATCH 08/18] hash-functions: New function hash_case_bytes().
Date: Sat, 19 Mar 2011 17:09:54 -0700

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 96ff282..c430173 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 bdf3da3..86414fb 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);
-- 
1.7.2.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]