PATCH: convenience routines for hashtab.c
Mark Mitchell
mark@codesourcery.com
Mon Apr 24 00:29:00 GMT 2000
Here are a couple of convenience routines for hashing and comparing
pointers.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2000-04-24 Mark Mitchell <mark@codesourcery.com>
* hashtab.h (hash_pointer): Declare.
(eq_pointer): Likewise.
2000-04-24 Mark Mitchell <mark@codesourcery.com>
* hashtab.c (hash_pointer): New function.
(eq_pointer): Likewise.
(htab_hash_pointer): New variable.
(htab_eq_pointer): Likewise.
Index: hashtab.h
===================================================================
RCS file: /cvs/gcc/egcs/include/hashtab.h,v
retrieving revision 1.7
diff -c -p -r1.7 hashtab.h
*** hashtab.h 2000/04/18 20:42:00 1.7
--- hashtab.h 2000/04/24 07:26:17
*************** extern size_t htab_size PARAMS ((htab_t)
*** 129,134 ****
--- 129,140 ----
extern size_t htab_elements PARAMS ((htab_t));
extern double htab_collisions PARAMS ((htab_t));
+ /* A hash function for pointers. */
+ extern htab_hash htab_hash_pointer;
+
+ /* An equality function for pointers. */
+ extern htab_eq htab_eq_pointer;
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
Index: hashtab.c
===================================================================
RCS file: /cvs/gcc/egcs/libiberty/hashtab.c,v
retrieving revision 1.11
diff -c -p -r1.11 hashtab.c
*** hashtab.c 2000/04/18 20:42:00 1.11
--- hashtab.c 2000/04/24 07:27:42
*************** Boston, MA 02111-1307, USA. */
*** 56,62 ****
--- 56,70 ----
#define DELETED_ENTRY ((void *) 1)
static unsigned long higher_prime_number PARAMS ((unsigned long));
+ static hashval_t hash_pointer PARAMS ((const void *));
+ static int eq_pointer PARAMS ((const void *, const void *));
+ /* At some point, we could make these be NULL, and modify the
+ hash-table routines to handle NULL specially; that would avoid
+ function-call overhead for the common case of hashing pointers. */
+ htab_hash htab_hash_pointer = hash_pointer;
+ htab_eq htab_eq_pointer = eq_pointer;
+
/* The following function returns the nearest prime number which is
greater than a given source number, N. */
*************** higher_prime_number (n)
*** 86,91 ****
--- 94,118 ----
}
return n;
+ }
+
+ /* Returns a hash code for P. */
+
+ hashval_t
+ hash_pointer (p)
+ const void *p;
+ {
+ return (hashval_t) p;
+ }
+
+ /* Returns non-zero if P1 and P2 are equal. */
+
+ int
+ eq_pointer (p1, p2)
+ const void *p1;
+ const void *p2;
+ {
+ return p1 == p2;
}
/* This function creates table with length slightly longer than given
More information about the Gcc-patches
mailing list