* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
+/*
+ * Modified by the GLib Team and others 1997-2000. See the AUTHORS
+ * file for a list of people on the GLib Team. See the ChangeLog
+ * files for a list of changes. These files are distributed with
+ * GLib at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
/*
* MT safe
*/
{
gint size;
gint nnodes;
- guint frozen;
GHashNode **nodes;
GHashFunc hash_func;
GCompareFunc key_compare_func;
static void g_hash_nodes_destroy (GHashNode *hash_node);
-G_LOCK_DECLARE_STATIC (g_hash_global);
+G_LOCK_DEFINE_STATIC (g_hash_global);
static GMemChunk *node_mem_chunk = NULL;
static GHashNode *node_free_list = NULL;
hash_table = g_new (GHashTable, 1);
hash_table->size = HASH_TABLE_MIN_SIZE;
hash_table->nnodes = 0;
- hash_table->frozen = FALSE;
hash_table->hash_func = hash_func ? hash_func : g_direct_hash;
hash_table->key_compare_func = key_compare_func;
hash_table->nodes = g_new (GHashNode*, hash_table->size);
{
*node = g_hash_node_new (key, value);
hash_table->nnodes++;
- if (!hash_table->frozen)
- g_hash_table_resize (hash_table);
+ g_hash_table_resize (hash_table);
}
}
g_hash_node_destroy (dest);
hash_table->nnodes--;
- if (!hash_table->frozen)
- g_hash_table_resize (hash_table);
+ g_hash_table_resize (hash_table);
}
}
void
g_hash_table_freeze (GHashTable *hash_table)
{
- g_return_if_fail (hash_table != NULL);
-
- hash_table->frozen++;
+#ifdef G_ENABLE_DEBUG
+ static gboolean first_call = TRUE;
+
+ if (first_call)
+ {
+ g_warning("g_hash_table_freeze and g_hash_table_thaw are deprecated.");
+ first_call = FALSE;
+ }
+#endif /* G_ENABLE_DEBUG */
}
void
g_hash_table_thaw (GHashTable *hash_table)
{
- g_return_if_fail (hash_table != NULL);
-
- if (hash_table->frozen)
- if (!(--hash_table->frozen))
- g_hash_table_resize (hash_table);
}
-gint
+guint
g_hash_table_foreach_remove (GHashTable *hash_table,
GHRFunc func,
gpointer user_data)
{
GHashNode *node, *prev;
guint i;
- gint deleted = 0;
+ guint deleted = 0;
g_return_val_if_fail (hash_table != NULL, 0);
g_return_val_if_fail (func != NULL, 0);
}
}
- if (!hash_table->frozen)
- g_hash_table_resize (hash_table);
+ g_hash_table_resize (hash_table);
return deleted;
}
}
/* Returns the number of elements contained in the hash table. */
-gint
+guint
g_hash_table_size (GHashTable *hash_table)
{
g_return_val_if_fail (hash_table != NULL, 0);
static void
g_hash_node_destroy (GHashNode *hash_node)
{
+
+#ifdef ENABLE_GC_FRIENDLY
+ hash_node->key = NULL;
+ hash_node->value = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
+
G_LOCK (g_hash_global);
hash_node->next = node_free_list;
node_free_list = hash_node;
GHashNode *node = hash_node;
while (node->next)
- node = node->next;
-
+ {
+#ifdef ENABLE_GC_FRIENDLY
+ node->key = NULL;
+ node->value = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
+ node = node->next;
+ }
+
+#ifdef ENABLE_GC_FRIENDLY
+ node->key = NULL;
+ node->value = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
+
G_LOCK (g_hash_global);
node->next = node_free_list;
node_free_list = hash_node;