[Top][All Lists]
[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
- [PATCH 07/18] str: New functions for checking for and removing string suffixes., (continued)
- [PATCH 07/18] str: New functions for checking for and removing string suffixes., Ben Pfaff, 2011/03/19
- [PATCH 10/18] i18n: New function recode_string_len()., Ben Pfaff, 2011/03/19
- [PATCH 09/18] i18n: New function uc_name()., Ben Pfaff, 2011/03/19
- [PATCH 14/18] encoding-guesser: New library to guess the encoding of a text file., Ben Pfaff, 2011/03/19
- [PATCH 04/18] output: New function text_item_create_nocopy()., Ben Pfaff, 2011/03/19
- [PATCH 05/18] str: New function ss_realloc()., Ben Pfaff, 2011/03/19
- [PATCH 13/18] i18n: New functions and data structure for obtaining encoding info., Ben Pfaff, 2011/03/19
- [PATCH 06/18] str: Rename ss_chomp() to ss_chomp_byte(), ds_chomp() to ds_chomp_byte()., Ben Pfaff, 2011/03/19
- [PATCH 02/18] file-name: Do not make output files line-buffered in fn_open()., Ben Pfaff, 2011/03/19
- [PATCH 12/18] identifier: Rename token_type_to_string() and make a new version., Ben Pfaff, 2011/03/19
- [PATCH 08/18] hash-functions: New function hash_case_bytes().,
Ben Pfaff <=
- [PATCH 11/18] i18n: New functions for truncating strings in an arbitrary encoding., Ben Pfaff, 2011/03/19
- [PATCH 17/18] scan: New library for high-level PSPP syntax lexical analysis., Ben Pfaff, 2011/03/19
- [PATCH 15/18] u8-istream: New library for reading a text file and recoding to UTF-8., Ben Pfaff, 2011/03/19
- [PATCH 16/18] segment: New library for low-level phase of lexical syntax analysis., Ben Pfaff, 2011/03/19
- [PATCH 03/18] sys-file-reader: Refactor to clean up character encoding support., Ben Pfaff, 2011/03/19
- Re: [PATCH 00/18] rewrite PSPP lexer, John Darrington, 2011/03/20
- Re: [PATCH 00/18] rewrite PSPP lexer, John Darrington, 2011/03/22