changeset 7466:c9738ed4c499

Avoid using the variable name 'index' for two completely different things.
author Bruno Haible <bruno@clisp.org>
date Tue, 10 Oct 2006 12:48:57 +0000
parents d92cc93118d2
children b7c575e9e398
files ChangeLog lib/gl_anyhash_list2.h lib/gl_anylinked_list2.h lib/gl_anytreehash_list1.h lib/gl_anytreehash_list2.h lib/gl_linkedhash_list.c
diffstat 6 files changed, 38 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2006-10-10  Bruno Haible  <bruno@clisp.org>
+
+	Fix a gcc -Wshadow warning.
+	* lib/gl_anyhash_list2.h (hash_resize): Rename local variable 'index'
+	to 'bucket'.
+	* lib/gl_anylinked_list2.h (gl_linked_search_from_to,
+	gl_linked_indexof_from_to): Likewise.
+	* lib/gl_linkedhash_list.c (add_to_bucket, remove_from_bucket):
+	Likewise.
+	* lib/gl_anytreehash_list1.h (add_to_bucket, remove_from_bucket):
+	Likewise.
+	* lib/gl_anytreehash_list2.h (gl_tree_search_from_to): Likewise.
+	Reported by Eric Blake.
+
 2006-10-09  Paul Eggert  <eggert@cs.ucla.edu>
 
 	* lib/filemode.h [HAVE_DECL_STRMODE]: Include unistd.h too,
--- a/lib/gl_anyhash_list2.h
+++ b/lib/gl_anyhash_list2.h
@@ -113,9 +113,9 @@
 	    {
 	      gl_hash_entry_t next = node->hash_next;
 	      /* Add the entry to the new table.  */
-	      size_t index = node->hashcode % new_size;
-	      node->hash_next = new_table[index];
-	      new_table[index] = node;
+	      size_t bucket = node->hashcode % new_size;
+	      node->hash_next = new_table[bucket];
+	      new_table[bucket] = node;
 
 	      node = next;
 	    }
--- a/lib/gl_anylinked_list2.h
+++ b/lib/gl_anylinked_list2.h
@@ -229,7 +229,7 @@
       (list->base.hashcode_fn != NULL
        ? list->base.hashcode_fn (elt)
        : (size_t)(uintptr_t) elt);
-    size_t index = hashcode % list->table_size;
+    size_t bucket = hashcode % list->table_size;
     gl_listelement_equals_fn equals = list->base.equals_fn;
 
     if (!list->base.allow_duplicates)
@@ -238,7 +238,7 @@
 	gl_list_node_t found = NULL;
 	gl_list_node_t node;
 
