Exemplo n.º 1
0
int HashDelete(HashTable ht, void *data)
/* Removes the record containing 'data' from ht. If no such record exists, 
   hashDelete returns 0. On success it returns 1. DOES NOT DESTROY DATA */
{
  int retval=0;
  HashInfoPtr tmp;
  unsigned int hashval = ht->calcIndx(data)%ht->size; 

  ErrPushFunc("HashDelete");
  if(ht->infoArray[hashval]!=NULL) {
    if(!(ht->compData(ht->infoArray[hashval]->data, data))) {
      HashInfoPtr toTrash;             /*First record matched -- remove it! */
      toTrash=ht->infoArray[hashval];
      ht->infoArray[hashval]=toTrash->next;
#if defined (_POSIX_SEMAPHORES) && defined (_POSIX_THREADS)
      {
        int error = sem_destroy(&(toTrash->cursorListSemaphore));
        if (error != 0)
          perror("hash.c HashDelete sem_destroy");
      }
#endif
      free(toTrash);
      ht->elementCount--;
      assert( ht->elementCount >= 0 );
      retval=1;
    }
    else {
      for( tmp = ht->infoArray[hashval];      /* Continue search for match */
           (tmp->next!=NULL) && (ht->compData(tmp->next->data, data));
           tmp = tmp->next)
        ;

      if(tmp->next!=NULL) {      /* If found, remove the matching record. */
        HashInfoPtr toTrash;
        toTrash = tmp->next;
        tmp->next = toTrash->next;
#if defined (_POSIX_SEMAPHORES) && defined (_POSIX_THREADS)
        {
          int error = sem_destroy(&(toTrash->cursorListSemaphore));
          if (error != 0)
            perror("hash.c HashDelete sem_destroy");
        }
#endif
        free(toTrash);
        ht->elementCount--;
        assert( ht->elementCount >= 0 );

        retval=1;
      }
    }
  }
  ErrPopFunc();
  return(retval);
}
Exemplo n.º 2
0
int HashDestroy(HashTable ht, void *data)
/* Removes the record containing 'data' from ht and DESTROYS data. 
   If no such record exists, it returns 0. On success 1 is returned. */
{
  int retval=0;
  HashInfoPtr tmp;
  unsigned int hashval = ht->calcIndx(data)%ht->size; 

  ErrPushFunc("HashDestroy");
  if(ht->infoArray[hashval]!=NULL) {
    if(!(ht->compData(ht->infoArray[hashval]->data, data))) {
      HashInfoPtr toTrash;             /*First record matched -- remove it! */
      toTrash=ht->infoArray[hashval];
      ht->infoArray[hashval]=toTrash->next;
      DestroyInfo(ht, toTrash);
      ht->elementCount--;

      assert( ht->elementCount >= 0 );

      retval=1;
    }
    else {
      for( tmp = ht->infoArray[hashval];      /* Continue search for match */
           (tmp->next!=NULL) && (ht->compData(tmp->next->data, data));
           tmp = tmp->next )
        ;

      if(tmp->next!=NULL) {      /* If found, remove the matching record. */
        HashInfoPtr toTrash;
        toTrash = tmp->next;
        tmp->next = toTrash->next;
        DestroyInfo(ht, toTrash);
        ht->elementCount--;
        assert( ht->elementCount >= 0 );
        retval=1;
      }
    }
  }
  ErrPopFunc();
  return(retval);
}
Exemplo n.º 3
0
/* Returns the record containing the specified data, NULL if not found */
static HashInfoPtr FindInfo(HashTable ht, void *data, unsigned int hashval)
{ 
  HashInfoPtr tmp;

/*  #warning "ErrPushFunc disabled for debugging" */
/*    ErrPushFunc("FindInfo"); */

  for( tmp=ht->infoArray[hashval]; 
       (tmp!=NULL) && (ht->compData(data, tmp->data)); 
       tmp=tmp->next)
    ;

/*    ErrPopFunc(); */
  return(tmp);
}