* Added hash_dump_table() function, dumping the whole table.
* Fixed hash_remove_current(): It didn't update "lastElement" and thus always also removed all elements in the same bucket preceding the one to be removed. Also got rid of the useless "for" loop. Fixes #2757. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27689 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -41,6 +41,7 @@ void *hash_next(struct hash_table *table, struct hash_iterator *i);
|
|||||||
void hash_rewind(struct hash_table *table, struct hash_iterator *i);
|
void hash_rewind(struct hash_table *table, struct hash_iterator *i);
|
||||||
uint32 hash_count_elements(struct hash_table *table);
|
uint32 hash_count_elements(struct hash_table *table);
|
||||||
uint32 hash_count_used_slots(struct hash_table *table);
|
uint32 hash_count_used_slots(struct hash_table *table);
|
||||||
|
void hash_dump_table(struct hash_table* table);
|
||||||
|
|
||||||
/* function pointers must look like this:
|
/* function pointers must look like this:
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -236,13 +236,13 @@ hash_remove_current(struct hash_table *table, struct hash_iterator *iterator)
|
|||||||
{
|
{
|
||||||
uint32 index = iterator->bucket;
|
uint32 index = iterator->bucket;
|
||||||
void *element;
|
void *element;
|
||||||
|
|
||||||
if (iterator->current == NULL)
|
|
||||||
panic("hash_remove_current() called too early.");
|
|
||||||
|
|
||||||
for (element = table->table[index]; index < table->table_size; index++) {
|
|
||||||
void *lastElement = NULL;
|
void *lastElement = NULL;
|
||||||
|
|
||||||
|
if (iterator->current == NULL || (element = table->table[index]) == NULL) {
|
||||||
|
panic("hash_remove_current(): invalid iteration state");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while (element != NULL) {
|
while (element != NULL) {
|
||||||
if (element == iterator->current) {
|
if (element == iterator->current) {
|
||||||
iterator->current = lastElement;
|
iterator->current = lastElement;
|
||||||
@@ -259,9 +259,11 @@ hash_remove_current(struct hash_table *table, struct hash_iterator *iterator)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastElement = element;
|
||||||
element = NEXT(table, element);
|
element = NEXT(table, element);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
panic("hash_remove_current(): current element not found!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -408,3 +410,25 @@ hash_count_used_slots(struct hash_table *table)
|
|||||||
|
|
||||||
return usedSlots;
|
return usedSlots;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
hash_dump_table(struct hash_table* table)
|
||||||
|
{
|
||||||
|
uint32 i;
|
||||||
|
|
||||||
|
dprintf("hash table %p, table size: %lu, elements: %u\n", table,
|
||||||
|
table->table_size, table->num_elements);
|
||||||
|
|
||||||
|
for (i = 0; i < table->table_size; i++) {
|
||||||
|
struct hash_element* element = table->table[i];
|
||||||
|
if (element != NULL) {
|
||||||
|
dprintf("%6lu:", i);
|
||||||
|
while (element != NULL) {
|
||||||
|
dprintf(" %p", element);
|
||||||
|
element = NEXT(table, element);
|
||||||
|
}
|
||||||
|
dprintf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user