Changes in kernel/generic/include/adt/hash_table.h [82cbf8c6:9d58539] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/adt/hash_table.h
r82cbf8c6 r9d58539 1 1 /* 2 2 * Copyright (c) 2006 Jakub Jermar 3 * Copyright (c) 2012 Adam Hraska4 *5 3 * All rights reserved. 6 4 * … … 29 27 */ 30 28 31 /** @addtogroup libc29 /** @addtogroup genericadt 32 30 * @{ 33 31 */ … … 35 33 */ 36 34 37 #ifndef LIBC_HASH_TABLE_H_38 #define LIBC_HASH_TABLE_H_35 #ifndef KERN_HASH_TABLE_H_ 36 #define KERN_HASH_TABLE_H_ 39 37 40 38 #include <adt/list.h> 41 #include <stdbool.h> 42 #include <macros.h> 43 44 /** Opaque hash table link type. */ 45 typedef struct ht_link { 46 link_t link; 47 } ht_link_t; 39 #include <typedefs.h> 48 40 49 41 /** Set of operations for hash table. */ 50 42 typedef struct { 51 /** Returns the hash of the key stored in the item (ie its lookup key). */ 52 size_t (*hash)(const ht_link_t *item); 43 /** Hash function. 44 * 45 * @param key Array of keys needed to compute hash index. All keys must 46 * be passed. 47 * 48 * @return Index into hash table. 49 */ 50 size_t (* hash)(sysarg_t key[]); 53 51 54 /** Returns the hash of the key. */55 size_t (*key_hash)(void *key);56 57 /** True if the items are equal (have the same lookup keys). */58 bool (*equal)(const ht_link_t *item1, const ht_link_t *item2);59 60 /** Returns true if the key is equal to the item's lookup key.*/61 bool (* key_equal)(void *key, const ht_link_t *item);52 /** Hash table item comparison function. 53 * 54 * @param key Array of keys that will be compared with item. It is not 55 * necessary to pass all keys. 56 * 57 * @return true if the keys match, false otherwise. 58 */ 59 bool (*compare)(sysarg_t key[], size_t keys, link_t *item); 62 60 63 61 /** Hash table item removal callback. 64 *65 * Must not invoke any mutating functions of the hash table.66 62 * 67 63 * @param item Item that was removed from the hash table. 68 64 */ 69 void (*remove_callback)( ht_link_t *item);70 } hash_table_op s_t;65 void (*remove_callback)(link_t *item); 66 } hash_table_operations_t; 71 67 72 68 /** Hash table structure. */ 73 69 typedef struct { 74 hash_table_ops_t *op; 75 list_t *bucket; 76 size_t bucket_cnt; 77 size_t full_item_cnt; 78 size_t item_cnt; 79 size_t max_load; 80 bool apply_ongoing; 70 list_t *entry; 71 size_t entries; 72 size_t max_keys; 73 hash_table_operations_t *op; 81 74 } hash_table_t; 82 75 83 #define hash_table_get_inst (item, type, member) \84 member_to_inst((item), type, member)76 #define hash_table_get_instance(item, type, member) \ 77 list_get_instance((item), type, member) 85 78 86 extern bool hash_table_create(hash_table_t *, size_t, size_t, 87 hash_table_ops_t *); 88 extern void hash_table_destroy(hash_table_t *); 89 90 extern bool hash_table_empty(hash_table_t *); 91 extern size_t hash_table_size(hash_table_t *); 92 93 extern void hash_table_clear(hash_table_t *); 94 extern void hash_table_insert(hash_table_t *, ht_link_t *); 95 extern bool hash_table_insert_unique(hash_table_t *, ht_link_t *); 96 extern ht_link_t *hash_table_find(const hash_table_t *, void *); 97 extern ht_link_t *hash_table_find_next(const hash_table_t *, ht_link_t *); 98 extern size_t hash_table_remove(hash_table_t *, void *); 99 extern void hash_table_remove_item(hash_table_t *, ht_link_t *); 100 extern void hash_table_apply(hash_table_t *, bool (*)(ht_link_t *, void *), 101 void *); 102 79 extern void hash_table_create(hash_table_t *h, size_t m, size_t max_keys, 80 hash_table_operations_t *op); 81 extern void hash_table_insert(hash_table_t *h, sysarg_t key[], link_t *item); 82 extern link_t *hash_table_find(hash_table_t *h, sysarg_t key[]); 83 extern void hash_table_remove(hash_table_t *h, sysarg_t key[], size_t keys); 103 84 104 85 #endif
Note:
See TracChangeset
for help on using the changeset viewer.