Changeset 0ca7286 in mainline for uspace/srv/hid/input/generic/gsp.c


Ignore:
Timestamp:
2012-07-21T11:19:27Z (13 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/srv/hid/input/generic/gsp.c

    r1c1da4b r0ca7286  
    5454#include <stdio.h>
    5555
    56 #define TRANS_TABLE_CHAINS 256
    57 
    5856/*
    5957 * Hash table operations for the transition function.
    6058 */
    6159
    62 static hash_index_t trans_op_hash(unsigned long key[]);
    63 static int trans_op_compare(unsigned long key[], hash_count_t keys,
    64     link_t *item);
    65 static void trans_op_remove_callback(link_t *item);
    66 
    67 static hash_table_operations_t trans_ops = {
     60static size_t trans_op_hash(const link_t *item);
     61static size_t trans_op_key_hash(unsigned long key[]);
     62static bool trans_op_match(unsigned long key[], size_t keys, const link_t *item);
     63
     64static hash_table_ops_t trans_ops = {
    6865        .hash = trans_op_hash,
    69         .compare = trans_op_compare,
    70         .remove_callback = trans_op_remove_callback
     66        .key_hash = trans_op_key_hash,
     67        .match = trans_op_match,
     68        .equal = 0,
     69        .remove_callback = 0
    7170};
    7271
     
    7574static gsp_trans_t *trans_new(void);
    7675
    77 /** Initialise scancode parser. */
     76/** Initialize scancode parser. */
    7877void gsp_init(gsp_t *p)
    7978{
    8079        p->states = 1;
    81         hash_table_create(&p->trans, TRANS_TABLE_CHAINS, 2, &trans_ops);
     80        hash_table_create(&p->trans, 0, 2, &trans_ops);
    8281}
    8382
     
    242241static void trans_insert(gsp_t *p, gsp_trans_t *t)
    243242{
    244         unsigned long key[2];
    245 
    246         key[0] = t->old_state;
    247         key[1] = t->input;
    248 
    249         hash_table_insert(&p->trans, key, &t->link);
     243        hash_table_insert(&p->trans, &t->link);
    250244}
    251245
     
    268262 */
    269263
    270 static hash_index_t trans_op_hash(unsigned long key[])
    271 {
    272         return (key[0] * 17 + key[1]) % TRANS_TABLE_CHAINS;
    273 }
    274 
    275 static int trans_op_compare(unsigned long key[], hash_count_t keys,
    276     link_t *item)
    277 {
    278         gsp_trans_t *t;
    279 
    280         t = hash_table_get_instance(item, gsp_trans_t, link);
     264static size_t trans_op_key_hash(unsigned long key[])
     265{
     266        return (key[0] * 17 + key[1]);
     267}
     268
     269static size_t trans_op_hash(const link_t *item)
     270{
     271        gsp_trans_t *t = hash_table_get_instance(item, gsp_trans_t, link);
     272        unsigned long key[] = {
     273                t->old_state,
     274                t->input
     275        };
     276       
     277        return trans_op_key_hash(key);
     278}
     279
     280static bool trans_op_match(unsigned long key[], size_t keys, const link_t *item)
     281{
     282        gsp_trans_t *t = hash_table_get_instance(item, gsp_trans_t, link);
    281283        return ((key[0] == (unsigned long) t->old_state)
    282284            && (key[1] == (unsigned long) t->input));
    283 }
    284 
    285 static void trans_op_remove_callback(link_t *item)
    286 {
    287285}
    288286
Note: See TracChangeset for help on using the changeset viewer.