-	for (node = (gl_list_node_t) list->table[index];
+	for (node = (gl_list_node_t) list->table[bucket];
 	     node != NULL;
 	     node = (gl_list_node_t) node->h.hash_next)
 	  if (node->h.hashcode == hashcode
@@ -279,7 +279,7 @@
 	gl_list_node_t first_match = NULL;
 	gl_list_node_t node;
 
-	for (node = (gl_list_node_t) list->table[index];
+	for (node = (gl_list_node_t) list->table[bucket];
 	     node != NULL;
 	     node = (gl_list_node_t) node->h.hash_next)
 	  if (node->h.hashcode == hashcode
@@ -385,7 +385,7 @@
       (list->base.hashcode_fn != NULL
        ? list->base.hashcode_fn (elt)
        : (size_t)(uintptr_t) elt);
-    size_t index = hashcode % list->table_size;
+    size_t bucket = hashcode % list->table_size;
     gl_listelement_equals_fn equals = list->base.equals_fn;
     gl_list_node_t node;
 
@@ -393,7 +393,7 @@
     if (!list->base.allow_duplicates)
       {
 	/* Look for the first match in the hash bucket.  */
-	for (node = (gl_list_node_t) list->table[index];
+	for (node = (gl_list_node_t) list->table[bucket];
 	     node != NULL;
 	     node = (gl_list_node_t) node->h.hash_next)
 	  if (node->h.hashcode == hashcode
@@ -408,7 +408,7 @@
 	bool multiple_matches = false;
 	gl_list_node_t first_match = NULL;
 
-	for (node = (gl_list_node_t) list->table[index];
+	for (node = (gl_list_node_t) list->table[bucket];
 	     node != NULL;
 	     node = (gl_list_node_t) node->h.hash_next)
 	  if (node->h.hashcode == hashcode
--- a/lib/gl_anytreehash_list1.h
+++ b/lib/gl_anytreehash_list1.h
@@ -109,7 +109,7 @@
 static void
 add_to_bucket (gl_list_t list, gl_list_node_t new_node)
 {
-  size_t index = new_node->h.hashcode % list->table_size;
+  size_t bucket = new_node->h.hashcode % list->table_size;
 
   /* If no duplicates are allowed, multiple nodes are not needed.  */
   if (list->base.allow_duplicates)
@@ -119,7 +119,7 @@
       gl_listelement_equals_fn equals = list->base.equals_fn;
       gl_hash_entry_t *entryp;
 
-      for (entryp = &list->table[index]; *entryp != NULL; entryp = &(*entryp)->hash_next)
+      for (entryp = &list->table[bucket]; *entryp != NULL; entryp = &(*entryp)->hash_next)
 	{
 	  gl_hash_entry_t entry = *entryp;
 
@@ -171,8 +171,8 @@
 	}
     }
   /* If no duplicates are allowed, multiple nodes are not needed.  */
-  new_node->h.hash_next = list->table[index];
-  list->table[index] = &new_node->h;
+  new_node->h.hash_next = list->table[bucket];
+  list->table[bucket] = &new_node->h;
 }
 
 /* Remove a node from the hash table structure.
@@ -184,7 +184,7 @@
 static void
 remove_from_bucket (gl_list_t list, gl_list_node_t old_node)
 {
-  size_t index = old_node->h.hashcode % list->table_size;
+  size_t bucket = old_node->h.hashcode % list->table_size;
 
   if (list->base.allow_duplicates)
     {
@@ -193,7 +193,7 @@
       gl_listelement_equals_fn equals = list->base.equals_fn;
       gl_hash_entry_t *entryp;
 
-      for (entryp = &list->table[index]; ; entryp = &(*entryp)->hash_next)
+      for (entryp = &list->table[bucket]; ; entryp = &(*entryp)->hash_next)
 	{
 	  gl_hash_entry_t entry = *entryp;
 
@@ -239,7 +239,7 @@
       /* If no duplicates are allowed, multiple nodes are not needed.  */
       gl_hash_entry_t *entryp;
 
-      for (entryp = &list->table[index]; ; entryp = &(*entryp)->hash_next)
+      for (entryp = &list->table[bucket]; ; entryp = &(*entryp)->hash_next)
 	{
 	  if (*entryp == &old_node->h)
 	    {
--- a/lib/gl_anytreehash_list2.h
+++ b/lib/gl_anytreehash_list2.h
@@ -31,13 +31,13 @@
       (list->base.hashcode_fn != NULL
        ? list->base.hashcode_fn (elt)
        : (size_t)(uintptr_t) elt);
-    size_t index = hashcode % list->table_size;
+    size_t bucket = hashcode % list->table_size;
     gl_listelement_equals_fn equals = list->base.equals_fn;
     gl_hash_entry_t entry;
 
     if (list->base.allow_duplicates)
       {
-	for (entry = list->table[index]; entry != NULL; entry = entry->hash_next)
+	for (entry = list->table[bucket]; entry != NULL; entry = entry->hash_next)
 	  if (entry->hashcode == hashcode)
 	    {
 	      if (((struct gl_multiple_nodes *) entry)->magic == MULTIPLE_NODES_MAGIC)
@@ -102,7 +102,7 @@
     else
       {
 	/* If no duplicates are allowed, multiple nodes are not needed.  */
-	for (entry = list->table[index]; entry != NULL; entry = entry->hash_next)
+	for (entry = list->table[bucket]; entry != NULL; entry = entry->hash_next)
 	  if (entry->hashcode == hashcode)
 	    {
 	      gl_list_node_t node = (struct gl_list_node_impl *) entry;
--- a/lib/gl_linkedhash_list.c
+++ b/lib/gl_linkedhash_list.c
@@ -58,20 +58,20 @@
 static inline void
 add_to_bucket (gl_list_t list, gl_list_node_t node)
 {
-  size_t index = node->h.hashcode % list->table_size;
+  size_t bucket = node->h.hashcode % list->table_size;
 
-  node->h.hash_next = list->table[index];
-  list->table[index] = &node->h;
+  node->h.hash_next = list->table[bucket];
+  list->table[bucket] = &node->h;
 }
 
 /* Remove a node from the hash table structure.  */
 static inline void
 remove_from_bucket (gl_list_t list, gl_list_node_t node)
 {
-  size_t index = node->h.hashcode % list->table_size;
+  size_t bucket = node->h.hashcode % list->table_size;
   gl_hash_entry_t *p;
 
-  for (p = &list->table[index]; ; p = &(*p)->hash_next)
+  for (p = &list->table[bucket]; ; p = &(*p)->hash_next)
     {
       if (*p == &node->h)
 	{