/* -*- mode: C; c-file-style: "gnu" -*- */
-/* dbus-hash.c Generic hash table utility (internal to D-BUS implementation)
+/* dbus-hash.c Generic hash table utility (internal to D-BUS implementation)
*
* Copyright (C) 2002 Red Hat, Inc.
* Copyright (c) 1991-1993 The Regents of the University of California.
*
* The guts of DBusHashTable.
*
+ * @todo rebuild_table() should be modified to also shrink the hash bucket
+ * array when appropriate; otherwise if a hash table has been
+ * very large but is now small, iteration becomes inefficient.
+ * We should still only shrink when adding hash entries though, not
+ * when removing them, so that you can still iterate over the hash
+ * removing entries. So if you added 5000, removed 4000, the
+ * shrinking would happen next time an entry was added.
* @{
*/
typedef struct DBusHashEntry DBusHashEntry;
/**
+ * @brief Internal representation of a hash entry.
+ *
* A single entry (key-value pair) in the hash table.
* Internal to hash table implementation.
*/
DBusHashEntry ***bucket);
/**
- * Hash table internal members.
+ * @brief Internals of DBusHashTable.
+ *
+ * Hash table internals. Hash tables are opaque objects, they must be
+ * used via accessor functions.
*/
struct DBusHashTable {
int refcount; /**< Reference count */
DBusFreeFunction free_value_function; /**< Function to free values */
};
-/**
- * Internals of DBusHashIter.
+/**
+ * @brief Internals of DBusHashIter.
*/
typedef struct
{
static void free_entry (DBusHashTable *table,
DBusHashEntry *entry);
-/** }@ */
+/** @} */
/**
* @addtogroup DBusHashTable
*
* @param table the hash table.
* @param key the hash key.
+ * @returns #TRUE if the entry existed
*/
-void
+dbus_bool_t
_dbus_hash_table_remove_string (DBusHashTable *table,
const char *key)
{
entry = (* table->find_function) (table, (char*) key, FALSE, &bucket);
if (entry)
- remove_entry (table, bucket, entry);
+ {
+ remove_entry (table, bucket, entry);
+ return TRUE;
+ }
+ else
+ return FALSE;
}
/**
*
* @param table the hash table.
* @param key the hash key.
+ * @returns #TRUE if the entry existed
*/
-void
+dbus_bool_t
_dbus_hash_table_remove_int (DBusHashTable *table,
int key)
{
entry = (* table->find_function) (table, _DBUS_INT_TO_POINTER (key), FALSE, &bucket);
if (entry)
- remove_entry (table, bucket, entry);
+ {
+ remove_entry (table, bucket, entry);
+ return TRUE;
+ }
+ else
+ return FALSE;
}
/**
return table->n_entries;
}
-/** }@ */
+/** @} */
#ifdef DBUS_BUILD_TESTS
#include "dbus-test.h"