summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-hash.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2002-11-23 19:56:30 +0000
committerHavoc Pennington <hp@redhat.com>2002-11-23 19:56:30 +0000
commit576cdb6e0b1274e9fa5276e01337aef330dd4e8c (patch)
tree6904e387bd7f70f0452abe8b4359f66070965d33 /dbus/dbus-hash.c
parentf09921965c769ff6411ae2f684f6b855d4c8f38d (diff)
2002-11-23 Havoc Pennington <hp@pobox.com>
* dbus/dbus-internals.h (_DBUS_INT_MAX): add _DBUS_INT_MIN _DBUS_INT_MAX * dbus/dbus-test.c (main): add list test, and include dbus-test.h as intended * dbus/dbus-hash.c (_dbus_hash_table_remove_string) (_dbus_hash_table_remove_int): return value indicates whether the entry existed to remove * dbus/dbus-list.c: add linked list utility class, with docs and tests * dbus/dbus-hash.c: add TODO item about shrinking the hash bucket array sometimes.
Diffstat (limited to 'dbus/dbus-hash.c')
-rw-r--r--dbus/dbus-hash.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/dbus/dbus-hash.c b/dbus/dbus-hash.c
index 77fa95dc..48e96ca6 100644
--- a/dbus/dbus-hash.c
+++ b/dbus/dbus-hash.c
@@ -92,6 +92,13 @@
*
* 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.
* @{
*/
@@ -929,8 +936,9 @@ _dbus_hash_table_lookup_int (DBusHashTable *table,
*
* @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)
{
@@ -942,7 +950,12 @@ _dbus_hash_table_remove_string (DBusHashTable *table,
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;
}
/**
@@ -951,8 +964,9 @@ _dbus_hash_table_remove_string (DBusHashTable *table,
*
* @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)
{
@@ -964,7 +978,12 @@ _dbus_hash_table_remove_int (DBusHashTable *table,
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;
}
/**