Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/input/gsp.c

    r4e00f87 rb6a088f  
    5050
    5151#include <adt/hash_table.h>
    52 #include <adt/hash.h>
    5352#include <stdlib.h>
    5453#include <stdio.h>
    5554#include "gsp.h"
    5655
     56#define TRANS_TABLE_CHAINS  256
     57
    5758/*
    58  * Transition function hash table operations.
    59  */
    60 typedef struct {
    61         int old_state;
    62         int input;
    63 } trans_key_t;
    64 
    65 static size_t trans_key_hash(void *key)
    66 {
    67         trans_key_t *trans_key = (trans_key_t *)key;
    68         return hash_combine(trans_key->input, trans_key->old_state);
    69 }
    70 
    71 static size_t trans_hash(const ht_link_t *item)
    72 {
    73         gsp_trans_t *t = hash_table_get_inst(item, gsp_trans_t, link);
    74         return hash_combine(t->input, t->old_state);
    75 }
    76 
    77 static bool trans_key_equal(void *key, const ht_link_t *item)
    78 {
    79         trans_key_t *trans_key = (trans_key_t *)key;
    80         gsp_trans_t *t = hash_table_get_inst(item, gsp_trans_t, link);
    81        
    82         return trans_key->input == t->input && trans_key->old_state == t->old_state;
    83 }
    84 
    85 static hash_table_ops_t trans_ops = {
    86         .hash = trans_hash,
    87         .key_hash = trans_key_hash,
    88         .key_equal = trans_key_equal,
    89         .equal = NULL,
    90         .remove_callback = NULL
     59 * Hash table operations for the transition function.
     60 */
     61
     62static hash_index_t trans_op_hash(unsigned long key[]);
     63static int trans_op_compare(unsigned long key[], hash_count_t keys,
     64    link_t *item);
     65static void trans_op_remove_callback(link_t *item);
     66
     67static hash_table_operations_t trans_ops = {
     68        .hash = trans_op_hash,
     69        .compare = trans_op_compare,
     70        .remove_callback = trans_op_remove_callback
    9171};
    92 
    9372
    9473static gsp_trans_t *trans_lookup(gsp_t *p, int state, int input);
     
    9675static gsp_trans_t *trans_new(void);
    9776
    98 /** Initialize scancode parser. */
     77/** Initialise scancode parser. */
    9978void gsp_init(gsp_t *p)
    10079{
    10180        p->states = 1;
    102         hash_table_create(&p->trans, 0, 0, &trans_ops);
     81        hash_table_create(&p->trans, TRANS_TABLE_CHAINS, 2, &trans_ops);
    10382}
    10483
     
    244223static gsp_trans_t *trans_lookup(gsp_t *p, int state, int input)
    245224{
    246         ht_link_t *item;
    247        
    248         trans_key_t key = {
    249                 .input = input,
    250                 .old_state = state
    251         };
    252 
    253         item = hash_table_find(&p->trans, &key);
     225        link_t *item;
     226        unsigned long key[2];
     227
     228        key[0] = state;
     229        key[1] = input;
     230
     231        item = hash_table_find(&p->trans, key);
    254232        if (item == NULL) return NULL;
    255233
    256         return hash_table_get_inst(item, gsp_trans_t, link);
     234        return hash_table_get_instance(item, gsp_trans_t, link);
    257235}
    258236
     
    264242static void trans_insert(gsp_t *p, gsp_trans_t *t)
    265243{
    266         hash_table_insert(&p->trans, &t->link);
     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);
    267250}
    268251
     
    281264}
    282265
     266/*
     267 * Transition function hash table operations.
     268 */
     269
     270static hash_index_t trans_op_hash(unsigned long key[])
     271{
     272        return (key[0] * 17 + key[1]) % TRANS_TABLE_CHAINS;
     273}
     274
     275static 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);
     281        return ((key[0] == (unsigned long) t->old_state)
     282            && (key[1] == (unsigned long) t->input));
     283}
     284
     285static void trans_op_remove_callback(link_t *item)
     286{
     287}
    283288
    284289/**
Note: See TracChangeset for help on using the changeset viewer.