Ignore:
Timestamp:
2011-10-10T06:58:55Z (13 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2ea6392
Parents:
e68c834 (diff), 80099c19 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge with mainline

File:
1 edited

Legend:

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

    re68c834 r7a68fe5  
    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                }
Note: See TracChangeset for help on using the changeset viewer.