Beispiel #1
0
/* Delete an item from the table
 * Returns TRUE if item was found and returns FALSE when passed item
 * is not stored in the table
 */
BOOL hb_hashTableDel( HB_HASH_TABLE_PTR pTable, void * pValue )
{
   HB_SIZE           ulKey;
   PHB_HASH_ITEM  pItem;
   PHB_HASH_ITEM  pPrev    = NULL;
   BOOL           bFound   = FALSE;

   ulKey = ( pTable->pKeyFunc )( pValue, NULL );
   pItem = pTable->pItems[ ulKey ];
   while( pItem && ! bFound )
   {
      if( ( pTable->pCompFunc )( pItem->cargo, pValue ) == 0 )
      {
         if( pPrev )
            pPrev->next = pItem->next;
         else
         {
            pTable->pItems[ ulKey ] = pItem->next;
            if( ! pItem->next )
               --pTable->ulUsed;
         }

         hb_hashItemDelete( pItem );
         bFound = TRUE;
         --pTable->ulCount;
      }
      else
      {
         pPrev = pItem;
         pItem = pItem->next;
      }
   }

   return bFound;
}
Beispiel #2
0
/* Delete an item from the table
 * Returns HB_TRUE if item was found and returns HB_FALSE when passed item
 * is not stored in the table
 */
HB_BOOL hb_hashTableDel( HB_HASH_TABLE_PTR pTable, const void * pKey )
{
   HB_SIZE nKey;
   HB_HASH_ITEM_PTR pItem;
   HB_HASH_ITEM_PTR pPrev = NULL;
   HB_BOOL bFound = HB_FALSE;

   nKey = ( pTable->pKeyFunc )( pTable, pKey, NULL );
   if( nKey > pTable->nTableSize )
      return HB_FALSE;

   pItem = pTable->pItems[ nKey ];
   while( pItem && ! bFound )
   {
      if( ( pTable->pCompFunc )( pTable, pItem->KeyPtr, pKey ) == 0 )
      {
         if( pPrev )
         {
            pPrev->next = pItem->next;
         }
         else
         {
            pTable->pItems[ nKey ] = pItem->next;
            if( ! pItem->next )
            {
               --pTable->nUsed;
               pTable->pItems[ nKey ] = NULL;
            }
         }
         --pTable->nCount;
         hb_hashItemDelete( pTable, pItem );
         bFound = HB_TRUE;
      }
      else
      {
         pPrev = pItem;
         pItem = pItem->next;
      }
   }

   return bFound;
}
Beispiel #3
0
/* Delete all items in the hash table and next delete the table
 */
void hb_hashTableKill( HB_HASH_TABLE_PTR pTable )
{
   HB_SIZE nSize = 0;

   while( nSize < pTable->nTableSize )
   {
      if( pTable->pItems[ nSize ] )
      {
         HB_HASH_ITEM_PTR pItem, pFree;
         pItem = pTable->pItems[ nSize ];
         while( pItem )
         {
            pFree = pItem;
            pItem = pItem->next;
            hb_hashItemDelete( pTable, pFree );
         }
      }
      ++nSize;
   }
   hb_xfree( pTable->pItems );
   hb_xfree( pTable );
}