Changeset bc216a0 in mainline for uspace/srv/hid/input/generic/gsp.c
- Timestamp:
- 2012-08-07T22:13:44Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- da68871a
- Parents:
- b17518e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/generic/gsp.c
rb17518e rbc216a0 51 51 #include <gsp.h> 52 52 #include <adt/hash_table.h> 53 #include <adt/hash.h> 53 54 #include <stdlib.h> 54 55 #include <stdio.h> 55 56 56 57 /* 57 * Hash table operations for the transition function. 58 */ 59 60 static size_t trans_op_hash(const link_t *item); 61 static size_t trans_op_key_hash(unsigned long key[]); 62 static bool trans_op_match(unsigned long key[], size_t keys, const link_t *item); 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 } 63 84 64 85 static hash_table_ops_t trans_ops = { 65 .hash = trans_ op_hash,66 .key_hash = trans_ op_key_hash,67 . match = trans_op_match,86 .hash = trans_hash, 87 .key_hash = trans_key_hash, 88 .key_equal = trans_key_equal, 68 89 .equal = 0, 69 90 .remove_callback = 0 70 91 }; 71 92 93 72 94 static gsp_trans_t *trans_lookup(gsp_t *p, int state, int input); 73 95 static void trans_insert(gsp_t *p, gsp_trans_t *t); … … 78 100 { 79 101 p->states = 1; 80 hash_table_create(&p->trans, 0, 2, &trans_ops);102 hash_table_create(&p->trans, 0, 0, &trans_ops); 81 103 } 82 104 … … 222 244 static gsp_trans_t *trans_lookup(gsp_t *p, int state, int input) 223 245 { 224 link_t *item; 225 unsigned long key[2]; 226 227 key[0] = state; 228 key[1] = input; 229 230 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); 231 254 if (item == NULL) return NULL; 232 255 233 return hash_table_get_inst ance(item, gsp_trans_t, link);256 return hash_table_get_inst(item, gsp_trans_t, link); 234 257 } 235 258 … … 258 281 } 259 282 260 /*261 * Transition function hash table operations.262 */263 264 static size_t trans_op_key_hash(unsigned long key[])265 {266 return (key[0] * 17 + key[1]);267 }268 269 static 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->input275 };276 277 return trans_op_key_hash(key);278 }279 280 static 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);283 return ((key[0] == (unsigned long) t->old_state)284 && (key[1] == (unsigned long) t->input));285 }286 283 287 284 /**
Note:
See TracChangeset
for help on using the changeset viewer.