/* resize table */ HB_HASH_TABLE_PTR hb_hashTableResize( HB_HASH_TABLE_PTR pTable, HB_SIZE ulNewSize ) { HB_HASH_TABLE_PTR pNew; ULONG ulSize = 0; if( ulNewSize == 0 ) ulNewSize = 2 * pTable->ulTableSize + 1; pNew = hb_hashTableCreate( ulNewSize, pTable->pKeyFunc, pTable->pDeleteItemFunc, pTable->pCompFunc ); while( ulSize < pTable->ulTableSize ) { if( pTable->pItems[ ulSize ] ) { PHB_HASH_ITEM pItem; pItem = pTable->pItems[ ulSize ]; while( pItem ) { HB_SIZE ulKey; PHB_HASH_ITEM pNewItem, pNext; pNext = pItem->next; ulKey = ( pTable->pKeyFunc )( pItem->cargo, NULL ); pNewItem = pNew->pItems[ ulKey ]; if( pNewItem ) { while( pNewItem->next ) pNewItem = pNewItem->next; pNewItem->next = pItem; } else { pNew->pItems[ ulKey ] = pItem; ++pNew->ulUsed; } pItem->key = ulKey; pItem->next = NULL; ++pNew->ulCount; pItem = pNext; } } ++ulSize; } hb_xfree( ( void * ) pTable->pItems ); hb_xfree( ( void * ) pTable ); return pNew; }
/* resize table */ HB_HASH_TABLE_PTR hb_hashTableResize( HB_HASH_TABLE_PTR pTable, HB_SIZE nNewSize ) { HB_HASH_TABLE_PTR pNew; HB_SIZE nSize = 0; if( nNewSize == 0 ) nNewSize = 2 * pTable->nTableSize + 1; pNew = hb_hashTableCreate( nNewSize, pTable->pKeyFunc, pTable->pDeleteItemFunc, pTable->pCompFunc ); while( nSize < pTable->nTableSize ) { if( pTable->pItems[ nSize ] ) { HB_HASH_ITEM_PTR pItem; pItem = pTable->pItems[ nSize ]; while( pItem ) { HB_SIZE nKey; HB_HASH_ITEM_PTR pNewItem, pNext; pNext = pItem->next; nKey = ( pTable->pKeyFunc )( pNew, pItem->KeyPtr, pItem->ValPtr ); pNewItem = pNew->pItems[ nKey ]; if( pNewItem ) { while( pNewItem->next ) pNewItem = pNewItem->next; pNewItem->next = pItem; } else { pNew->pItems[ nKey ] = pItem; ++pNew->nUsed; } pItem->key = nKey; pItem->next = NULL; ++pNew->nCount; pItem = pNext; } } ++nSize; } hb_xfree( pTable->pItems ); hb_xfree( pTable ); return pNew; }
/* initialize the hash table for identifiers */ void hb_compIdentifierOpen( HB_COMP_DECL ) { HB_COMP_PARAM->pIdentifiers = hb_hashTableCreate( HB_IDENT_TABLE_SIZE, hb_comp_IdentKey, hb_comp_IdentDel, hb_comp_IdentComp ); }