Example #1
0
void insert_table(hash_t *h, char *key, char *value) {

	// Compute hash value of key. 
	long hash_val = hash_f(key, (*h)->size); 

	// Create the new pair
	struct element* new_node = new_pair(key, value); 

	// Create pointer to traverse the linked list 
	struct element* temp = (*h)->entries[hash_val]; 

	// If there's no entry already 
	if (temp == NULL) {
		new_node->next = temp; 
		(*h)->entries[hash_val] = new_node; 
		printf("1\n"); 
	}
	/*
	else {
		while (temp != NULL) {
			temp = temp->next; 
		}
		temp->next = new_node; 
		h->entries[hash_val] = temp;
	}
	*/
}
Example #2
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));
  }
}
Example #3
0
char *find_pair(hash_t h, char *key) {

	long hash_val = hash_f(key, h->size); 
	struct element* pair = h->entries[hash_val]; 

	while (pair != NULL && !strcmp(pair->key, key)) {
		pair = pair->next; 
	}

	if (pair == NULL) {
		return NULL; 
	}
	else {
		return pair->value; 
	}
}
Example #4
0
int hash_add (char *x)   /* returns 1 if x already was in the hash */ 
{
  unsigned int hashval;
  
  hashval=hash_f(x);
  while (hashtab[hashval].word){
    if (strcmp(x,hashtab[hashval].word)==0) {
      hashtab[hashval].count++;;
      return 1;
    }
    hashval = ((hashval+1) & (HASHSIZE));
    collisions++;
  }
  hashtab[hashval].word = strdup(x);
  hashtab[hashval].count = 1;
  return 0;
}
Example #5
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;
}
Example #6
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;
}
Example #7
0
DecoratedPosition::DecoratedPosition(const Position * const position, const std::string * const move_str, const int score)
	: position_(const_cast<Position *>(position)),
	  hash_(hash_f(position_)),
	  move_str_(const_cast<std::string *>(move_str)),
	  score_(score) {}