Changeset b800b0e in mainline for uspace/srv/hid/input/gsp.c


Ignore:
Timestamp:
2012-10-23T13:16:49Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6ecf5b8
Parents:
32b3a12 (diff), b2ac3998 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

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

    r32b3a12 rb800b0e  
    5050
    5151#include <adt/hash_table.h>
     52#include <adt/hash.h>
    5253#include <stdlib.h>
    5354#include <stdio.h>
    5455#include "gsp.h"
    5556
    56 #define TRANS_TABLE_CHAINS  256
    57 
    5857/*
    59  * Hash table operations for the transition function.
    60  */
    61 
    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 = {
    68         .hash = trans_op_hash,
    69         .compare = trans_op_compare,
    70         .remove_callback = trans_op_remove_callback
     58 * Transition function hash table operations.
     59 */
     60typedef struct {
     61        int old_state;
     62        int input;
     63} trans_key_t;
     64
     65static 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
     71static 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
     77static 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
     85static 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
    7191};
     92
    7293
    7394static gsp_trans_t *trans_lookup(gsp_t *p, int state, int input);
     
    7596static gsp_trans_t *trans_new(void);
    7697
    77 /** Initialise scancode parser. */
     98/** Initialize scancode parser. */
    7899void gsp_init(gsp_t *p)
    79100{
    80101        p->states = 1;
    81         hash_table_create(&p->trans, TRANS_TABLE_CHAINS, 2, &trans_ops);
     102        hash_table_create(&p->trans, 0, 0, &trans_ops);
    82103}
    83104
     
    223244static gsp_trans_t *trans_lookup(gsp_t *p, int state, int input)
    224245{
    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);
     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);
    232254        if (item == NULL) return NULL;
    233255
    234         return hash_table_get_instance(item, gsp_trans_t, link);
     256        return hash_table_get_inst(item, gsp_trans_t, link);
    235257}
    236258
     
    242264static void trans_insert(gsp_t *p, gsp_trans_t *t)
    243265{
    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);
     266        hash_table_insert(&p->trans, &t->link);
    250267}
    251268
     
    264281}
    265282
    266 /*
    267  * Transition function hash table operations.
    268  */
    269 
    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);
    281         return ((key[0] == (unsigned long) t->old_state)
    282             && (key[1] == (unsigned long) t->input));
    283 }
    284 
    285 static void trans_op_remove_callback(link_t *item)
    286 {
    287 }
    288283
    289284/**
Note: See TracChangeset for help on using the changeset viewer.