From: <fr...@us...> - 2011-01-20 12:19:10
|
Revision: 4267 http://fuse-emulator.svn.sourceforge.net/fuse-emulator/?rev=4267&view=rev Author: fredm Date: 2011-01-20 12:19:04 +0000 (Thu, 20 Jan 2011) Log Message: ----------- Add the g_hash_table_foreach() function and update g_hash_table_new() function to support the g_hash_table_new( NULL, NULL ) syntax (patch #3160211) (Sergio Baldovi). Modified Paths: -------------- trunk/libspectrum/hacking/ChangeLog trunk/libspectrum/make-perl.c trunk/libspectrum/myglib/ghash.c Modified: trunk/libspectrum/hacking/ChangeLog =================================================================== --- trunk/libspectrum/hacking/ChangeLog 2011-01-20 11:47:49 UTC (rev 4266) +++ trunk/libspectrum/hacking/ChangeLog 2011-01-20 12:19:04 UTC (rev 4267) @@ -796,3 +796,7 @@ 20101216 test/Makefile.am: ensure all test files are distributed. 20101217 Makefile.am: mark windres.rc as a source file so it is distributed (thanks, Guesser). +20110120 make-perl.c,myglib/ghash.c: add the g_hash_table_foreach() function and + update g_hash_table_new() function to support the + g_hash_table_new( NULL, NULL ) syntax (patch #3160211) (Sergio + Baldovi). Modified: trunk/libspectrum/make-perl.c =================================================================== --- trunk/libspectrum/make-perl.c 2011-01-20 11:47:49 UTC (rev 4266) +++ trunk/libspectrum/make-perl.c 2011-01-20 12:19:04 UTC (rev 4267) @@ -133,6 +133,7 @@ "typedef long glong;\n" "typedef gint gboolean;\n" "typedef unsigned int guint;\n" +"typedef unsigned long gulong;\n" "typedef const void * gconstpointer;\n" "typedef void * gpointer;\n" "\n" @@ -196,6 +197,10 @@ "\n" "typedef guint (*GHashFunc) (gconstpointer key);\n" "\n" +"typedef void (*GHFunc) (gpointer key,\n" +" gpointer value,\n" +" gpointer user_data);\n" +"\n" "typedef gboolean (*GHRFunc) (gpointer key,\n" " gpointer value,\n" " gpointer user_data);\n" @@ -220,6 +225,10 @@ "WIN32_DLL gpointer g_hash_table_lookup (GHashTable *hash_table,\n" " gconstpointer key);\n" "\n" +"WIN32_DLL void g_hash_table_foreach (GHashTable *hash_table,\n" +" GHFunc func,\n" +" gpointer user_data);\n" +"\n" "WIN32_DLL guint g_hash_table_foreach_remove (GHashTable *hash_table,\n" " GHRFunc func,\n" " gpointer user_data);\n" @@ -248,9 +257,11 @@ if( sizeof( void* ) == sizeof( int ) ) { printf( "#define GINT_TO_POINTER(i) ((gpointer) (i))\n" ); printf( "#define GPOINTER_TO_INT(p) ((gint) (p))\n" ); + printf( "#define GPOINTER_TO_UINT(p) ((guint) (p))\n" ); } else if( sizeof( void* ) == sizeof( long ) ) { printf( "#define GINT_TO_POINTER(i) ((gpointer) (glong)(i))\n" ); printf( "#define GPOINTER_TO_INT(p) ((gint) (glong)(p))\n" ); + printf( "#define GPOINTER_TO_UINT(p) ((guint) (gulong)(p))\n" ); } else { fprintf( stderr, "No plausible int to pointer cast found\n" ); return 1; Modified: trunk/libspectrum/myglib/ghash.c =================================================================== --- trunk/libspectrum/myglib/ghash.c 2011-01-20 11:47:49 UTC (rev 4266) +++ trunk/libspectrum/myglib/ghash.c 2011-01-20 12:19:04 UTC (rev 4267) @@ -8,7 +8,7 @@ files for a list of changes. These files are distributed with GLib at ftp://ftp.gtk.org/pub/gtk/. - Modified by Philip Kendall 2004-2008. + Modified by Philip Kendall 2004-2011. $Id$ @@ -61,6 +61,12 @@ static GHashNode *node_free_list = NULL; +guint +g_direct_hash (gconstpointer v) +{ + return GPOINTER_TO_UINT (v); +} + GHashTable* g_hash_table_new (GHashFunc hash_func, GCompareFunc key_equal_func) @@ -71,7 +77,7 @@ hash_table = libspectrum_malloc (sizeof (GHashTable)); hash_table->nnodes = 0; - hash_table->hash_func = hash_func; + hash_table->hash_func = hash_func? hash_func : g_direct_hash; hash_table->key_equal_func = key_equal_func; hash_table->nodes = libspectrum_malloc (HASH_TABLE_SIZE * sizeof (GHashNode*)); @@ -116,10 +122,17 @@ node = &hash_table->nodes [(* hash_table->hash_func) (key) % HASH_TABLE_SIZE]; - - while (*node && !(*hash_table->key_equal_func) ((*node)->key, key)) + + while( *node ) { + if( hash_table->key_equal_func ) { + if( hash_table->key_equal_func( (*node)->key, key ) ) break; + } else if( (*node)->key == key ) { + break; + } + node = &(*node)->next; - + } + return node; } @@ -230,6 +243,19 @@ return deleted; } +void +g_hash_table_foreach (GHashTable *hash_table, + GHFunc func, + gpointer user_data) +{ + GHashNode *node; + gint i; + + for (i = 0; i < HASH_TABLE_SIZE; i++) + for (node = hash_table->nodes[i]; node; node = node->next) + (* func) (node->key, node->value, user_data); +} + guint g_hash_table_size (GHashTable *hash_table) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |