Re: Possible GHashTable bug?
- From: Darin Adler <darin bentspoon com>
- To: Derek Simkowiak <dereks realloc net>
- Cc: gtk-devel-list redhat com
- Subject: Re: Possible GHashTable bug?
- Date: Thu, 5 Jul 2001 10:11:39 -0700
On Thursday, July 5, 2001, at 05:31 AM, Havoc Pennington wrote:
Derek Simkowiak <dereks realloc net> writes:
Ooh, ouch; I take this means I also cannot *add* elements while
within g_hash_table_foreach(). That may be a showstopper for me. How
can
player1 fire a rocket (resulting in a new entity --the rocket-- for the
hash) if I can't add entities in the iteration of my main loop? I guess
I'll need a queue or something for post-foreach additions and removals.
Anyway, thanks for the help. It would be cool if there were an
Iterator for the GHashTable (g_hash_table_next() or some such) that would
still allow you to add/remove elements between calls.
The usual solution is to flatten the hash into a list, then iterate
over that.
For an example of how to do this, you can look at
eel_g_hash_table_safe_for_each.
<http://cvs.gnome.org/lxr/ident?i=eel_g_hash_table_safe_for_each>. While I
don't like the name I chose that much, I occasionally find it handy to
have a version of g_hash_table_foreach that flattens into lists and then
uses the lists, allowing the hash table to change during the iteration. It'
s used 3 places in Nautilus.
-- Darin
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]