All pastes #912031 Raw Edit

tomasso

public text v1 · immutable
·published 2008-02-21 02:06 UTC
rendered paste body

struct Hashtable {
  char **value;
  long size;
  int collision;
};

void init(struct Hashtable *h, long size);
void insert(struct Hashtable *h,char *str);
char* valueAt(struct Hashtable *h,int pos);



int isMoreOrLessPrime(long x){
  if ( (x % 2)==0 || (x % 3)==0 || (x % 5)==0 ) {
    return -1;
  } else {
    return 0;
  }
}



int closestPrimeNumber(long x){
  while (isMoreOrLessPrime(x) == -1){
   x = x + 1;
  }
  return x;
}


void init(struct Hashtable *h, long size){
  h = malloc(sizeof(h));
  h->size = closestPrimeNumber(size);
  h->value = malloc(sizeof(char **)*(long)h->size);
  char *currentElement = *((char **)(h->value));
  int j;
  for (j=1;j<h->size;j++){
    currentElement = currentElement + (sizeof(char **)*j);
    currentElement = NULL;
  }

}