Changeset 892022a1 in mainline


Ignore:
Timestamp:
2011-10-07T12:42:11Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f51b1d3
Parents:
f98bec0f
Message:

hash table improvements cherrypicked from lp:~helenos-nicf/helenos/nicf

Location:
uspace/lib/c
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/adt/hash_table.c

    rf98bec0f r892022a1  
    7676       
    7777        return true;
     78}
     79
     80/** Remove all elements from the hash table
     81 *
     82 * @param h Hash table to be cleared
     83 */
     84void hash_table_clear(hash_table_t *h)
     85{
     86        for (hash_count_t chain = 0; chain < h->entries; ++chain) {
     87                link_t *cur;
     88                link_t *next;
     89               
     90                for (cur = h->entry[chain].head.next;
     91                    cur != &h->entry[chain].head;
     92                    cur = next) {
     93                        next = cur->next;
     94                        list_remove(cur);
     95                        h->op->remove_callback(cur);
     96                }
     97        }
    7898}
    7999
     
    198218 */
    199219void hash_table_apply(hash_table_t *h, void (*f)(link_t *, void *), void *arg)
    200 {
    201         hash_index_t bucket;
    202        
    203         for (bucket = 0; bucket < h->entries; bucket++) {
    204                 list_foreach(h->entry[bucket], cur) {
     220{       
     221        for (hash_index_t bucket = 0; bucket < h->entries; bucket++) {
     222                link_t *cur;
     223                link_t *next;
     224
     225                for (cur = h->entry[bucket].head.next; cur != &h->entry[bucket].head;
     226                    cur = next) {
     227                        /*
     228                         * The next pointer must be stored prior to the functor
     229                         * call to allow using destructor as the functor (the
     230                         * free function could overwrite the cur->next pointer).
     231                         */
     232                        next = cur->next;
    205233                        f(cur, arg);
    206234                }
  • uspace/lib/c/include/adt/hash_table.h

    rf98bec0f r892022a1  
    8686extern bool hash_table_create(hash_table_t *, hash_count_t, hash_count_t,
    8787    hash_table_operations_t *);
     88extern void hash_table_clear(hash_table_t *);
    8889extern void hash_table_insert(hash_table_t *, unsigned long [], link_t *);
    8990extern link_t *hash_table_find(hash_table_t *, unsigned long []);
Note: See TracChangeset for help on using the changeset viewer.