Beispiel #1
0
void
hash_table_put (struct hash_table *ht, const void *key, const void *value)
{
  struct cell *c = find_cell (ht, key);
  if (CELL_OCCUPIED (c))
    {
      /* update existing item */
      c->key   = (void *)key; /* const? */
      c->value = (void *)value;
      return;
    }

  /* If adding the item would make the table exceed max. fullness,
     grow the table first.  */
  if (ht->count >= ht->resize_threshold)
    {
      grow_hash_table (ht);
      c = find_cell (ht, key);
    }

  /* add new item */
  ++ht->count;
  c->key   = (void *)key;       /* const? */
  c->value = (void *)value;
}
Beispiel #2
0
void
hash_table_put (struct hash_table *ht, const void *key, void *value)
{
  struct mapping *mappings = ht->mappings;
  int size = ht->size;
  int (*equals) (const void *, const void *) = ht->test_function;

  struct mapping *mp = mappings + HASH_POSITION (ht, key);

  LOOP_NON_EMPTY (mp, mappings, size)
    if (equals (key, mp->key))
      {
	mp->key   = (void *)key; /* const? */
	mp->value = value;
	return;
      }

  ++ht->count;
  mp->key   = (void *)key;	/* const? */
  mp->value = value;

  if (ht->count > ht->resize_threshold)
    /* When table is 75% full, regrow it. */
    grow_hash_table (ht);
}
Beispiel #3
0
hash_info_t *
newentry()
{
	int	index;
	
	index = hash_table->head;

	++hash_table->head;

	if (hash_table->head == hash_table->tail) {
		if (grow_hash_table(HASH_TABLE_ENTRIES) != 0) {
			fprintf(stderr, "newentry:grow_hash_table:failed\n");
			return(NULL);
		}
	}

	if (hash_table->head == hash_table->size) {
		hash_table->head = 0;
	}

	return(&hash_table->entry[index]);
}