Changeset 204 for trunk/kernel/libk/xhtab.h
- Timestamp:
- Jul 17, 2017, 8:42:59 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/xhtab.h
r188 r204 36 36 // It can be accessed by any thread, running in any cluster. 37 37 // It is generic as it can be used to register various types of items. 38 // The main goal is to speedup search by key fora large number of items of same type.38 // The main goal is to speedup search by key in a large number of items of same type. 39 39 // For this purpose the set of all registered items is split in several subsets. 40 40 // Each subset is organised as an embedded double linked lists. 41 41 // - an item is uniquely identified by a <key>, that is a single uint32_t value. 42 // - From the <key> value, the hash table uses an item type specific xhtab_index() function,43 // to compute an <index> value, defining a subset of registered items.42 // - From the <key> value, the hash table uses an item type specific xhtab_index() 43 // function, to compute an <index> value, defining a subset of registered items. 44 44 // - to discriminate between items that have the same <index>, the hash table makes 45 // an associative search in subset.45 // an associative search on the key in subset. 46 46 // - Each registered item is a structure, that must contain an embedded xlist_entry, 47 47 // that is part of the xlist implementing the subset. 48 48 // 49 // A total order is defined for all registered itemsby the increasing index values,50 // and for each index value by the position in the partial xlist.49 // For all registered items, a total order is defined by the increasing index values, 50 // and for each index value, by the position in the partial xlist. 51 51 // This order is used by the two functions xhtab_get_first() and xhtab_get_next(), that 52 52 // are used to scan all registered items. The two "current_index" and "current_xlist_xp" … … 54 54 // 55 55 // Implementation Note: 56 // For each supported item type ***, you must define the threeitem-type-specific56 // For each supported item type ***, you must define four item-type-specific 57 57 // functions specified below, and you must update the xhtab_init() function 58 58 // and the xhtab_item_type_t. 59 59 /////////////////////////////////////////////////////////////////////////////////////////// 60 60 61 #define XHASHTAB_SIZE 64// number of subsets61 #define XHASHTAB_SIZE 8 // number of subsets 62 62 63 63 /****************************************************************************************** 64 * This define the three item type specific function prototypes. 64 * This define the four item_type_specific function prototypes that must be defined 65 * for each item type. 65 66 *****************************************************************************************/ 66 67 67 typedef bool_t xhtab_match_t ( xptr_t item_xp , void * key ); 68 typedef xptr_t xhtab_item_t ( xptr_t xlist_xp ); 69 typedef uint32_t xhtab_index_t ( void * key ); 68 typedef bool_t (item_match_key_t) ( xptr_t item_xp , void * key ); 69 typedef xptr_t (item_from_xlist_t) ( xptr_t xlist_xp ); 70 typedef uint32_t (index_from_key_t) ( void * key ); 71 typedef void (item_print_key_t) ( xptr_t item_xp ); 70 72 71 73 /****************************************************************************************** … … 85 87 typedef struct xhtab_s 86 88 { 87 xlist_entry_t roots[XHASHTAB_SIZE]; /*! array of roots of xlist */ 88 xhtab_index_t * index_from_key; /*! item specific function */ 89 xhtab_match_t * item_match_key; /*! item specific function */ 90 xhtab_item_t * item_from_xlist; /*! item specific function */ 91 uint32_t items; /*! number of registered items */ 92 remote_rwlock_t lock; /*! lock protecting hash table accesses */ 93 uint32_t current_index; /*! current item subset index */ 94 xptr_t * current_xlist_xp; /*! xptr on current item xlist entry */ 89 xlist_entry_t roots[XHASHTAB_SIZE]; /*! array of roots of xlist */ 90 index_from_key_t * index_from_key; /*! item specific function pointer */ 91 item_match_key_t * item_match_key; /*! item specific function pointer */ 92 item_from_xlist_t * item_from_xlist; /*! item specific function pointer */ 93 item_print_key_t * item_print_key; /*! item specific function pointer */ 94 uint32_t items; /*! number of registered items */ 95 remote_rwlock_t lock; /*! lock protecting hash table accesses */ 96 uint32_t current_index; /*! current item subset index */ 97 xptr_t current_xlist_xp; /*! xptr on current item xlist entry */ 95 98 } 96 99 xhtab_t; … … 100 103 * The initialisation must be done by a thread running in cluster containing the table. 101 104 ****************************************************************************************** 102 * @ xhtab : local pointer on local xhtab to be initialized.103 * @ type : item type (see above).105 * @ xhtab : local pointer on local xhtab to be initialized. 106 * @ type : item type (see above). 104 107 *****************************************************************************************/ 105 108 void xhtab_init( xhtab_t * xhtab, … … 176 179 xptr_t xhtab_get_next( xptr_t xhtab_xp ); 177 180 178 181 /****************************************************************************************** 182 * This function displays the full content of an xhtab. 183 ****************************************************************************************** 184 * @ xhtab_xp : extended pointer on hash table. 185 *****************************************************************************************/ 186 void xhtab_display( xptr_t xhtab_xp ); 179 187 180 188 #endif /* _XHTAB_H_ */
Note: See TracChangeset
for help on using the changeset viewer.