Beispiel #1
0
PUBLIC void delete_hash (void *x)  /* doesn't work in case of collsions */
{                                  /* doesn't free anything ! */
  unsigned int hashval;
  
  hashval=hash_f(x);
  while (hashtab[hashval]){
    if (hash_comp(x,hashtab[hashval])==0) {
      hashtab[hashval]=NULL;
      return;
    }
    hashval = ((hashval+1) & (HASHSIZE));
  }
}
Beispiel #2
0
PUBLIC void * lookup_hash (void *x)  /* returns NULL unless x is in the hash */ 
{ 
  unsigned int hashval;

  hashval=hash_f(x);
/* xtof poset debug ! */
#ifdef _DEBUG_HASH_
  fprintf(stderr,
	  "lookup %s => %d\n",
	  ((hash_entry *)x)->structure,
	  hashval);
#endif
  if (hashtab[hashval]==NULL) return NULL; 
  while (hashtab[hashval]){
    if (hash_comp(x,hashtab[hashval])==0) return hashtab[hashval];
    hashval = ((hashval+1) & (HASHSIZE));
  }
  return NULL;
}
Beispiel #3
0
PUBLIC int write_hash (void *x)   /* returns 1 if x already was in the hash */ 
{
  unsigned int hashval;
  
  hashval=hash_f(x);
#ifdef _DEBUG_HASH_
  fprintf(stderr,
	  "write  %s => %d\n",
	  ((hash_entry *)x)->structure,
	  hashval);
#endif
  while (hashtab[hashval]){
    if (hash_comp(x,hashtab[hashval])==0) return 1;
    hashval = ((hashval+1) & (HASHSIZE));
    collisions++;
  }
  hashtab[hashval]=x;
  return 0;
}
Beispiel #4
0
void	*_hashtable_lookup(void **hash,
			   void *key,
			   unsigned int m,
			   hashing_function_p hash_func,
			   hashing_compare_p hash_comp)
{
  uint64_t   hki;
  void	*it;

  if (!hash || !key || !hash_func || !hash_comp)
    return (NULL);
  hki = hash_func(key);
  it = hash[hki];
  while (it)
    {
      if ((hash_comp(key, it)) == 0)
	break;
      it = GET_FIELD(it, m, hashtable_t)->next;
    }
  return (it);
}