Changeset bc216a0 in mainline for uspace/app


Ignore:
Timestamp:
2012-08-07T22:13:44Z (14 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().

Location:
uspace/app
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/mkexfat/mkexfat.c

    rb17518e rbc216a0  
    4949#include <str.h>
    5050#include <getopt.h>
     51#include <macros.h>
    5152#include "exfat.h"
    5253#include "upcase.h"
     
    8788#define FIRST_FREE_CLUSTER   2
    8889
    89 #define min(x, y) ((x) < (y) ? (x) : (y))
    9090
    9191typedef struct exfat_cfg {
  • uspace/app/trace/ipcp.c

    rb17518e rbc216a0  
    5353        ipc_callid_t call_hash;
    5454
    55         link_t link;
     55        ht_link_t link;
    5656} pending_call_t;
    5757
     
    7373proto_t *proto_unknown;         /**< Protocol with no known methods. */
    7474
    75 static size_t pending_call_key_hash(unsigned long key[]);
    76 static size_t pending_call_hash(const link_t *item);
    77 static bool pending_call_match(unsigned long key[], size_t keys,
    78     const link_t *item);
     75
     76static size_t pending_call_key_hash(void *key)
     77{
     78        ipc_callid_t *call_id = (ipc_callid_t *)key;
     79        return *call_id;
     80}
     81
     82static size_t pending_call_hash(const ht_link_t *item)
     83{
     84        pending_call_t *hs = hash_table_get_inst(item, pending_call_t, link);
     85        return hs->call_hash;
     86}
     87
     88static bool pending_call_key_equal(void *key, const ht_link_t *item)
     89{
     90        ipc_callid_t *call_id = (ipc_callid_t *)key;
     91        pending_call_t *hs = hash_table_get_inst(item, pending_call_t, link);
     92
     93        return *call_id == hs->call_hash;
     94}
    7995
    8096static hash_table_ops_t pending_call_ops = {
    8197        .hash = pending_call_hash,
    8298        .key_hash = pending_call_key_hash,
    83         .match = pending_call_match,
     99        .key_equal = pending_call_key_equal,
    84100        .equal = 0,
    85101        .remove_callback = 0
    86102};
    87 
    88 
    89 static size_t pending_call_key_hash(unsigned long key[])
    90 {
    91         size_t hash = 17;
    92         hash = 31 * hash + key[1];
    93         hash = 31 * hash + key[0];
    94         return hash;
    95 }
    96 
    97 static size_t pending_call_hash(const link_t *item)
    98 {
    99         pending_call_t *hs = hash_table_get_instance(item, pending_call_t, link);
    100         unsigned long key[] = {
    101                 LOWER32(hs->call_hash),
    102                 UPPER32(hs->call_hash)
    103         };
    104         return pending_call_key_hash(key);
    105 }
    106 
    107 static bool pending_call_match(unsigned long key[], size_t keys,
    108         const link_t *item)
    109 {
    110         assert(keys == 2);
    111         pending_call_t *hs = hash_table_get_instance(item, pending_call_t, link);
    112 
    113         return MERGE_LOUP32(key[0], key[1]) == hs->call_hash;
    114 }
    115 
    116103
    117104
     
    184171        }
    185172
    186         hash_table_create(&pending_calls, 0, 2, &pending_call_ops);
     173        bool ok = hash_table_create(&pending_calls, 0, 0, &pending_call_ops);
     174        assert(ok);
    187175}
    188176
     
    338326void ipcp_call_in(ipc_call_t *call, ipc_callid_t hash)
    339327{
    340         link_t *item;
     328        ht_link_t *item;
    341329        pending_call_t *pcall;
    342330       
     
    350338       
    351339        hash = hash & ~IPC_CALLID_ANSWERED;
    352         unsigned long key[] = {
    353                 LOWER32(hash),
    354                 UPPER32(hash)
    355         };
    356        
    357         item = hash_table_find(&pending_calls, key);
     340       
     341        item = hash_table_find(&pending_calls, &hash);
    358342        if (item == NULL)
    359343                return; /* No matching question found */
     
    363347         */
    364348       
    365         pcall = hash_table_get_instance(item, pending_call_t, link);
    366         hash_table_remove(&pending_calls, key, 2);
     349        pcall = hash_table_get_inst(item, pending_call_t, link);
     350        hash_table_remove(&pending_calls, &hash);
    367351       
    368352        parse_answer(hash, pcall, call);
  • uspace/app/trace/proto.c

    rb17518e rbc216a0  
    4545
    4646typedef struct {
    47         unsigned srv;
     47        int srv;
    4848        proto_t *proto;
    49         link_t link;
     49        ht_link_t link;
    5050} srv_proto_t;
    5151
    5252typedef struct {
    53         sysarg_t method;
     53        int method;
    5454        oper_t *oper;
    55         link_t link;
     55        ht_link_t link;
    5656} method_oper_t;
    5757
    58 
    59 
    60 
    61 static size_t srv_proto_key_hash(unsigned long key[])
    62 {
    63         return key[0];
    64 }
    65 
    66 static size_t srv_proto_hash(const link_t *item)
    67 {
    68         srv_proto_t *sp = hash_table_get_instance(item, srv_proto_t, link);
    69         unsigned long key = sp->srv;
    70         return srv_proto_key_hash(&key);       
    71 }
    72 
    73 static bool srv_proto_match(unsigned long key[], size_t keys, const link_t *item)
    74 {
    75         srv_proto_t *sp = hash_table_get_instance(item, srv_proto_t, link);
    76 
    77         return key[0] == sp->srv;
     58/* Hash table operations. */
     59
     60static size_t srv_proto_key_hash(void *key)
     61{
     62        return *(int *)key;
     63}
     64
     65static size_t srv_proto_hash(const ht_link_t *item)
     66{
     67        srv_proto_t *sp = hash_table_get_inst(item, srv_proto_t, link);
     68        return sp->srv;
     69}
     70
     71static bool srv_proto_key_equal(void *key, const ht_link_t *item)
     72{
     73        srv_proto_t *sp = hash_table_get_inst(item, srv_proto_t, link);
     74        return sp->srv == *(int *)key;
    7875}
    7976
     
    8178        .hash = srv_proto_hash,
    8279        .key_hash = srv_proto_key_hash,
    83         .match = srv_proto_match,
     80        .key_equal = srv_proto_key_equal,
    8481        .equal = 0,
    8582        .remove_callback = 0
     
    8784
    8885
    89 static size_t method_oper_key_hash(unsigned long key[])
    90 {
    91         return key[0];
    92 }
    93 
    94 static size_t method_oper_hash(const link_t *item)
    95 {
    96         method_oper_t *mo = hash_table_get_instance(item, method_oper_t, link);
    97         unsigned long key = mo->method;
    98         return method_oper_key_hash(&key);
    99 }
    100 
    101 static bool method_oper_match(unsigned long key[], size_t keys,
    102         const link_t *item)
    103 {
    104         method_oper_t *mo = hash_table_get_instance(item, method_oper_t, link);
    105 
    106         return key[0] == mo->method;
     86static size_t method_oper_key_hash(void *key)
     87{
     88        return *(int *)key;
     89}
     90
     91static size_t method_oper_hash(const ht_link_t *item)
     92{
     93        method_oper_t *mo = hash_table_get_inst(item, method_oper_t, link);
     94        return mo->method;
     95}
     96
     97static bool method_oper_key_equal(void *key, const ht_link_t *item)
     98{
     99        method_oper_t *mo = hash_table_get_inst(item, method_oper_t, link);
     100        return mo->method == *(int *)key;
    107101}
    108102
     
    110104        .hash = method_oper_hash,
    111105        .key_hash = method_oper_key_hash,
    112         .match = method_oper_match,
     106        .key_equal = method_oper_key_equal,
    113107        .equal = 0,
    114108        .remove_callback = 0
     
    118112void proto_init(void)
    119113{
    120         hash_table_create(&srv_proto, 0, 1, &srv_proto_ops);
     114        /* todo: check return value. */
     115        bool ok = hash_table_create(&srv_proto, 0, 0, &srv_proto_ops);
     116        assert(ok);
    121117}
    122118
     
    139135proto_t *proto_get_by_srv(int srv)
    140136{
    141         link_t *item;
    142         srv_proto_t *sp;
    143 
    144         unsigned long key = srv;
    145         item = hash_table_find(&srv_proto, &key);
     137        ht_link_t *item = hash_table_find(&srv_proto, &srv);
    146138        if (item == NULL) return NULL;
    147139
    148         sp = hash_table_get_instance(item, srv_proto_t, link);
     140        srv_proto_t *sp = hash_table_get_inst(item, srv_proto_t, link);
    149141        return sp->proto;
    150142}
     
    153145{
    154146        proto->name = name;
    155         hash_table_create(&proto->method_oper, 0, 1, &method_oper_ops);
     147        /* todo: check return value. */
     148        bool ok = hash_table_create(&proto->method_oper, 0, 0, &method_oper_ops);
     149        assert(ok);
    156150}
    157151
     
    184178oper_t *proto_get_oper(proto_t *proto, int method)
    185179{
    186         unsigned long key;
    187         link_t *item;
    188         method_oper_t *mo;
    189 
    190         key = method;
    191         item = hash_table_find(&proto->method_oper, &key);
     180        ht_link_t *item = hash_table_find(&proto->method_oper, &method);
    192181        if (item == NULL) return NULL;
    193182
    194         mo = hash_table_get_instance(item, method_oper_t, link);
     183        method_oper_t *mo = hash_table_get_inst(item, method_oper_t, link);
    195184        return mo->oper;
    196185}
Note: See TracChangeset for help on using the changeset viewer.