2008-03-13 10:19:23 +00:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
|
|
|
* Copyright 2008 VMware, Inc.
|
2008-03-13 10:19:23 +00:00
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) shall be included in all copies or substantial portions
|
|
|
|
* of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
|
|
|
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
|
2008-03-13 10:19:23 +00:00
|
|
|
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* General purpose hash table implementation.
|
|
|
|
*
|
|
|
|
* Just uses the cso_hash for now, but it might be better switch to a linear
|
|
|
|
* probing hash table implementation at some point -- as it is said they have
|
|
|
|
* better lookup and cache performance and it appears to be possible to write
|
|
|
|
* a lock-free implementation of such hash tables .
|
|
|
|
*
|
s/Tungsten Graphics/VMware/
Tungsten Graphics Inc. was acquired by VMware Inc. in 2008. Leaving the
old copyright name is creating unnecessary confusion, hence this change.
This was the sed script I used:
$ cat tg2vmw.sed
# Run as:
#
# git reset --hard HEAD && find include scons src -type f -not -name 'sed*' -print0 | xargs -0 sed -i -f tg2vmw.sed
#
# Rename copyrights
s/Tungsten Gra\(ph\|hp\)ics,\? [iI]nc\.\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./g
/Copyright/s/Tungsten Graphics\(,\? [iI]nc\.\)\?\(, Cedar Park\)\?\(, Austin\)\?\(, \(Texas\|TX\)\)\?\.\?/VMware, Inc./
s/TUNGSTEN GRAPHICS/VMWARE/g
# Rename emails
s/alanh@tungstengraphics.com/alanh@vmware.com/
s/jens@tungstengraphics.com/jowen@vmware.com/g
s/jrfonseca-at-tungstengraphics-dot-com/jfonseca-at-vmware-dot-com/
s/jrfonseca\?@tungstengraphics.com/jfonseca@vmware.com/g
s/keithw\?@tungstengraphics.com/keithw@vmware.com/g
s/michel@tungstengraphics.com/daenzer@vmware.com/g
s/thomas-at-tungstengraphics-dot-com/thellstom-at-vmware-dot-com/
s/zack@tungstengraphics.com/zackr@vmware.com/
# Remove dead links
s@Tungsten Graphics (http://www.tungstengraphics.com)@Tungsten Graphics@g
# C string src/gallium/state_trackers/vega/api_misc.c
s/"Tungsten Graphics, Inc"/"VMware, Inc"/
Reviewed-by: Brian Paul <brianp@vmware.com>
2014-01-17 16:27:50 +00:00
|
|
|
* @author José Fonseca <jfonseca@vmware.com>
|
2008-03-13 10:19:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "pipe/p_compiler.h"
|
2009-02-18 12:05:26 +00:00
|
|
|
#include "util/u_debug.h"
|
2008-03-13 10:19:23 +00:00
|
|
|
|
|
|
|
#include "cso_cache/cso_hash.h"
|
2008-08-25 00:48:55 +01:00
|
|
|
|
|
|
|
#include "util/u_memory.h"
|
|
|
|
#include "util/u_hash_table.h"
|
2008-03-13 10:19:23 +00:00
|
|
|
|
|
|
|
|
2009-10-17 11:45:04 +01:00
|
|
|
struct util_hash_table
|
2008-03-13 10:19:23 +00:00
|
|
|
{
|
|
|
|
struct cso_hash *cso;
|
|
|
|
|
|
|
|
/** Hash function */
|
|
|
|
unsigned (*hash)(void *key);
|
|
|
|
|
|
|
|
/** Compare two keys */
|
|
|
|
int (*compare)(void *key1, void *key2);
|
|
|
|
|
|
|
|
/* TODO: key, value destructors? */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-17 11:45:04 +01:00
|
|
|
struct util_hash_table_item
|
2008-03-13 10:19:23 +00:00
|
|
|
{
|
|
|
|
void *key;
|
|
|
|
void *value;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-07-21 00:58:43 +01:00
|
|
|
static inline struct util_hash_table_item *
|
2009-10-17 11:45:04 +01:00
|
|
|
util_hash_table_item(struct cso_hash_iter iter)
|
2008-05-08 07:19:07 +01:00
|
|
|
{
|
2009-10-17 11:45:04 +01:00
|
|
|
return (struct util_hash_table_item *)cso_hash_iter_data(iter);
|
2008-05-08 07:19:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-17 11:45:04 +01:00
|
|
|
struct util_hash_table *
|
|
|
|
util_hash_table_create(unsigned (*hash)(void *key),
|
|
|
|
int (*compare)(void *key1, void *key2))
|
2008-03-13 10:19:23 +00:00
|
|
|
{
|
2009-10-17 11:45:04 +01:00
|
|
|
struct util_hash_table *ht;
|
2008-03-13 10:19:23 +00:00
|
|
|
|
2009-10-17 11:45:04 +01:00
|
|
|
ht = MALLOC_STRUCT(util_hash_table);
|
2015-12-04 06:12:30 +00:00
|
|
|
if (!ht)
|
2008-03-13 10:19:23 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ht->cso = cso_hash_create();
|
|
|
|
if(!ht->cso) {
|
|
|
|
FREE(ht);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ht->hash = hash;
|
|
|
|
ht->compare = compare;
|
|
|
|
|
|
|
|
return ht;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-21 00:58:43 +01:00
|
|
|
static inline struct cso_hash_iter
|
2009-10-17 11:45:04 +01:00
|
|
|
util_hash_table_find_iter(struct util_hash_table *ht,
|
|
|
|
void *key,
|
|
|
|
unsigned key_hash)
|
2008-05-08 07:19:07 +01:00
|
|
|
{
|
|
|
|
struct cso_hash_iter iter;
|
2009-10-17 11:45:04 +01:00
|
|
|
struct util_hash_table_item *item;
|
2008-05-08 07:19:07 +01:00
|
|
|
|
|
|
|
iter = cso_hash_find(ht->cso, key_hash);
|
|
|
|
while (!cso_hash_iter_is_null(iter)) {
|
2009-10-17 11:45:04 +01:00
|
|
|
item = (struct util_hash_table_item *)cso_hash_iter_data(iter);
|
2008-05-08 07:19:07 +01:00
|
|
|
if (!ht->compare(item->key, key))
|
|
|
|
break;
|
|
|
|
iter = cso_hash_iter_next(iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-21 00:58:43 +01:00
|
|
|
static inline struct util_hash_table_item *
|
2009-10-17 11:45:04 +01:00
|
|
|
util_hash_table_find_item(struct util_hash_table *ht,
|
|
|
|
void *key,
|
|
|
|
unsigned key_hash)
|
2008-03-13 10:19:23 +00:00
|
|
|
{
|
|
|
|
struct cso_hash_iter iter;
|
2009-10-17 11:45:04 +01:00
|
|
|
struct util_hash_table_item *item;
|
2008-03-13 10:19:23 +00:00
|
|
|
|
|
|
|
iter = cso_hash_find(ht->cso, key_hash);
|
|
|
|
while (!cso_hash_iter_is_null(iter)) {
|
2009-10-17 11:45:04 +01:00
|
|
|
item = (struct util_hash_table_item *)cso_hash_iter_data(iter);
|
2008-03-13 10:19:23 +00:00
|
|
|
if (!ht->compare(item->key, key))
|
|
|
|
return item;
|
|
|
|
iter = cso_hash_iter_next(iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum pipe_error
|
2009-10-17 11:45:04 +01:00
|
|
|
util_hash_table_set(struct util_hash_table *ht,
|
|
|
|
void *key,
|
|
|
|
void *value)
|
2008-03-13 10:19:23 +00:00
|
|
|
{
|
|
|
|
unsigned key_hash;
|
2009-10-17 11:45:04 +01:00
|
|
|
struct util_hash_table_item *item;
|
2008-05-08 07:19:07 +01:00
|
|
|
struct cso_hash_iter iter;
|
2008-03-13 10:19:23 +00:00
|
|
|
|
|
|
|
assert(ht);
|
2009-06-21 02:19:57 +01:00
|
|
|
if (!ht)
|
|
|
|
return PIPE_ERROR_BAD_INPUT;
|
2008-03-13 10:19:23 +00:00
|
|
|
|
|
|
|
key_hash = ht->hash(key);
|
|
|
|
|
2009-10-17 11:45:04 +01:00
|
|
|
item = util_hash_table_find_item(ht, key, key_hash);
|
2015-12-04 06:12:30 +00:00
|
|
|
if (item) {
|
2008-03-13 10:19:23 +00:00
|
|
|
/* TODO: key/value destruction? */
|
|
|
|
item->value = value;
|
|
|
|
return PIPE_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-17 11:45:04 +01:00
|
|
|
item = MALLOC_STRUCT(util_hash_table_item);
|
2015-12-04 06:12:30 +00:00
|
|
|
if (!item)
|
2008-03-13 10:19:23 +00:00
|
|
|
return PIPE_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
item->key = key;
|
|
|
|
item->value = value;
|
|
|
|
|
2008-05-08 07:19:07 +01:00
|
|
|
iter = cso_hash_insert(ht->cso, key_hash, item);
|
|
|
|
if(cso_hash_iter_is_null(iter)) {
|
2008-03-13 10:19:23 +00:00
|
|
|
FREE(item);
|
|
|
|
return PIPE_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PIPE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void *
|
2009-10-17 11:45:04 +01:00
|
|
|
util_hash_table_get(struct util_hash_table *ht,
|
|
|
|
void *key)
|
2008-03-13 10:19:23 +00:00
|
|
|
{
|
|
|
|
unsigned key_hash;
|
2009-10-17 11:45:04 +01:00
|
|
|
struct util_hash_table_item *item;
|
2008-03-13 10:19:23 +00:00
|
|
|
|
|
|
|
assert(ht);
|
2009-06-21 02:19:57 +01:00
|
|
|
if (!ht)
|
|
|
|
return NULL;
|
2008-03-13 10:19:23 +00:00
|
|
|
|
|
|
|
key_hash = ht->hash(key);
|
|
|
|
|
2009-10-17 11:45:04 +01:00
|
|
|
item = util_hash_table_find_item(ht, key, key_hash);
|
2015-12-04 06:12:30 +00:00
|
|
|
if (!item)
|
2008-03-13 10:19:23 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return item->value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2009-10-17 11:45:04 +01:00
|
|
|
util_hash_table_remove(struct util_hash_table *ht,
|
|
|
|
void *key)
|
2008-03-13 10:19:23 +00:00
|
|
|
{
|
|
|
|
unsigned key_hash;
|
2008-05-08 07:19:07 +01:00
|
|
|
struct cso_hash_iter iter;
|
2009-10-17 11:45:04 +01:00
|
|
|
struct util_hash_table_item *item;
|
2008-03-13 10:19:23 +00:00
|
|
|
|
|
|
|
assert(ht);
|
2009-06-21 02:19:57 +01:00
|
|
|
if (!ht)
|
|
|
|
return;
|
2008-03-13 10:19:23 +00:00
|
|
|
|
|
|
|
key_hash = ht->hash(key);
|
|
|
|
|
2009-10-17 11:45:04 +01:00
|
|
|
iter = util_hash_table_find_iter(ht, key, key_hash);
|
2008-05-08 07:19:07 +01:00
|
|
|
if(cso_hash_iter_is_null(iter))
|
2008-03-13 10:19:23 +00:00
|
|
|
return;
|
|
|
|
|
2009-10-17 11:45:04 +01:00
|
|
|
item = util_hash_table_item(iter);
|
2008-05-08 07:19:07 +01:00
|
|
|
assert(item);
|
|
|
|
FREE(item);
|
|
|
|
|
|
|
|
cso_hash_erase(ht->cso, iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2009-10-17 11:45:04 +01:00
|
|
|
util_hash_table_clear(struct util_hash_table *ht)
|
2008-05-08 07:19:07 +01:00
|
|
|
{
|
|
|
|
struct cso_hash_iter iter;
|
2009-10-17 11:45:04 +01:00
|
|
|
struct util_hash_table_item *item;
|
2008-05-08 07:19:07 +01:00
|
|
|
|
|
|
|
assert(ht);
|
2009-06-21 02:19:57 +01:00
|
|
|
if (!ht)
|
|
|
|
return;
|
|
|
|
|
2008-05-08 07:19:07 +01:00
|
|
|
iter = cso_hash_first_node(ht->cso);
|
|
|
|
while (!cso_hash_iter_is_null(iter)) {
|
2009-10-17 11:45:04 +01:00
|
|
|
item = (struct util_hash_table_item *)cso_hash_take(ht->cso, cso_hash_iter_key(iter));
|
2008-05-08 07:19:07 +01:00
|
|
|
FREE(item);
|
|
|
|
iter = cso_hash_first_node(ht->cso);
|
|
|
|
}
|
2008-03-13 10:19:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-18 12:01:14 +00:00
|
|
|
enum pipe_error
|
2009-10-17 11:45:04 +01:00
|
|
|
util_hash_table_foreach(struct util_hash_table *ht,
|
2009-10-16 16:27:56 +01:00
|
|
|
enum pipe_error (*callback)
|
|
|
|
(void *key, void *value, void *data),
|
|
|
|
void *data)
|
2008-03-18 12:01:14 +00:00
|
|
|
{
|
|
|
|
struct cso_hash_iter iter;
|
2009-10-17 11:45:04 +01:00
|
|
|
struct util_hash_table_item *item;
|
2008-03-18 12:01:14 +00:00
|
|
|
enum pipe_error result;
|
2009-06-21 02:19:57 +01:00
|
|
|
|
2008-05-08 07:19:07 +01:00
|
|
|
assert(ht);
|
2009-06-21 02:19:57 +01:00
|
|
|
if (!ht)
|
|
|
|
return PIPE_ERROR_BAD_INPUT;
|
|
|
|
|
2008-03-18 12:01:14 +00:00
|
|
|
iter = cso_hash_first_node(ht->cso);
|
|
|
|
while (!cso_hash_iter_is_null(iter)) {
|
2009-10-17 11:45:04 +01:00
|
|
|
item = (struct util_hash_table_item *)cso_hash_iter_data(iter);
|
2008-03-18 12:01:14 +00:00
|
|
|
result = callback(item->key, item->value, data);
|
|
|
|
if(result != PIPE_OK)
|
|
|
|
return result;
|
|
|
|
iter = cso_hash_iter_next(iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
return PIPE_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-13 10:19:23 +00:00
|
|
|
void
|
2009-10-17 11:45:04 +01:00
|
|
|
util_hash_table_destroy(struct util_hash_table *ht)
|
2008-03-13 10:19:23 +00:00
|
|
|
{
|
2008-05-08 07:19:07 +01:00
|
|
|
struct cso_hash_iter iter;
|
2009-10-17 11:45:04 +01:00
|
|
|
struct util_hash_table_item *item;
|
2009-06-21 02:19:57 +01:00
|
|
|
|
2008-03-13 10:19:23 +00:00
|
|
|
assert(ht);
|
2009-06-21 02:19:57 +01:00
|
|
|
if (!ht)
|
|
|
|
return;
|
|
|
|
|
2008-05-08 07:19:07 +01:00
|
|
|
iter = cso_hash_first_node(ht->cso);
|
|
|
|
while (!cso_hash_iter_is_null(iter)) {
|
2009-10-17 11:45:04 +01:00
|
|
|
item = (struct util_hash_table_item *)cso_hash_iter_data(iter);
|
2008-05-08 07:19:07 +01:00
|
|
|
FREE(item);
|
|
|
|
iter = cso_hash_iter_next(iter);
|
|
|
|
}
|
2008-03-13 10:19:23 +00:00
|
|
|
|
|
|
|
cso_hash_delete(ht->cso);
|
|
|
|
|
|
|
|
FREE(ht);
|
|
|
|
}
|