Changes in uspace/srv/hid/input/gsp.c [4e00f87:b6a088f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/input/gsp.c
r4e00f87 rb6a088f 50 50 51 51 #include <adt/hash_table.h> 52 #include <adt/hash.h>53 52 #include <stdlib.h> 54 53 #include <stdio.h> 55 54 #include "gsp.h" 56 55 56 #define TRANS_TABLE_CHAINS 256 57 57 58 /* 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 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 91 71 }; 92 93 72 94 73 static gsp_trans_t *trans_lookup(gsp_t *p, int state, int input); … … 96 75 static gsp_trans_t *trans_new(void); 97 76 98 /** Initiali ze scancode parser. */77 /** Initialise scancode parser. */ 99 78 void gsp_init(gsp_t *p) 100 79 { 101 80 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); 103 82 } 104 83 … … 244 223 static gsp_trans_t *trans_lookup(gsp_t *p, int state, int input) 245 224 { 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); 254 232 if (item == NULL) return NULL; 255 233 256 return hash_table_get_inst (item, gsp_trans_t, link);234 return hash_table_get_instance(item, gsp_trans_t, link); 257 235 } 258 236 … … 264 242 static void trans_insert(gsp_t *p, gsp_trans_t *t) 265 243 { 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); 267 250 } 268 251 … … 281 264 } 282 265 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 } 283 288 284 289 /**
Note:
See TracChangeset
for help on using the changeset viewer.