{
nir_register *reg = ralloc(mem_ctx, nir_register);
- reg->uses = _mesa_set_create(mem_ctx, _mesa_key_pointer_equal);
- reg->defs = _mesa_set_create(mem_ctx, _mesa_key_pointer_equal);
- reg->if_uses = _mesa_set_create(mem_ctx, _mesa_key_pointer_equal);
+ reg->uses = _mesa_set_create(mem_ctx, _mesa_hash_pointer,
+ _mesa_key_pointer_equal);
+ reg->defs = _mesa_set_create(mem_ctx, _mesa_hash_pointer,
+ _mesa_key_pointer_equal);
+ reg->if_uses = _mesa_set_create(mem_ctx, _mesa_hash_pointer,
+ _mesa_key_pointer_equal);
reg->num_components = 0;
reg->num_array_elems = 0;
static inline void
block_add_pred(nir_block *block, nir_block *pred)
{
- _mesa_set_add(block->predecessors, _mesa_hash_pointer(pred), pred);
+ _mesa_set_add(block->predecessors, pred);
}
static void
pred->successors[1] = NULL;
}
- struct set_entry *entry = _mesa_set_search(succ->predecessors,
- _mesa_hash_pointer(pred), pred);
+ struct set_entry *entry = _mesa_set_search(succ->predecessors, pred);
assert(entry);
cf_init(&block->cf_node, nir_cf_node_block);
block->successors[0] = block->successors[1] = NULL;
- block->predecessors = _mesa_set_create(mem_ctx, _mesa_key_pointer_equal);
+ block->predecessors = _mesa_set_create(mem_ctx, _mesa_hash_pointer,
+ _mesa_key_pointer_equal);
block->imm_dom = NULL;
- block->dom_frontier = _mesa_set_create(mem_ctx, _mesa_key_pointer_equal);
+ block->dom_frontier = _mesa_set_create(mem_ctx, _mesa_hash_pointer,
+ _mesa_key_pointer_equal);
exec_list_make_empty(&block->instr_list);
if_stmt->condition.ssa->if_uses :
if_stmt->condition.reg.reg->uses;
- _mesa_set_add(if_uses_set, _mesa_hash_pointer(if_stmt), if_stmt);
+ _mesa_set_add(if_uses_set, if_stmt);
}
void
struct set *uses_set = src->is_ssa ? src->ssa->uses : src->reg.reg->uses;
- _mesa_set_add(uses_set, _mesa_hash_pointer(instr), instr);
+ _mesa_set_add(uses_set, instr);
return true;
}
nir_instr *instr = (nir_instr *) state;
if (!dest->is_ssa)
- _mesa_set_add(dest->reg.reg->defs, _mesa_hash_pointer(instr), instr);
+ _mesa_set_add(dest->reg.reg->defs, instr);
return true;
}
struct set *uses_set = src->is_ssa ? src->ssa->uses : src->reg.reg->uses;
- struct set_entry *entry = _mesa_set_search(uses_set,
- _mesa_hash_pointer(instr),
- instr);
+ struct set_entry *entry = _mesa_set_search(uses_set, instr);
if (entry)
_mesa_set_remove(uses_set, entry);
nir_register *reg = dest->reg.reg;
- struct set_entry *entry = _mesa_set_search(reg->defs,
- _mesa_hash_pointer(instr),
- instr);
+ struct set_entry *entry = _mesa_set_search(reg->defs, instr);
if (entry)
_mesa_set_remove(reg->defs, entry);
nir_ssa_def *old_ssa = src->ssa;
*src = new_src;
if (old_ssa && nir_foreach_src(instr, src_does_not_use_def, old_ssa)) {
- struct set_entry *entry = _mesa_set_search(old_ssa->uses,
- _mesa_hash_pointer(instr),
- instr);
+ struct set_entry *entry = _mesa_set_search(old_ssa->uses, instr);
assert(entry);
_mesa_set_remove(old_ssa->uses, entry);
}
nir_register *old_reg = src->reg.reg;
*src = new_src;
if (old_reg && nir_foreach_src(instr, src_does_not_use_reg, old_reg)) {
- struct set_entry *entry = _mesa_set_search(old_reg->uses,
- _mesa_hash_pointer(instr),
- instr);
+ struct set_entry *entry = _mesa_set_search(old_reg->uses, instr);
assert(entry);
_mesa_set_remove(old_reg->uses, entry);
}
if (new_src.is_ssa) {
if (new_src.ssa)
- _mesa_set_add(new_src.ssa->uses, _mesa_hash_pointer(instr), instr);
+ _mesa_set_add(new_src.ssa->uses, instr);
} else {
if (new_src.reg.reg)
- _mesa_set_add(new_src.reg.reg->uses, _mesa_hash_pointer(instr), instr);
+ _mesa_set_add(new_src.reg.reg->uses, instr);
}
}
def->name = name;
def->parent_instr = instr;
- def->uses = _mesa_set_create(mem_ctx, _mesa_key_pointer_equal);
- def->if_uses = _mesa_set_create(mem_ctx, _mesa_key_pointer_equal);
+ def->uses = _mesa_set_create(mem_ctx, _mesa_hash_pointer,
+ _mesa_key_pointer_equal);
+ def->if_uses = _mesa_set_create(mem_ctx, _mesa_hash_pointer,
+ _mesa_key_pointer_equal);
def->num_components = num_components;
if (instr->block) {
_mesa_set_remove(def->uses, entry);
nir_foreach_src(instr, ssa_def_rewrite_uses_src, &state);
- _mesa_set_add(new_uses, _mesa_hash_pointer(instr), instr);
+ _mesa_set_add(new_uses, instr);
}
set_foreach(def->if_uses, entry) {
_mesa_set_remove(def->if_uses, entry);
if_use->condition = nir_src_copy(new_src, mem_ctx);
- _mesa_set_add(new_if_uses, _mesa_hash_pointer(if_use), if_use);
+ _mesa_set_add(new_if_uses, if_use);
}
}
set_foreach(block->predecessors, entry) {
nir_block *runner = (nir_block *) entry->key;
while (runner != block->imm_dom) {
- _mesa_set_add(runner->dom_frontier, _mesa_hash_pointer(block),
- block);
+ _mesa_set_add(runner->dom_frontier, block);
runner = runner->imm_dom;
}
}
exec_list_push_tail(&pcopy->entries, &entry->node);
entry->src = nir_src_copy(src->src, state->dead_ctx);
- _mesa_set_add(src->src.ssa->uses,
- _mesa_hash_pointer(&pcopy->instr), &pcopy->instr);
+ _mesa_set_add(src->src.ssa->uses, &pcopy->instr);
entry->dest.is_ssa = true;
nir_ssa_def_init(&pcopy->instr, &entry->dest.ssa,
phi->dest.ssa.num_components, src->src.ssa->name);
struct set_entry *use_entry =
- _mesa_set_search(src->src.ssa->uses,
- _mesa_hash_pointer(instr), instr);
+ _mesa_set_search(src->src.ssa->uses, instr);
if (use_entry)
/* It is possible that a phi node can use the same source twice
* but for different basic blocks. If that happens, entry will
_mesa_set_remove(src->src.ssa->uses, use_entry);
src->src.ssa = &entry->dest.ssa;
- _mesa_set_add(entry->dest.ssa.uses, _mesa_hash_pointer(instr), instr);
+ _mesa_set_add(entry->dest.ssa.uses, instr);
}
nir_parallel_copy_entry *entry = ralloc(state->dead_ctx,
entry->src.is_ssa = true;
entry->src.ssa = &phi->dest.ssa;
- _mesa_set_add(phi->dest.ssa.uses,
- _mesa_hash_pointer(&block_pcopy->instr),
- &block_pcopy->instr);
+ _mesa_set_add(phi->dest.ssa.uses, &block_pcopy->instr);
}
return true;
/* We don't need to remove it from the uses set because that is going
* away. We just need to add it to the one for the register. */
- _mesa_set_add(reg->uses, _mesa_hash_pointer(state->instr), state->instr);
+ _mesa_set_add(reg->uses, state->instr);
}
return true;
memset(dest, 0, sizeof *dest);
dest->reg.reg = reg;
- _mesa_set_add(reg->defs, _mesa_hash_pointer(state->instr), state->instr);
+ _mesa_set_add(reg->defs, state->instr);
}
return true;
memset(&following_if->condition, 0, sizeof following_if->condition);
following_if->condition.reg.reg = reg;
- _mesa_set_add(reg->if_uses, _mesa_hash_pointer(following_if),
- following_if);
+ _mesa_set_add(reg->if_uses, following_if);
} else {
/* FIXME: We really shouldn't hit this. We should be doing
* constant control flow propagation.
return;
if (node->loads == NULL)
- node->loads = _mesa_set_create(state->dead_ctx,
+ node->loads = _mesa_set_create(state->dead_ctx, _mesa_hash_pointer,
_mesa_key_pointer_equal);
- _mesa_set_add(node->loads, _mesa_hash_pointer(load_instr), load_instr);
+ _mesa_set_add(node->loads, load_instr);
}
static void
return;
if (node->stores == NULL)
- node->stores = _mesa_set_create(state->dead_ctx,
+ node->stores = _mesa_set_create(state->dead_ctx, _mesa_hash_pointer,
_mesa_key_pointer_equal);
- _mesa_set_add(node->stores, _mesa_hash_pointer(store_instr), store_instr);
+ _mesa_set_add(node->stores, store_instr);
}
static void
continue;
if (node->copies == NULL)
- node->copies = _mesa_set_create(state->dead_ctx,
+ node->copies = _mesa_set_create(state->dead_ctx, _mesa_hash_pointer,
_mesa_key_pointer_equal);
- _mesa_set_add(node->copies, _mesa_hash_pointer(copy_instr), copy_instr);
+ _mesa_set_add(node->copies, copy_instr);
}
}
if (arg_node == NULL)
continue;
- struct set_entry *arg_entry = _mesa_set_search(arg_node->copies,
- copy_entry->hash,
- copy);
+ struct set_entry *arg_entry = _mesa_set_search(arg_node->copies, copy);
assert(arg_entry);
_mesa_set_remove(node->copies, arg_entry);
}
src->src.is_ssa = true;
src->src.ssa = get_ssa_def_for_block(node, pred, state);
- _mesa_set_add(src->src.ssa->uses, _mesa_hash_pointer(instr), instr);
+ _mesa_set_add(src->src.ssa->uses, instr);
exec_list_push_tail(&phi->srcs, &src->node);
}
nir_foreach_block(impl, register_variable_uses_block, &state);
struct set *outputs = _mesa_set_create(state.dead_ctx,
+ _mesa_hash_pointer,
_mesa_key_pointer_equal);
bool progress = false;
}
if (deref->var->data.mode == nir_var_shader_out)
- _mesa_set_add(outputs, _mesa_hash_pointer(node), node);
+ _mesa_set_add(outputs, node);
foreach_deref_node_match(deref, lower_copies_to_load_store, &state);
}
search_state.found = false;
nir_foreach_src(parent_instr, search_def, &search_state);
if (!search_state.found) {
- struct set_entry *entry =
- _mesa_set_search(old_def->uses, _mesa_hash_pointer(parent_instr),
- parent_instr);
+ struct set_entry *entry = _mesa_set_search(old_def->uses, parent_instr);
assert(entry);
_mesa_set_remove(old_def->uses, entry);
}
- _mesa_set_add(new_def->uses, _mesa_hash_pointer(parent_instr),
- parent_instr);
+ _mesa_set_add(new_def->uses, parent_instr);
}
static void
if_stmt->condition.ssa = new_def;
- struct set_entry *entry =
- _mesa_set_search(old_def->if_uses, _mesa_hash_pointer(if_stmt), if_stmt);
+ struct set_entry *entry = _mesa_set_search(old_def->if_uses, if_stmt);
assert(entry);
_mesa_set_remove(old_def->if_uses, entry);
- _mesa_set_add(new_def->if_uses, _mesa_hash_pointer(if_stmt), if_stmt);
+ _mesa_set_add(new_def->if_uses, if_stmt);
}
static bool
glsl_print_type(var->type, fp);
- struct set_entry *entry =
- _mesa_set_search(state->syms, _mesa_hash_string(var->name), var->name);
+ struct set_entry *entry = _mesa_set_search(state->syms, var->name);
char *name;
fprintf(fp, "\n");
- _mesa_set_add(state->syms, _mesa_hash_string(name), name);
+ _mesa_set_add(state->syms, name);
_mesa_hash_table_insert(state->ht, var, name);
}
{
state->ht = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
_mesa_key_pointer_equal);
- state->syms = _mesa_set_create(NULL, _mesa_key_string_equal);
+ state->syms = _mesa_set_create(NULL, _mesa_key_hash_string,
+ _mesa_key_string_equal);
state->index = 0;
}
unsigned num_vars = nir_intrinsic_infos[instr->intrinsic].num_variables;
for (unsigned i = 0; i < num_vars; i++) {
nir_variable *var = instr->variables[i]->var;
- _mesa_set_add(live, _mesa_hash_pointer(var), var);
+ _mesa_set_add(live, var);
}
}
{
if (instr->return_deref != NULL) {
nir_variable *var = instr->return_deref->var;
- _mesa_set_add(live, _mesa_hash_pointer(var), var);
+ _mesa_set_add(live, var);
}
for (unsigned i = 0; i < instr->num_params; i++) {
nir_variable *var = instr->params[i]->var;
- _mesa_set_add(live, _mesa_hash_pointer(var), var);
+ _mesa_set_add(live, var);
}
}
{
if (instr->sampler != NULL) {
nir_variable *var = instr->sampler->var;
- _mesa_set_add(live, _mesa_hash_pointer(var), var);
+ _mesa_set_add(live, var);
}
}
remove_dead_local_vars(nir_function_impl *impl, struct set *live)
{
foreach_list_typed_safe(nir_variable, var, node, &impl->locals) {
- struct set_entry *entry =
- _mesa_set_search(live, _mesa_hash_pointer(var), var);
+ struct set_entry *entry = _mesa_set_search(live, var);
if (entry == NULL)
exec_node_remove(&var->node);
}
remove_dead_global_vars(nir_shader *shader, struct set *live)
{
foreach_list_typed_safe(nir_variable, var, node, &shader->globals) {
- struct set_entry *entry =
- _mesa_set_search(live, _mesa_hash_pointer(var), var);
+ struct set_entry *entry = _mesa_set_search(live, var);
if (entry == NULL)
exec_node_remove(&var->node);
}
nir_remove_dead_variables(nir_shader *shader)
{
struct set *live =
- _mesa_set_create(NULL, _mesa_key_pointer_equal);
+ _mesa_set_create(NULL, _mesa_hash_pointer, _mesa_key_pointer_equal);
add_var_use_shader(shader, live);
src->ssa = get_ssa_src(src->reg.reg, state);
if (state->parent_instr)
- _mesa_set_add(src->ssa->uses, _mesa_hash_pointer(state->parent_instr),
- state->parent_instr);
+ _mesa_set_add(src->ssa->uses, state->parent_instr);
else
- _mesa_set_add(src->ssa->if_uses, _mesa_hash_pointer(state->parent_if),
- state->parent_if);
+ _mesa_set_add(src->ssa->if_uses, state->parent_if);
return true;
}
{
assert(src->reg != NULL);
- struct set_entry *entry =
- _mesa_set_search(src->reg->uses, _mesa_hash_pointer(state->instr),
- state->instr);
+ struct set_entry *entry = _mesa_set_search(src->reg->uses, state->instr);
assert(entry && "use not in nir_register.uses");
struct hash_entry *entry2;
assert(entry2);
reg_validate_state *reg_state = (reg_validate_state *) entry2->data;
- _mesa_set_add(reg_state->uses, _mesa_hash_pointer(state->instr),
- state->instr);
+ _mesa_set_add(reg_state->uses, state->instr);
if (!src->reg->is_global) {
assert(reg_state->where_defined == state->impl &&
struct set_entry *entry2;
- entry2 = _mesa_set_search(def->uses, _mesa_hash_pointer(state->instr),
- state->instr);
+ entry2 = _mesa_set_search(def->uses, state->instr);
assert(entry2 && "SSA use missing");
{
assert(dest->reg != NULL);
- struct set_entry *entry =
- _mesa_set_search(dest->reg->defs, _mesa_hash_pointer(state->instr),
- state->instr);
+ struct set_entry *entry = _mesa_set_search(dest->reg->defs, state->instr);
assert(entry && "definition not in nir_register.defs");
struct hash_entry *entry2;
assert(entry2);
reg_validate_state *reg_state = (reg_validate_state *) entry2->data;
- _mesa_set_add(reg_state->defs, _mesa_hash_pointer(state->instr),
- state->instr);
+ _mesa_set_add(reg_state->defs, state->instr);
if (!dest->reg->is_global) {
assert(reg_state->where_defined == state->impl &&
for (unsigned i = 0; i < 2; i++) {
if (block->successors[i] != NULL) {
struct set_entry *entry =
- _mesa_set_search(block->successors[i]->predecessors,
- _mesa_hash_pointer(block), block);
+ _mesa_set_search(block->successors[i]->predecessors, block);
assert(entry);
validate_phi_srcs(block, block->successors[i], state);
if (!if_stmt->condition.is_ssa) {
nir_register *reg = if_stmt->condition.reg.reg;
- struct set_entry *entry =
- _mesa_set_search(reg->if_uses, _mesa_hash_pointer(if_stmt), if_stmt);
+ struct set_entry *entry = _mesa_set_search(reg->if_uses, if_stmt);
assert(entry);
} else {
nir_ssa_def *def = if_stmt->condition.ssa;
- struct set_entry *entry =
- _mesa_set_search(def->if_uses, _mesa_hash_pointer(if_stmt), if_stmt);
+ struct set_entry *entry = _mesa_set_search(def->if_uses, if_stmt);
assert(entry);
}
BITSET_SET(state->regs_found, reg->index);
reg_validate_state *reg_state = ralloc(state->regs, reg_validate_state);
- reg_state->uses = _mesa_set_create(reg_state, _mesa_key_pointer_equal);
- reg_state->defs = _mesa_set_create(reg_state, _mesa_key_pointer_equal);
+ reg_state->uses = _mesa_set_create(reg_state, _mesa_hash_pointer,
+ _mesa_key_pointer_equal);
+ reg_state->defs = _mesa_set_create(reg_state, _mesa_hash_pointer,
+ _mesa_key_pointer_equal);
reg_state->where_defined = is_global ? NULL : state->impl;
struct set_entry *entry;
set_foreach(reg->uses, entry) {
struct set_entry *entry2 =
- _mesa_set_search(reg_state->uses, _mesa_hash_pointer(entry->key),
- entry->key);
+ _mesa_set_search(reg_state->uses, entry->key);
if (entry2 == NULL) {
printf("%p\n", entry->key);
struct set_entry *entry;
set_foreach(reg->defs, entry) {
struct set_entry *entry2 =
- _mesa_set_search(reg_state->defs, _mesa_hash_pointer(entry->key),
- entry->key);
+ _mesa_set_search(reg_state->defs, entry->key);
if (entry2 == NULL) {
printf("%p\n", entry->key);
void
brw_render_cache_set_add_bo(struct brw_context *brw, drm_intel_bo *bo)
{
- _mesa_set_add(brw->render_cache, _mesa_hash_pointer(bo), bo);
+ _mesa_set_add(brw->render_cache, bo);
}
/**
void
brw_render_cache_set_check_flush(struct brw_context *brw, drm_intel_bo *bo)
{
- if (!_mesa_set_search(brw->render_cache, _mesa_hash_pointer(bo), bo))
+ if (!_mesa_set_search(brw->render_cache, bo))
return;
intel_batchbuffer_emit_mi_flush(brw);
dd->EGLImageTargetRenderbufferStorage =
intel_image_target_renderbuffer_storage;
- brw->render_cache = _mesa_set_create(brw, _mesa_key_pointer_equal);
+ brw->render_cache = _mesa_set_create(brw, _mesa_hash_pointer,
+ _mesa_key_pointer_equal);
}
shared->FrameBuffers = _mesa_NewHashTable();
shared->RenderBuffers = _mesa_NewHashTable();
- shared->SyncObjects = _mesa_set_create(NULL, _mesa_key_pointer_equal);
+ shared->SyncObjects = _mesa_set_create(NULL, _mesa_hash_pointer,
+ _mesa_key_pointer_equal);
return shared;
}
const struct gl_sync_object *syncObj)
{
return (syncObj != NULL)
- && _mesa_set_search(ctx->Shared->SyncObjects,
- _mesa_hash_pointer(syncObj),
- syncObj) != NULL
+ && _mesa_set_search(ctx->Shared->SyncObjects, syncObj) != NULL
&& (syncObj->Type == GL_SYNC_FENCE)
&& !syncObj->DeletePending;
}
mtx_lock(&ctx->Shared->Mutex);
syncObj->RefCount--;
if (syncObj->RefCount == 0) {
- entry = _mesa_set_search(ctx->Shared->SyncObjects,
- _mesa_hash_pointer(syncObj),
- syncObj);
+ entry = _mesa_set_search(ctx->Shared->SyncObjects, syncObj);
assert (entry != NULL);
_mesa_set_remove(ctx->Shared->SyncObjects, entry);
mtx_unlock(&ctx->Shared->Mutex);
ctx->Driver.FenceSync(ctx, syncObj, condition, flags);
mtx_lock(&ctx->Shared->Mutex);
- _mesa_set_add(ctx->Shared->SyncObjects,
- _mesa_hash_pointer(syncObj),
- syncObj);
+ _mesa_set_add(ctx->Shared->SyncObjects, syncObj);
mtx_unlock(&ctx->Shared->Mutex);
return (GLsync) syncObj;
ctx->vdpDevice = vdpDevice;
ctx->vdpGetProcAddress = getProcAddress;
- ctx->vdpSurfaces = _mesa_set_create(NULL, _mesa_key_pointer_equal);
+ ctx->vdpSurfaces = _mesa_set_create(NULL, _mesa_hash_pointer,
+ _mesa_key_pointer_equal);
}
static void
_mesa_reference_texobj(&surf->textures[i], tex);
}
- _mesa_set_add(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf);
+ _mesa_set_add(ctx->vdpSurfaces, surf);
return (GLintptr)surf;
}
return false;
}
- if (!_mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf)) {
+ if (!_mesa_set_search(ctx->vdpSurfaces, surf)) {
return false;
}
if (surface == 0)
return;
- entry = _mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf);
+ entry = _mesa_set_search(ctx->vdpSurfaces, surf);
if (!entry) {
_mesa_error(ctx, GL_INVALID_VALUE, "VDPAUUnregisterSurfaceNV");
return;
return;
}
- if (!_mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf)) {
+ if (!_mesa_set_search(ctx->vdpSurfaces, surf)) {
_mesa_error(ctx, GL_INVALID_VALUE, "VDPAUGetSurfaceivNV");
return;
}
return;
}
- if (!_mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf)) {
+ if (!_mesa_set_search(ctx->vdpSurfaces, surf)) {
_mesa_error(ctx, GL_INVALID_VALUE, "VDPAUSurfaceAccessNV");
return;
}
for (i = 0; i < numSurfaces; ++i) {
struct vdp_surface *surf = (struct vdp_surface *)surfaces[i];
- if (!_mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf)) {
+ if (!_mesa_set_search(ctx->vdpSurfaces, surf)) {
_mesa_error(ctx, GL_INVALID_VALUE, "VDPAUSurfaceAccessNV");
return;
}
for (i = 0; i < numSurfaces; ++i) {
struct vdp_surface *surf = (struct vdp_surface *)surfaces[i];
- if (!_mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf)) {
+ if (!_mesa_set_search(ctx->vdpSurfaces, surf)) {
_mesa_error(ctx, GL_INVALID_VALUE, "VDPAUSurfaceAccessNV");
return;
}
*/
#include <stdlib.h>
+#include <assert.h>
#include "macros.h"
#include "ralloc.h"
struct set *
_mesa_set_create(void *mem_ctx,
+ uint32_t (*key_hash_function)(const void *key),
bool (*key_equals_function)(const void *a,
const void *b))
{
ht->size = hash_sizes[ht->size_index].size;
ht->rehash = hash_sizes[ht->size_index].rehash;
ht->max_entries = hash_sizes[ht->size_index].max_entries;
+ ht->key_hash_function = key_hash_function;
ht->key_equals_function = key_equals_function;
ht->table = rzalloc_array(ht, struct set_entry, ht->size);
ht->entries = 0;
*
* Returns NULL if no entry is found.
*/
-struct set_entry *
-_mesa_set_search(const struct set *ht, uint32_t hash, const void *key)
+static struct set_entry *
+set_search(const struct set *ht, uint32_t hash, const void *key)
{
uint32_t hash_address;
return NULL;
}
+struct set_entry *
+_mesa_set_search(const struct set *set, const void *key)
+{
+ assert(set->key_hash_function);
+ return set_search(set, set->key_hash_function(key), key);
+}
+
+struct set_entry *
+_mesa_set_search_pre_hashed(const struct set *set, uint32_t hash,
+ const void *key)
+{
+ assert(set->key_hash_function == NULL ||
+ hash == set->key_hash_function(key));
+ return set_search(set, hash, key);
+}
+
+static struct set_entry *
+set_add(struct set *ht, uint32_t hash, const void *key);
+
static void
set_rehash(struct set *ht, int new_size_index)
{
entry != old_ht.table + old_ht.size;
entry++) {
if (entry_is_present(entry)) {
- _mesa_set_add(ht, entry->hash, entry->key);
+ set_add(ht, entry->hash, entry->key);
}
}
* Note that insertion may rearrange the table on a resize or rehash,
* so previously found hash_entries are no longer valid after this function.
*/
-struct set_entry *
-_mesa_set_add(struct set *ht, uint32_t hash, const void *key)
+static struct set_entry *
+set_add(struct set *ht, uint32_t hash, const void *key)
{
uint32_t hash_address;
return NULL;
}
+struct set_entry *
+_mesa_set_add(struct set *set, const void *key)
+{
+ assert(set->key_hash_function);
+ return set_add(set, set->key_hash_function(key), key);
+}
+
+struct set_entry *
+_mesa_set_add_pre_hashed(struct set *set, uint32_t hash, const void *key)
+{
+ assert(set->key_hash_function == NULL ||
+ hash == set->key_hash_function(key));
+ return set_add(set, hash, key);
+}
+
/**
* This function deletes the given hash table entry.
*
struct set {
void *mem_ctx;
struct set_entry *table;
+ uint32_t (*key_hash_function)(const void *key);
bool (*key_equals_function)(const void *a, const void *b);
uint32_t size;
uint32_t rehash;
struct set *
_mesa_set_create(void *mem_ctx,
+ uint32_t (*key_hash_function)(const void *key),
bool (*key_equals_function)(const void *a,
const void *b));
void
void (*delete_function)(struct set_entry *entry));
struct set_entry *
-_mesa_set_add(struct set *set, uint32_t hash, const void *key);
+_mesa_set_add(struct set *set, const void *key);
+struct set_entry *
+_mesa_set_add_pre_hashed(struct set *set, uint32_t hash, const void *key);
struct set_entry *
-_mesa_set_search(const struct set *set, uint32_t hash,
- const void *key);
+_mesa_set_search(const struct set *set, const void *key);
+struct set_entry *
+_mesa_set_search_pre_hashed(const struct set *set, uint32_t hash,
+ const void *key);
void
_mesa_set_remove(struct set *set, struct set_entry *entry);