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


Ignore:
Timestamp:
2012-07-21T11:19:27Z (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:
2732c94
Parents:
1c1da4b
Message:

Added resizing to user space (single-threaded) hash_table. Resizes in a way to mitigate effects of bad hash functions. Change of interface affected many files.

File:
1 edited

Legend:

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

    r1c1da4b r0ca7286  
    4040#include <errno.h>
    4141
    42 #define NIC_WV_HASH_COUNT 32
    43 
    44 /**
    45  * Hash table helper function
    46  */
    47 static int nic_wv_compare(unsigned long key[], hash_count_t keys,
    48         link_t *item)
     42
     43/*
     44 * Hash table helper functions
     45 */
     46
     47static size_t nic_wv_key_hash(unsigned long keys[])
     48{
     49        return keys[0];
     50}
     51
     52static size_t nic_wv_hash(const link_t *item)
     53{
     54        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
     59static bool nic_wv_match(unsigned long key[], size_t keys, const link_t *item)
    4960{
    5061        nic_wol_virtue_t *virtue = (nic_wol_virtue_t *) item;
     
    5364
    5465/**
    55  * Hash table helper function
    56  */
    57 static void nic_wv_rc(link_t *item)
    58 {
    59 }
    60 
    61 /**
    62  * Hash table helper function
    63  */
    64 static hash_index_t nic_wv_hash(unsigned long keys[])
    65 {
    66         return keys[0] % NIC_WV_HASH_COUNT;
    67 }
    68 
    69 /**
    7066 * Initializes the WOL virtues structure
    7167 *
     
    7773int nic_wol_virtues_init(nic_wol_virtues_t *wvs)
    7874{
    79         bzero(wvs, sizeof (nic_wol_virtues_t));
    80         wvs->table_operations.compare = nic_wv_compare;
     75        bzero(wvs, sizeof(nic_wol_virtues_t));
    8176        wvs->table_operations.hash = nic_wv_hash;
    82         wvs->table_operations.remove_callback = nic_wv_rc;
    83         if (!hash_table_create(&wvs->table, NIC_WV_HASH_COUNT, 1,
    84                 &wvs->table_operations)) {
     77        wvs->table_operations.key_hash = nic_wv_key_hash;
     78        wvs->table_operations.match = nic_wv_match;
     79        wvs->table_operations.equal = 0;
     80        wvs->table_operations.remove_callback = 0;
     81       
     82        if (!hash_table_create(&wvs->table, 0, 1, &wvs->table_operations)) {
    8583                return ENOMEM;
    8684        }
     
    172170        } while (NULL !=
    173171                hash_table_find(&wvs->table, (unsigned long *) &virtue->id));
    174         hash_table_insert(&wvs->table,
    175                 (unsigned long *) &virtue->id, &virtue->item);
     172        hash_table_insert(&wvs->table, &virtue->item);
    176173        virtue->next = wvs->lists[virtue->type];
    177174        wvs->lists[virtue->type] = virtue;
Note: See TracChangeset for help on using the changeset viewer.