summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2015-12-31 11:57:22 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2015-12-31 11:57:22 (GMT)
commit3b73967c62da68d865f32ca91c8407e65b8ddc03 (patch) (side-by-side diff)
treea909617e087fd33f34716134194ab1a0c776f13d
parent8312f45f48ed9d995a15ee6707257f4c8946528d (diff)
downloadgrecs-3b73967c62da68d865f32ca91c8407e65b8ddc03.tar.gz
grecs-3b73967c62da68d865f32ca91c8407e65b8ddc03.tar.bz2
Case-insensitive hash function
* src/grecs.hin (grecs_hash_string_ci): New proto. * src/symtab.c (grecs_hash_string_ci): New function.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/grecs.hin1
-rw-r--r--src/symtab.c13
2 files changed, 14 insertions, 0 deletions
diff --git a/src/grecs.hin b/src/grecs.hin
index c01c175..b82f45a 100644
--- a/src/grecs.hin
+++ b/src/grecs.hin
@@ -458,6 +458,7 @@ int grecs_symtab_enumerate(struct grecs_symtab *st,
size_t grecs_symtab_count_entries(struct grecs_symtab *st);
unsigned grecs_hash_string(const char *name, unsigned long hashsize);
+unsigned grecs_hash_string_ci(const char *name, unsigned long hashsize);
void grecs_value_free(struct grecs_value *val);
diff --git a/src/symtab.c b/src/symtab.c
index 1e1c99a..652f859 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <errno.h>
#include <string.h>
+#include <ctype.h>
/* |hash_size| defines a sequence of symbol table sizes. These are prime
numbers, each of which is approximately twice its predecessor. */
@@ -85,6 +86,18 @@ grecs_hash_string(const char *name, unsigned long hashsize)
return i % hashsize;
}
+unsigned
+grecs_hash_string_ci(const char *name, unsigned long hashsize)
+{
+ unsigned i;
+
+ for (i = 0; *name; name++) {
+ i <<= 1;
+ i ^= tolower (*(unsigned char*) name);
+ }
+ return i % hashsize;
+}
+
static unsigned
def_hash(void *data, unsigned long hashsize)
{

Return to:

Send suggestions and report system problems to the System administrator.