[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: 32-gary-hash-string-function-move.patch
From: |
Gary V. Vaughan |
Subject: |
FYI: 32-gary-hash-string-function-move.patch |
Date: |
Tue, 28 May 2002 22:52:14 +0100 |
User-agent: |
Mutt/1.2.5i |
Index: ChangeLog
from Gary V. Vaughan <address@hidden>
* m4/symtab.c (m4_symtab_hash, m4_symtab_cmp): Moved from here...
* m4/hash.c (m4_hash_string_hash, m4_hash_string_cmp): .. to here,
and reenamed.
* m4/hash.h: Adjust prototypes.
Index: m4/hash.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/hash.c,v
retrieving revision 1.5
diff -u -p -u -r1.5 hash.c
--- m4/hash.c 30 Sep 2001 22:26:57 -0000 1.5
+++ m4/hash.c 28 May 2002 21:29:48 -0000
@@ -374,7 +374,7 @@ m4_hash_exit (void)
xfree (stale);
}
}
-
+
struct m4_hash_iterator
@@ -466,4 +466,34 @@ m4_hash_iterator_value (m4_hash_iterator
assert (place);
return M4_HASH_NODE_VAL (M4_ITERATOR_PLACE (place));
+}
+
+
+/* Using a string as the hash key is common enough that we provide
+ implementations here for use in client hash table routines. */
+
+/* Return a hash value for a string, from GNU Emacs. */
+size_t
+m4_hash_string_hash (const void *key)
+{
+ int val = 0;
+ const char *ptr = (const char *) key;
+ char ch;
+
+ while ((ch = *ptr++) != '\0')
+ {
+ if (ch >= 0140)
+ ch -= 40;
+ val = ((val << 3) + (val >> 28) + ch);
+ };
+ val = (val < 0) ? -val : val;
+ return val;
+}
+
+/* Comparison function for hash keys -- used by the underlying
+ hash table ADT when searching for a key match during name lookup. */
+int
+m4_hash_string_cmp (const void *key, const void *try)
+{
+ return (strcmp ((const char *) key, (const char *) try));
}
Index: m4/hash.h
===================================================================
RCS file: /cvsroot/m4/m4/m4/hash.h,v
retrieving revision 1.4
diff -u -p -u -r1.4 hash.h
--- m4/hash.h 30 Sep 2001 22:26:57 -0000 1.4
+++ m4/hash.h 28 May 2002 21:29:48 -0000
@@ -48,6 +48,11 @@ void m4_hash_exit (void);
+size_t m4_hash_string_hash (const void *key);
+int m4_hash_string_cmp (const void *key, const void *try);
+
+
+
typedef struct m4_hash_iterator m4_hash_iterator;
m4_hash_iterator * m4_hash_iterator_next (const m4_hash *hash,
@@ -57,4 +62,4 @@ void * m4_hash_iterator_value (m4_hash
END_C_DECLS
-#endif /* M4_HASH_H */
+#endif /* !M4_HASH_H */
Index: m4/symtab.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/symtab.c,v
retrieving revision 1.27
diff -u -p -u -r1.27 symtab.c
--- m4/symtab.c 16 Oct 2001 02:28:08 -0000 1.27
+++ m4/symtab.c 28 May 2002 21:29:50 -0000
@@ -42,8 +42,6 @@
of fluff in these functions to make sure that such symbols (with empty
value stacks) are invisible to the users of this module. */
-static size_t m4_symtab_hash (const void *key);
-static int m4_symtab_cmp (const void *key, const void *try);
static int m4_symbol_destroy (const char *name, m4_symbol *symbol,
void *data);
@@ -60,7 +58,7 @@ m4_hash *m4_symtab = 0;
void
m4_symtab_init (void)
{
- m4_symtab = m4_hash_new (m4_symtab_hash, m4_symtab_cmp);
+ m4_symtab = m4_hash_new (m4_hash_string_hash, m4_hash_string_cmp);
}
/* The following function is used for the cases where we want to do
@@ -160,33 +158,6 @@ m4_symbol_destroy (const char *name, m4_
return 0;
}
-
-/* Return a hash value for a string, from GNU Emacs. */
-static size_t
-m4_symtab_hash (const void *key)
-{
- int val = 0;
- const char *ptr = (const char *) key;
- char ch;
-
- while ((ch = *ptr++) != '\0')
- {
- if (ch >= 0140)
- ch -= 40;
- val = ((val << 3) + (val >> 28) + ch);
- };
- val = (val < 0) ? -val : val;
- return val;
-}
-
-/* Comparison function for hash keys -- used by the underlying
- hash table ADT when searching for a key match during name lookup. */
-static int
-m4_symtab_cmp (const void *key, const void *try)
-{
- return (strcmp ((const char *) key, (const char *) try));
-}
-
--
())_. Gary V. Vaughan gary@(oranda.demon.co.uk|gnu.org)
( '/ Research Scientist http://www.oranda.demon.co.uk ,_())____
/ )= GNU Hacker http://www.gnu.org/software/libtool \' `&
`(_~)_ Tech' Author http://sources.redhat.com/autobook =`---d__/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- FYI: 32-gary-hash-string-function-move.patch,
Gary V. Vaughan <=