Changeset 610 for trunk/kernel/libk/htab.c
- Timestamp:
- Dec 27, 2018, 7:38:58 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/htab.c
r563 r610 34 34 /////////////////////////////////////////////////////////////////////////////////////////// 35 35 // Item type specific (static) functions (two functions for each item type). 36 // Example below if for <vhs_inode_t>, where the identifier is the inum field. 37 /////////////////////////////////////////////////////////////////////////////////////////// 38 39 /////////////////////////////////////////////////////////////////////////////////////////// 40 // These static functions compute the hash index from the key. 36 // Example below if for <bloup_t> type, where the identifier is an uint32_t field. 37 /////////////////////////////////////////////////////////////////////////////////////////// 38 39 typedef struct bloup_s 40 { 41 uint32_t key; 42 list_entry_t list; 43 } 44 bloup_t; 45 46 /////////////////////////////////////////////////////////////////////////////////////////// 47 // This static function computes the hash index from the key. 41 48 /////////////////////////////////////////////////////////////////////////////////////////// 42 49 // @ key : local pointer on key. 43 50 // @ return the index value, from 0 to (HASHTAB_SIZE - 1) 44 51 /////////////////////////////////////////////////////////////////////////////////////////// 45 static uint32_t htab_inode_index( void * key ) 46 { 47 uint32_t * inum = key; 48 return (((*inum) >> 16) ^ ((*inum) & 0xFFFF)) % HASHTAB_SIZE; 52 static uint32_t htab_bloup_index( void * key ) 53 { 54 return (*(uint32_t *)key) % HASHTAB_SIZE; 49 55 } 50 56 51 57 /////////////////////////////////////////////////////////////////////////////////////// 52 // Th ese static functions areused by htab_lookup(), htab_insert(), and htab_remove().58 // This static function is used by htab_lookup(), htab_insert(), and htab_remove(). 53 59 // They scan one sub-list identified by <index> to find an item identified by <key>. 54 60 // The sub-list is not modified, but the lock must have been taken by the caller. … … 59 65 // @ return pointer on item if found / return NULL if not found. 60 66 /////////////////////////////////////////////////////////////////////////////////////// 61 static void * htab_ inode_scan( htab_t * htab,67 static void * htab_bloup_scan( htab_t * htab, 62 68 uint32_t index, 63 69 void * key ) 64 70 { 65 71 list_entry_t * list_entry; // pointer on list_entry_t (iterator) 66 vfs_inode_t * inode; // pointer on item72 bloup_t * bloup; // pointer on item 67 73 68 74 LIST_FOREACH( &htab->roots[index] , list_entry ) 69 75 { 70 inode = (vfs_inode_t *)LIST_ELEMENT( list_entry , vfs_inode_t , list );71 if( inode->inum == *(uint32_t *)key ) return inode;76 bloup = (bloup_t *)LIST_ELEMENT( list_entry , bloup_t , list ); 77 if( bloup->key == *(uint32_t *)key ) return bloup; 72 78 } 73 79 … … 91 97 htab->items = 0; 92 98 93 if( type == HTAB_ INODE_TYPE )94 { 95 htab->scan = &htab_ inode_scan;96 htab->index = &htab_ inode_index;99 if( type == HTAB_BLOUP_TYPE ) 100 { 101 htab->scan = &htab_bloup_scan; 102 htab->index = &htab_bloup_index; 97 103 } 98 104 else
Note: See TracChangeset
for help on using the changeset viewer.