Changeset bc216a0 in mainline for uspace/lib/nic/src/nic_wol_virtues.c


Ignore:
Timestamp:
2012-08-07T22:13:44Z (12 years ago)
Author:
Adam Hraska <adam.hraska+hos@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
da68871a
Parents:
b17518e
Message:

Refactored any users of hash_table to use opaque void* keys instead of the cumbersome unsigned long[] keys. Switched from the ad hoc computations of hashes of multiple values to hash_combine().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/nic/src/nic_wol_virtues.c

    rb17518e rbc216a0  
    3737
    3838#include "nic_wol_virtues.h"
     39#include "nic.h"
    3940#include <assert.h>
    4041#include <errno.h>
     
    4546 */
    4647
    47 static size_t nic_wv_key_hash(unsigned long keys[])
    48 {
    49         return keys[0];
    50 }
    51 
    52 static size_t nic_wv_hash(const link_t *item)
     48static size_t nic_wv_key_hash(void *key)
     49{
     50        return *(nic_wv_id_t*) key;
     51}
     52
     53static size_t nic_wv_hash(const ht_link_t *item)
    5354{
    5455        nic_wol_virtue_t *virtue = (nic_wol_virtue_t *) item;
    55         unsigned long key = virtue->id;
    56         return nic_wv_key_hash(&key);
    57 }
    58 
    59 static bool nic_wv_match(unsigned long key[], size_t keys, const link_t *item)
     56        return virtue->id;
     57}
     58
     59static bool nic_wv_key_equal(void *key, const ht_link_t *item)
    6060{
    6161        nic_wol_virtue_t *virtue = (nic_wol_virtue_t *) item;
    62         return (virtue->id == (nic_wv_id_t) key[0]);
     62        return (virtue->id == *(nic_wv_id_t*) key);
    6363}
    6464
     
    7676        wvs->table_operations.hash = nic_wv_hash;
    7777        wvs->table_operations.key_hash = nic_wv_key_hash;
    78         wvs->table_operations.match = nic_wv_match;
     78        wvs->table_operations.key_equal = nic_wv_key_equal;
    7979        wvs->table_operations.equal = 0;
    8080        wvs->table_operations.remove_callback = 0;
    8181       
    82         if (!hash_table_create(&wvs->table, 0, 1, &wvs->table_operations)) {
     82        if (!hash_table_create(&wvs->table, 0, 0, &wvs->table_operations)) {
    8383                return ENOMEM;
    8484        }
     
    168168        do {
    169169                virtue->id = wvs->next_id++;
    170         } while (NULL !=
    171                 hash_table_find(&wvs->table, (unsigned long *) &virtue->id));
     170        } while (NULL != hash_table_find(&wvs->table, &virtue->id));
    172171        hash_table_insert(&wvs->table, &virtue->item);
    173172        virtue->next = wvs->lists[virtue->type];
     
    188187nic_wol_virtue_t *nic_wol_virtues_remove(nic_wol_virtues_t *wvs, nic_wv_id_t id)
    189188{
    190         nic_wol_virtue_t *virtue = (nic_wol_virtue_t *)
    191                 hash_table_find(&wvs->table, (unsigned long *) &id);
     189        nic_wol_virtue_t *virtue =
     190                (nic_wol_virtue_t *) hash_table_find(&wvs->table, &id);
    192191        if (virtue == NULL) {
    193192                return NULL;
     
    195194
    196195        /* Remove from filter_table */
    197         hash_table_remove(&wvs->table, (unsigned long *) &id, 1);
     196        hash_table_remove_item(&wvs->table, &virtue->item);
    198197
    199198        /* Remove from filter_types */
     
    232231         * constant virtue the retyping is correct.
    233232         */
    234         link_t *virtue = hash_table_find(
    235                 &((nic_wol_virtues_t *) wvs)->table, (unsigned long *) &id);
     233        ht_link_t *virtue = hash_table_find(&((nic_wol_virtues_t *) wvs)->table, &id);
    236234        return (const nic_wol_virtue_t *) virtue;
    237235}
Note: See TracChangeset for help on using the changeset viewer.