Re: [gtk-list] Re: Are GHashTable's deterministic?



>  I wrote the little code below which examplify this behavior.
>  the function surface_read just fills in hash table s->triangles from a
>  file. id (t) just returns a unique number corresponding to the order of
>  creation of the triangle t. In that case, the output of the program
>  (i.e. the order in which the hash table is traversed) is the same when
>  the same code is run multiple times but differs if the code is linked to
>  an object surface.o which size is different (the function surface_read
>  NOT being modified in any way).
[example snipped]

This is not a useful test program, since it cannot be compiled.  You
should provide a complete test that exhibits this behavior.

Hash tables are essentialy unordered data structures.  Glib's
g_hash_table_foreach() is just a nice convenience function that walks
the hash buckets.  If you use it to walk a hash table, and do not
change the hash table, and walk it again, the order should not change
--- this is not a requirement of hash tables per se, but it is what
the glib code happens to do.

Your code may be creating the hash table in a different way "depending
on the code size" due to a bug.  Try manually printing the order in
which triangles are inserted in the hash table as you read them from
the file.

  Federico



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]