This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PATCH: Use hashval_t typedef



This patch introduces a typedef (hashval_t) for the value returned by
a hash function in the generic hash table machinery.  That makes the
code clearer, and makes it easier to change the value later.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2000-03-30  Mark Mitchell  <mark@codesourcery.com>

	* hashtab.h (hashval_t): New type.
	(htab_find_with_hash): Use it as an argument.
	(htab_find_slot_with_hash): Likewise.

2000-03-30  Mark Mitchell  <mark@codesourcery.com>

	* hashtab.c (find_empty_slot_for_expand): Use hashval_t for hash
	codes.
	(htab_find_with_hash): Likewise.
	(htab_find_slot_with_hash): Likewise.
	
Index: include/hashtab.h
===================================================================
RCS file: /cvs/gcc/egcs/include/hashtab.h,v
retrieving revision 1.5
diff -c -p -r1.5 hashtab.h
*** hashtab.h	2000/03/14 18:28:45	1.5
--- hashtab.h	2000/03/31 07:00:34
***************
*** 1,5 ****
  /* An expandable hash tables datatype.  
!    Copyright (C) 1999 Free Software Foundation, Inc.
     Contributed by Vladimir Makarov (vmakarov@cygnus.com).
  
  This program is free software; you can redistribute it and/or modify
--- 1,5 ----
  /* An expandable hash tables datatype.  
!    Copyright (C) 1999, 2000 Free Software Foundation, Inc.
     Contributed by Vladimir Makarov (vmakarov@cygnus.com).
  
  This program is free software; you can redistribute it and/or modify
*************** extern "C" {
*** 38,47 ****
  
  #include <ansidecl.h>
  
  /* Callback function pointer types.  */
  
  /* Calculate hash of a table entry.  */
! typedef unsigned int (*htab_hash) PARAMS ((const void *));
  
  /* Compare a table entry with a possible entry.  The entry already in
     the table always comes first, so the second element can be of a
--- 38,50 ----
  
  #include <ansidecl.h>
  
+ /* The type for a hash code.  */
+ typedef unsigned int hashval_t;
+ 
  /* Callback function pointer types.  */
  
  /* Calculate hash of a table entry.  */
! typedef hashval_t (*htab_hash) PARAMS ((const void *));
  
  /* Compare a table entry with a possible entry.  The entry already in
     the table always comes first, so the second element can be of a
*************** extern void	htab_empty	PARAMS ((htab_t))
*** 109,117 ****
  extern void    *htab_find	PARAMS ((htab_t, const void *));
  extern void   **htab_find_slot	PARAMS ((htab_t, const void *, int));
  extern void    *htab_find_with_hash		PARAMS ((htab_t, const void *,
! 							 unsigned int));
  extern void   **htab_find_slot_with_hash	PARAMS ((htab_t, const void *,
! 							 unsigned int, int));
  extern void	htab_clear_slot	PARAMS ((htab_t, void **));
  extern void	htab_remove_elt	PARAMS ((htab_t, void *));
  
--- 112,120 ----
  extern void    *htab_find	PARAMS ((htab_t, const void *));
  extern void   **htab_find_slot	PARAMS ((htab_t, const void *, int));
  extern void    *htab_find_with_hash		PARAMS ((htab_t, const void *,
! 							 hashval_t));
  extern void   **htab_find_slot_with_hash	PARAMS ((htab_t, const void *,
! 							 hashval_t, int));
  extern void	htab_clear_slot	PARAMS ((htab_t, void **));
  extern void	htab_remove_elt	PARAMS ((htab_t, void *));
  
Index: libiberty/hashtab.c
===================================================================
RCS file: /cvs/gcc/egcs/libiberty/hashtab.c,v
retrieving revision 1.9
diff -c -p -r1.9 hashtab.c
*** hashtab.c	2000/03/29 19:04:54	1.9
--- hashtab.c	2000/03/31 07:00:34
***************
*** 1,5 ****
  /* An expandable hash tables datatype.  
!    Copyright (C) 1999 Free Software Foundation, Inc.
     Contributed by Vladimir Makarov (vmakarov@cygnus.com).
  
  This file is part of the libiberty library.
--- 1,5 ----
  /* An expandable hash tables datatype.  
!    Copyright (C) 1999, 2000 Free Software Foundation, Inc.
     Contributed by Vladimir Makarov (vmakarov@cygnus.com).
  
  This file is part of the libiberty library.
*************** htab_empty (htab)
*** 155,164 ****
  static void **
  find_empty_slot_for_expand (htab, hash)
       htab_t htab;
!      unsigned int hash;
  {
    size_t size = htab->size;
!   unsigned int hash2 = 1 + hash % (size - 2);
    unsigned int index = hash % size;
  
    for (;;)
--- 155,164 ----
  static void **
  find_empty_slot_for_expand (htab, hash)
       htab_t htab;
!      hashval_t hash;
  {
    size_t size = htab->size;
!   hashval_t hash2 = 1 + hash % (size - 2);
    unsigned int index = hash % size;
  
    for (;;)
*************** void *
*** 221,229 ****
  htab_find_with_hash (htab, element, hash)
       htab_t htab;
       const void *element;
!      unsigned int hash;
  {
!   unsigned int index, hash2;
    size_t size;
    void *entry;
  
--- 221,230 ----
  htab_find_with_hash (htab, element, hash)
       htab_t htab;
       const void *element;
!      hashval_t hash;
  {
!   unsigned int index;
!   hashval_t hash2;
    size_t size;
    void *entry;
  
*************** void **
*** 272,282 ****
  htab_find_slot_with_hash (htab, element, hash, insert)
       htab_t htab;
       const void *element;
!      unsigned int hash;
       int insert;
  {
    void **first_deleted_slot;
!   unsigned int index, hash2;
    size_t size;
  
    if (insert && htab->size * 3 <= htab->n_elements * 4)
--- 273,284 ----
  htab_find_slot_with_hash (htab, element, hash, insert)
       htab_t htab;
       const void *element;
!      hashval_t hash;
       int insert;
  {
    void **first_deleted_slot;
!   unsigned int index;
!   hashval_t hash2;
    size_t size;
  
    if (insert && htab->size * 3 <= htab->n_elements * 4)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]