Add an element disposal function.
[pspp] / lib / gl_anytreehash_list1.h
index f6e319b49002cc2f628c59f03a376ea6edd9127e..b7a3bd9432954ddc3b54b822a7379d5384092998 100644 (file)
@@ -1,5 +1,5 @@
 /* Sequential list data type implemented by a hash table with a binary tree.
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006-2007 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2006.
 
    This program is free software; you can redistribute it and/or modify
@@ -109,7 +109,7 @@ gl_oset_first (gl_oset_t set)
 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 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node)
       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;
 
@@ -152,13 +152,12 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node)
 
                      nodes =
                        gl_oset_create_empty (OSET_TREE_FLAVOR,
-                                             compare_by_position);
+                                             compare_by_position, NULL);
 
                      gl_oset_add (nodes, node);
                      gl_oset_add (nodes, new_node);
 
-                     multi_entry =
-                       (struct gl_multiple_nodes *) xmalloc (sizeof (struct gl_multiple_nodes));
+                     multi_entry = XMALLOC (struct gl_multiple_nodes);
                      multi_entry->h.hash_next = entry->hash_next;
                      multi_entry->h.hashcode = entry->hashcode;
                      multi_entry->magic = MULTIPLE_NODES_MAGIC;
@@ -171,8 +170,8 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node)
        }
     }
   /* 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 +183,7 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node)
 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 +192,7 @@ remove_from_bucket (gl_list_t list, gl_list_node_t old_node)
       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 +238,7 @@ remove_from_bucket (gl_list_t list, gl_list_node_t old_node)
       /* 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)
            {