Exemple #1
0
int CHTBLremove(CHtbl htbl, void **data)
{
  int bucket, retval;

  /* Hash the key */
  bucket = htbl->h(*data) % htbl->buckets;

  /* Remove the node */
  if ((retval = SLISTfind_remove(htbl->table[bucket], data)) == 0) /* Node removal successful.. */
    htbl->size--;

  return retval;
}
Exemple #2
0
/* --- Function: void rem_nodes(Slist list) --- */
void rem_nodes(Slist list)
{
  int tmp, *pi, retval;
  char mess[BUFSIZ];

  do
    {
      my_clearscrn();
      printf("--- REMOVE NODE FROM LIST ---\n");
      printf("\nCurrent list status(%d nodes): ", SLISTsize(list));
      SLISTtraverse(list, print, SLIST_FWD);

      tmp = read_int("\nEnter keydata for node to be removed (-1=Quit): ", 0, 0);

      if (tmp == -1)
        break;

      /* Remove node - and free memory */
      pi = &tmp;

      if ((retval = SLISTfind_remove(list, (void **)&pi)) != OK)
        {
          if (retval == 1)
            {
              sprintf(mess, "Error: Node %d not found..!", tmp);
              prompt_and_pause(mess);
            }
          else 
            {
              if (retval == -2)
                printf("\nError: Match-callback is missing... - bailing out!");
              else
                printf("\nFatal error... - bailing out!");
              SLISTdestroy(list);
              exit(retval);
            }
        }
      else
        {
          /* Removal succesful - notify user.. */
          sprintf(mess, "Node %d will be removed..!", *(int *)pi);
          prompt_and_pause(mess);
          /* Free node - after being removed from list.. */
          my_destroy(pi);
        }
    } while (TRUE);
}