partial dbghelp wine sync

svn path=/trunk/; revision=41474
This commit is contained in:
Christoph von Wittich 2009-06-19 22:14:54 +00:00
parent aa85426a38
commit d9042af464
2 changed files with 20 additions and 21 deletions

View file

@ -78,11 +78,17 @@ struct hash_table_elt
struct hash_table_elt* next; struct hash_table_elt* next;
}; };
struct hash_table_bucket
{
struct hash_table_elt* first;
struct hash_table_elt* last;
};
struct hash_table struct hash_table
{ {
unsigned num_elts; unsigned num_elts;
unsigned num_buckets; unsigned num_buckets;
struct hash_table_elt** buckets; struct hash_table_bucket* buckets;
struct pool* pool; struct pool* pool;
}; };
@ -90,7 +96,6 @@ void hash_table_init(struct pool* pool, struct hash_table* ht,
unsigned num_buckets); unsigned num_buckets);
void hash_table_destroy(struct hash_table* ht); void hash_table_destroy(struct hash_table* ht);
void hash_table_add(struct hash_table* ht, struct hash_table_elt* elt); void hash_table_add(struct hash_table* ht, struct hash_table_elt* elt);
void* hash_table_find(const struct hash_table* ht, const char* name);
unsigned hash_table_hash(const char* name, unsigned num_buckets); unsigned hash_table_hash(const char* name, unsigned num_buckets);
struct hash_table_iter struct hash_table_iter

View file

@ -361,36 +361,30 @@ void hash_table_destroy(struct hash_table* ht)
void hash_table_add(struct hash_table* ht, struct hash_table_elt* elt) void hash_table_add(struct hash_table* ht, struct hash_table_elt* elt)
{ {
unsigned hash = hash_table_hash(elt->name, ht->num_buckets); unsigned hash = hash_table_hash(elt->name, ht->num_buckets);
struct hash_table_elt** p;
if (!ht->buckets) if (!ht->buckets)
{ {
ht->buckets = pool_alloc(ht->pool, ht->num_buckets * sizeof(struct hash_table_elt*)); ht->buckets = pool_alloc(ht->pool, ht->num_buckets * sizeof(struct hash_table_bucket));
assert(ht->buckets); assert(ht->buckets);
memset(ht->buckets, 0, ht->num_buckets * sizeof(struct hash_table_elt*)); memset(ht->buckets, 0, ht->num_buckets * sizeof(struct hash_table_bucket));
} }
/* in some cases, we need to get back the symbols of same name in the order /* in some cases, we need to get back the symbols of same name in the order
* in which they've been inserted. So insert new elements at the end of the list. * in which they've been inserted. So insert new elements at the end of the list.
*/ */
for (p = &ht->buckets[hash]; *p; p = &((*p)->next)); if (!ht->buckets[hash].first)
*p = elt; {
ht->buckets[hash].first = elt;
}
else
{
ht->buckets[hash].last->next = elt;
}
ht->buckets[hash].last = elt;
elt->next = NULL; elt->next = NULL;
ht->num_elts++; ht->num_elts++;
} }
void* hash_table_find(const struct hash_table* ht, const char* name)
{
unsigned hash = hash_table_hash(name, ht->num_buckets);
struct hash_table_elt* elt;
if(!ht->buckets) return NULL;
for (elt = ht->buckets[hash]; elt; elt = elt->next)
if (!strcmp(name, elt->name)) return elt;
return NULL;
}
void hash_table_iter_init(const struct hash_table* ht, void hash_table_iter_init(const struct hash_table* ht,
struct hash_table_iter* hti, const char* name) struct hash_table_iter* hti, const char* name)
{ {
@ -414,6 +408,6 @@ void* hash_table_iter_up(struct hash_table_iter* hti)
if (hti->element) hti->element = hti->element->next; if (hti->element) hti->element = hti->element->next;
while (!hti->element && hti->index < hti->last) while (!hti->element && hti->index < hti->last)
hti->element = hti->ht->buckets[++hti->index]; hti->element = hti->ht->buckets[++hti->index].first;
return hti->element; return hti->element;
} }