int main(int argc, char **argv) { struct hash_table *ht; struct hash_entry *entry; unsigned size = 10000; uint32_t keys[size]; uint32_t i; (void) argc; (void) argv; ht = _mesa_hash_table_create(NULL, key_value, uint32_t_key_equals); for (i = 0; i < size; i++) { keys[i] = i; _mesa_hash_table_insert(ht, keys + i, NULL); } for (i = 0; i < size; i++) { entry = _mesa_hash_table_search(ht, keys + i); assert(entry); assert(key_value(entry->key) == i); } assert(ht->entries == size); _mesa_hash_table_destroy(ht, NULL); return 0; }
void act( T& ref_, ValueT const& value_, ReferentT const& key_ ) const { typedef typename T::value_type value_type; value_type key_value(key_, value_); ref_.insert( key_value ); }
int main(int argc, char **argv) { struct hash_table *ht; struct hash_entry *entry; int size = 10000; uint32_t keys[size]; uint32_t i; ht = _mesa_hash_table_create(NULL, key_value, uint32_t_key_equals); for (i = 0; i < size; i++) { keys[i] = i; _mesa_hash_table_insert(ht, keys + i, NULL); if (i >= 100) { uint32_t delete_value = i - 100; entry = _mesa_hash_table_search(ht, &delete_value); _mesa_hash_table_remove(ht, entry); } } /* Make sure that all our entries were present at the end. */ for (i = size - 100; i < size; i++) { entry = _mesa_hash_table_search(ht, keys + i); assert(entry); assert(key_value(entry->key) == i); } /* Make sure that no extra entries got in */ for (entry = _mesa_hash_table_next_entry(ht, NULL); entry != NULL; entry = _mesa_hash_table_next_entry(ht, entry)) { assert(key_value(entry->key) >= size - 100 && key_value(entry->key) < size); } assert(ht->entries == 100); _mesa_hash_table_destroy(ht, NULL); return 0; }
int main(int argc, char **argv) { struct hash_table *ht; struct hash_entry *entry; uint32_t keys[SIZE]; uint32_t i, random_value; (void) argc; (void) argv; ht = _mesa_hash_table_create(NULL, key_value, uint32_t_key_equals); for (i = 0; i < SIZE; i++) { keys[i] = i; _mesa_hash_table_insert(ht, keys + i, NULL); } /* Test the no-predicate case. */ entry = _mesa_hash_table_random_entry(ht, NULL); assert(entry); /* Check that we're getting different entries and that the predicate * works. */ for (i = 0; i < 100; i++) { entry = _mesa_hash_table_random_entry(ht, uint32_t_key_is_even); assert(entry); assert((key_value(entry->key) & 1) == 0); if (i == 0 || key_value(entry->key) != random_value) break; random_value = key_value(entry->key); } assert(i != 100); _mesa_hash_table_destroy(ht, NULL); return 0; }
int main(int argc, char **argv) { struct set *set; struct set_entry *entry; int size = 10000; uint32_t keys[size]; uint32_t i, random_value; set = set_create(key_value, uint32_t_key_equals); for (i = 0; i < size; i++) { keys[i] = i; set_add(set, keys + i); } /* Test the no-predicate case. */ entry = set_random_entry(set, NULL); assert(entry); /* Check that we're getting different entries and that the predicate * works. */ for (i = 0; i < 100; i++) { entry = set_random_entry(set, uint32_t_key_is_even); assert(entry); assert((key_value(entry->key) & 1) == 0); if (i == 0 || key_value(entry->key) != random_value) break; random_value = key_value(entry->key); } assert(i != 100); set_destroy(set, NULL); return 0; }
void act( T& ref_, ValueT const& value_, IteratorT const& first_, IteratorT const& last_ ) const { typedef typename T::key_type key_type; typedef typename T::value_type value_type; key_type key(first_,last_); value_type key_value(key, value_); ref_.insert( key_value ); }
static bool uint32_t_key_is_even(struct hash_entry *entry) { return (key_value(entry->key) & 1) == 0; }
static bool uint32_t_key_equals(const void *a, const void *b) { return key_value(a) == key_value(b); }
static int uint32_t_key_is_even(struct set_entry *entry) { return (key_value(entry->key) & 1) == 0; }
/* This is defined so we can pass a value_tracker_t to something that expects an existence_tracker_t. */ bool key_exists(seed_t seed) { bool exists; key_value(seed, &exists, NULL); return exists; }