Changeset eb522e8 in mainline for uspace/lib/c/include/adt/hash_table.h
- Timestamp:
- 2011-06-01T08:43:42Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8d6c1f1
- Parents:
- 9e2e715 (diff), e51a514 (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/lib/c/include/adt/hash_table.h
r9e2e715 reb522e8 38 38 #include <adt/list.h> 39 39 #include <unistd.h> 40 #include <bool.h> 40 41 41 42 typedef unsigned long hash_count_t; 42 43 typedef unsigned long hash_index_t; 43 typedef struct hash_table hash_table_t; 44 typedef struct hash_table_operations hash_table_operations_t; 44 45 /** Set of operations for hash table. */ 46 typedef struct { 47 /** Hash function. 48 * 49 * @param key Array of keys needed to compute hash index. 50 * All keys must be passed. 51 * 52 * @return Index into hash table. 53 * 54 */ 55 hash_index_t (*hash)(unsigned long key[]); 56 57 /** Hash table item comparison function. 58 * 59 * @param key Array of keys that will be compared with item. It is 60 * not necessary to pass all keys. 61 * 62 * @return True if the keys match, false otherwise. 63 * 64 */ 65 int (*compare)(unsigned long key[], hash_count_t keys, link_t *item); 66 67 /** Hash table item removal callback. 68 * 69 * @param item Item that was removed from the hash table. 70 * 71 */ 72 void (*remove_callback)(link_t *item); 73 } hash_table_operations_t; 45 74 46 75 /** Hash table structure. */ 47 struct hash_table{76 typedef struct { 48 77 link_t *entry; 49 78 hash_count_t entries; 50 79 hash_count_t max_keys; 51 80 hash_table_operations_t *op; 52 }; 53 54 /** Set of operations for hash table. */ 55 struct hash_table_operations { 56 /** Hash function. 57 * 58 * @param key Array of keys needed to compute hash index. All keys 59 * must be passed. 60 * 61 * @return Index into hash table. 62 */ 63 hash_index_t (* hash)(unsigned long key[]); 64 65 /** Hash table item comparison function. 66 * 67 * @param key Array of keys that will be compared with item. It is 68 * not necessary to pass all keys. 69 * 70 * @return true if the keys match, false otherwise. 71 */ 72 int (*compare)(unsigned long key[], hash_count_t keys, link_t *item); 73 74 /** Hash table item removal callback. 75 * 76 * @param item Item that was removed from the hash table. 77 */ 78 void (*remove_callback)(link_t *item); 79 }; 81 } hash_table_t; 80 82 81 83 #define hash_table_get_instance(item, type, member) \ 82 84 list_get_instance((item), type, member) 83 85 84 extern inthash_table_create(hash_table_t *, hash_count_t, hash_count_t,86 extern bool hash_table_create(hash_table_t *, hash_count_t, hash_count_t, 85 87 hash_table_operations_t *); 86 88 extern void hash_table_insert(hash_table_t *, unsigned long [], link_t *);
Note:
See TracChangeset
for help on using the changeset viewer.