Ignore:
Timestamp:
2018-03-02T20:34:50Z (7 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a1a81f69, d5e5fd1
Parents:
3061bc1 (diff), 34e1206 (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.
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:34:50)
git-committer:
GitHub <noreply@…> (2018-03-02 20:34:50)
Message:

Remove all trailing whitespace, everywhere.

See individual commit messages for details.

File:
1 edited

Legend:

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

    r3061bc1 r8565a42  
    9696        assert(h);
    9797        assert(op && op->hash && op->key_hash && op->key_equal);
    98        
     98
    9999        /* Check for compulsory ops. */
    100100        if (!op || !op->hash || !op->key_hash || !op->key_equal)
    101101                return false;
    102        
     102
    103103        h->bucket_cnt = round_up_size(init_size);
    104        
     104
    105105        if (!alloc_table(h->bucket_cnt, &h->bucket))
    106106                return false;
    107        
     107
    108108        h->max_load = (max_load == 0) ? HT_MAX_LOAD : max_load;
    109109        h->item_cnt = 0;
     
    115115                h->op->remove_callback = nop_remove_callback;
    116116        }
    117        
     117
    118118        return true;
    119119}
     
    128128        assert(h && h->bucket);
    129129        assert(!h->apply_ongoing);
    130        
     130
    131131        clear_items(h);
    132        
     132
    133133        free(h->bucket);
    134134
     
    159159        assert(h && h->bucket);
    160160        assert(!h->apply_ongoing);
    161        
     161
    162162        clear_items(h);
    163        
     163
    164164        /* Shrink the table to its minimum size if possible. */
    165165        if (HT_MIN_BUCKETS < h->bucket_cnt) {
     
    173173        if (h->item_cnt == 0)
    174174                return;
    175        
     175
    176176        for (size_t idx = 0; idx < h->bucket_cnt; ++idx) {
    177177                list_foreach_safe(h->bucket[idx], cur, next) {
    178178                        assert(cur);
    179179                        ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link);
    180                        
     180
    181181                        list_remove(cur);
    182182                        h->op->remove_callback(cur_link);
    183183                }
    184184        }
    185        
     185
    186186        h->item_cnt = 0;
    187187}
     
    197197        assert(h && h->bucket);
    198198        assert(!h->apply_ongoing);
    199        
     199
    200200        size_t idx = h->op->hash(item) % h->bucket_cnt;
    201        
     201
    202202        list_append(&item->link, &h->bucket[idx]);
    203203        ++h->item_cnt;
     
    220220        assert(h->op && h->op->hash && h->op->equal);
    221221        assert(!h->apply_ongoing);
    222        
     222
    223223        size_t idx = h->op->hash(item) % h->bucket_cnt;
    224        
     224
    225225        /* Check for duplicates. */
    226226        list_foreach(h->bucket[idx], link, ht_link_t, cur_link) {
     
    232232                        return false;
    233233        }
    234        
     234
    235235        list_append(&item->link, &h->bucket[idx]);
    236236        ++h->item_cnt;
    237237        grow_if_needed(h);
    238        
     238
    239239        return true;
    240240}
     
    251251{
    252252        assert(h && h->bucket);
    253        
     253
    254254        size_t idx = h->op->key_hash(key) % h->bucket_cnt;
    255255
     
    264264                }
    265265        }
    266        
     266
    267267        return NULL;
    268268}
     
    306306        assert(h && h->bucket);
    307307        assert(!h->apply_ongoing);
    308        
     308
    309309        size_t idx = h->op->key_hash(key) % h->bucket_cnt;
    310310
    311311        size_t removed = 0;
    312        
     312
    313313        list_foreach_safe(h->bucket[idx], cur, next) {
    314314                ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link);
    315                
     315
    316316                if (h->op->key_equal(key, cur_link)) {
    317317                        ++removed;
     
    323323        h->item_cnt -= removed;
    324324        shrink_if_needed(h);
    325        
     325
    326326        return removed;
    327327}
     
    353353        assert(f);
    354354        assert(h && h->bucket);
    355        
     355
    356356        if (h->item_cnt == 0)
    357357                return;
    358        
     358
    359359        h->apply_ongoing = true;
    360        
     360
    361361        for (size_t idx = 0; idx < h->bucket_cnt; ++idx) {
    362362                list_foreach_safe(h->bucket[idx], cur, next) {
     
    372372out:
    373373        h->apply_ongoing = false;
    374        
     374
    375375        shrink_if_needed(h);
    376376        grow_if_needed(h);
     
    381381{
    382382        size_t rounded_size = HT_MIN_BUCKETS;
    383        
     383
    384384        while (rounded_size < size) {
    385385                rounded_size = 2 * rounded_size + 1;
    386386        }
    387        
     387
    388388        return rounded_size;
    389389}
     
    393393{
    394394        assert(pbuckets && HT_MIN_BUCKETS <= bucket_cnt);
    395                
     395
    396396        list_t *buckets = malloc(bucket_cnt * sizeof(list_t));
    397397        if (!buckets)
    398398                return false;
    399        
     399
    400400        for (size_t i = 0; i < bucket_cnt; i++)
    401401                list_initialize(&buckets[i]);
     
    435435        assert(h && h->bucket);
    436436        assert(HT_MIN_BUCKETS <= new_bucket_cnt);
    437        
     437
    438438        /* We are traversing the table and resizing would mess up the buckets. */
    439439        if (h->apply_ongoing)
    440440                return;
    441        
     441
    442442        list_t *new_buckets;
    443443
     
    445445        if (!alloc_table(new_bucket_cnt, &new_buckets))
    446446                return;
    447        
     447
    448448        if (0 < h->item_cnt) {
    449449                /* Rehash all the items to the new table. */
     
    458458                }
    459459        }
    460        
     460
    461461        free(h->bucket);
    462462        h->bucket = new_buckets;
Note: See TracChangeset for help on using the changeset viewer.