[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

hash two integers



Kære c-liste,

jeg har lavet en hash funktion, der tager to integers og hasher til en
integer. Jeg laver hver integer om til ascii og sætter dem sammen i et
array, jeg så gennemløber, når jeg hasher.

Problemet er at mit program går ned, når jeg forsøger at free() det array
jeg allokerer??? Hvis jeg udelader free() kører mit program, blot falder
hastigheden jo flere gange funktionen kaldes.

Hvad gør jeg forkert?

Er der nogen der har en smartere måde at hashe to integers på?

Funktionen er sådan ud:

int hash_two_integers(int i, int j, int hashtable_length){
  int h,k;
  k= h= 0;

  int* ij=  (int *) calloc(30, sizeof(t));

/*transform two integers into one ascii array in reverse order, seperated
by a  ascii-zero*/
  do{
    ij[k++]=  (i % 10 + '0');

  }while ((i /= 10) > 0);

  ij[k++]= 10 %10 + '0';

  do{
   ij[k++]=  (j % 10 + '0');

  }while ((j /= 10) > 0);


  /*hash ascii array ij*/

  while(*ij != 0){
    h= (256*h+*ij++) % hashtable_length;

  }

  free(ij) //medfører programmet krasher

  return h;
}


med venlig hilsen
Marie Louise





 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *