Changeset 23 for trunk/kernel/libk/xhtab.h
- Timestamp:
- Jun 18, 2017, 10:06:41 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/xhtab.h
r14 r23 2 2 * xhtab.h - Remote access embedded hash table definition. 3 3 * 4 * Author Alain Greiner (2016)4 * Author Alain Greiner (2016,2017) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 31 31 32 32 33 /****************************************************************************************** 34 * This file define a generic, embedded, hash table that can be remotely accessed by 35 * any thread running in any cluster. 36 * The main goal is to speedup search by key in a set of items identified by their key. 37 * For this purpose the set of all registered items is split in several subsets: 38 * Each subset is organised an embedded double linked lists. 39 * - an item is uniquely identified by a <key>, that can be a single uint32_t, 40 * a name (character string), or a more complex structure. 41 * - From the <key>, the hash table uses an item type specific "xhtab_index()" function, 42 * to compute an <index> value, defining a subset of registered items. 43 * - to discriminate between items that have the same <index>, the hash table uses another 44 * item type specific "xhtab_compare()" function for the associative search in subset. 45 * - Each registered item is a structure, that must contain an embedded xlist_entry, 46 * that is part of the xlist implementing the subset. 47 * - The xhtab header contains an array indexed by <index> and containing the roots 48 * of the various xlists implementing the subsets. 49 * pointer on the searched item can be obtained by a simple offset. 50 * Implementation note: 51 * to use this generic infrastructure for a new type of item, you must define a new 52 * type in the xhtan_item_type_t" below, and to define the two associated 53 * "xhtab_compare() and xhtab_index(). 54 *****************************************************************************************/ 33 /////////////////////////////////////////////////////////////////////////////////////////// 34 // This file define a generic, embedded, remotely accessible hash table. 35 // 36 // It can be accessed by any thread, running in any cluster. 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 for a large number of items of same type. 39 // For this purpose the set of all registered items is split in several subsets. 40 // Each subset is organised an embedded double linked lists. 41 // - an item is uniquely identified by a <key>, that can be a single uint32_t, 42 // a name (character string), or a more complex structure. 43 // - From the pointer on <key>, we use an item type specific xhtab_index() function, 44 // to compute an <index> value, defining a subset of registered items. 45 // - to discriminate between items that have the same <index>, the hash table uses another 46 // item type specific "xhtab_scan()" function for the associative search in subset. 47 // - Each registered item is a structure, that must contain an embedded xlist_entry, 48 // that is part of the xlist implementing the subset. 49 // 50 // Implementation Note: for each supported item type ***, you must define the two 51 // xhtab_***_index() and xhtab_***_scan() functions, and 52 // update the xhtab_init() function. 53 /////////////////////////////////////////////////////////////////////////////////////////// 55 54 56 55 #define HASHTAB_SIZE 64 // number of subsets 57 56 58 57 /****************************************************************************************** 59 * These typedef define the generic xhtab_compare() and xhtab_index() function prototypes. 60 * It must exist a specific couple of functions for each item type. 61 * @ entry_xp : extended pointer on an xlist_entry_t in a partial xlist. 62 * @ key : local pointer on the searched item key. 63 * @ item_xp : buffer to store extended pointer on found item. 58 * These typedef define the two item type specific function prototypes. 64 59 *****************************************************************************************/ 65 60 66 typedef bool_t xhtab_compare_t( xptr_t entry_xp , void * key , xptr_t * item_xp ); 61 typedef xptr_t xhtab_scan_t( xptr_t xhtab_xp , uint32_t index , void * key ); 62 67 63 typedef uint32_t xhtab_index_t( void * key ); 68 64 … … 73 69 typedef enum 74 70 { 75 XHTAB_DENTRY_TYPE = 1, /*! item is a vfs_dentry_t */ 76 XHTAB_INODE_TYPE = 2, /*! item is a vfs_inode_t */ 71 XHTAB_DENTRY_TYPE = 0, /*! item is a vfs_dentry_t */ 77 72 } 78 73 xhtab_item_type_t; 79 74 80 75 /****************************************************************************************** 81 * This structure define the root of a generic, remote accessible,hash table.76 * This structure define the root of the remote accessible hash table. 82 77 *****************************************************************************************/ 83 78 … … 85 80 { 86 81 xlist_entry_t roots[HASHTAB_SIZE]; /*! array of roots of xlist */ 87 xhtab_ compare_t * compare; /*! item specific index function*/88 xhtab_ index_t * index; /*! item specific compare function*/82 xhtab_index_t * index; /*! item specific function */ 83 xhtab_scan_t * scan; /*! item specific function */ 89 84 uint32_t items; /*! number of registered items */ 90 remote_rwlock_t lock; /*! lock protecting hash table modifs*/85 remote_rwlock_t lock; /*! lock protecting hash table accesses */ 91 86 } 92 87 xhtab_t; 93 88 94 89 /****************************************************************************************** 95 * This function initializes an empty hash table (zero children).90 * This function initializes an empty hash table (zero registered item). 96 91 * The initialisation must be done by a thread running in cluster containing the table. 97 92 ****************************************************************************************** … … 99 94 * @ type : item type (see above). 100 95 *****************************************************************************************/ 101 void xhtab_init( xhtab_t * xhtab,102 uint32_ttype );96 void xhtab_init( xhtab_t * xhtab, 97 xhtab_item_type_t type ); 103 98 104 99 /****************************************************************************************** … … 108 103 * @ key : local pointer on item identifier. 109 104 * @ xlist_xp : extended pointer on xlist_entry_t embedded in item to be registered. 105 * @ return 0 if success / return EINVAL if item already registered. 110 106 *****************************************************************************************/ 111 void xhtab_register( xptr_t xhtab_xp,112 void * key,113 xptr_t xlist_xp );107 error_t xhtab_insert( xptr_t xhtab_xp, 108 void * key, 109 xptr_t xlist_xp ); 114 110 115 111 /****************************************************************************************** 116 112 * This function safely remove an item from the hash table, using the lock protecting it. 117 113 ****************************************************************************************** 118 * @ xhtab_xp : extended pointer on hash table. 119 * @ key : local pointer on item identifier. 114 * @ xhtab_xp : extended pointer on hash table. 115 * @ key : local pointer on item identifier. 116 * @ xlist_entry_xp : extended pointer on xlist_entry embedded in item to be removed. 117 * @ return 0 if success / return EINVAL if item not found. 120 118 *****************************************************************************************/ 121 void xhtab_remove( xptr_t xhtab_xp, 122 void * key ); 119 error_t xhtab_remove( xptr_t xhtab_xp, 120 void * key, 121 xptr_t xlist_entry_xp ); 123 122 124 123 /****************************************************************************************** … … 133 132 134 133 135 /************************ vfs_dentry_t specific functions ******************************/136 137 /******************************************************************************************138 * This function compute the hash index from the key, when the item is a vhs_dentry_t.139 ******************************************************************************************140 * @ key : local pointer on dentry name.141 * @ return the index value, from 0 to (HASHTAB_SIZE - 1)142 *****************************************************************************************/143 uint32_t xhtab_dentry_index( void * key );144 145 /******************************************************************************************146 * This function check the key value for a given item, when the item is a vhs_dentry_t.147 ******************************************************************************************148 * @ xlist_xp : extended pointer on xlist_entry_t contained in a vfs_dentry_t.149 * @ key : local pointer on searched dentry name.150 * @ return true if the item name matches the searched name.151 *****************************************************************************************/152 bool_t xhtab_dentry_compare( xptr_t xlist_xp,153 void * key,154 xptr_t * item_xp );155 156 157 /************************ vfs_inode_t specific functions *******************************/158 159 /******************************************************************************************160 * This function compute the hash index from the key, when the item is a vhs_inode_t.161 ******************************************************************************************162 * @ key : local pointer on dentry name.163 * @ return the index value, from 0 to (HASHTAB_SIZE - 1)164 *****************************************************************************************/165 uint32_t xhtab_inode_index( void * key );166 167 /******************************************************************************************168 * This function check the key value for a given item, when the item is a vhs_inode_t.169 ******************************************************************************************170 * @ xlist_xp : extended pointer on xlist_entry_t contained in a vfs_dentry_t.171 * @ key : local pointer on searched dentry name.172 * @ return true if the item name matches the searched name.173 *****************************************************************************************/174 bool_t xhtab_inode_compare( xptr_t xlist_xp,175 void * key,176 xptr_t * item_xp );177 178 134 #endif /* _XHTAB_H_ */
Note: See TracChangeset
for help on using the changeset viewer.