Changeset 9f4067b6 in mainline for uspace/srv/hid/input/gsp.c
- Timestamp:
- 2012-10-09T21:16:13Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6659037, 7d248e3
- Parents:
- d1ef4a1 (diff), 97b199b1 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/gsp.c
rd1ef4a1 r9f4067b6 50 50 51 51 #include <adt/hash_table.h> 52 #include <adt/hash.h> 52 53 #include <stdlib.h> 53 54 #include <stdio.h> 54 55 #include "gsp.h" 55 56 56 #define TRANS_TABLE_CHAINS 25657 58 57 /* 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 */ 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 71 91 }; 92 72 93 73 94 static gsp_trans_t *trans_lookup(gsp_t *p, int state, int input); … … 75 96 static gsp_trans_t *trans_new(void); 76 97 77 /** Initiali se scancode parser. */98 /** Initialize scancode parser. */ 78 99 void gsp_init(gsp_t *p) 79 100 { 80 101 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); 82 103 } 83 104 … … 223 244 static gsp_trans_t *trans_lookup(gsp_t *p, int state, int input) 224 245 { 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); 232 254 if (item == NULL) return NULL; 233 255 234 return hash_table_get_inst ance(item, gsp_trans_t, link);256 return hash_table_get_inst(item, gsp_trans_t, link); 235 257 } 236 258 … … 242 264 static void trans_insert(gsp_t *p, gsp_trans_t *t) 243 265 { 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); 250 267 } 251 268 … … 264 281 } 265 282 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 }288 283 289 284 /**
Note:
See TracChangeset
for help on using the changeset viewer.