Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 616
  • Last Modified:

duplicating a GHashTable

Hi i want to create a  GHashTable  from an existing GHashTable
my need is to create a temproery GHashTable for some purpose
i looked here
http://developer.gnome.org/doc/API/2.0/glib/glib-Hash-Tables.html
but i didnt find any easier way

void fff(GHashTable *gp)
{
GHashTable tmpg;
tmpg=make_new _ghashtable(gp);
}
i want to do like this ,is ther any simple way like this or ,i need to access each strings in the existing ghashtable and need to insert into tmp hashtable?
thanks..







 
0
hirosh
Asked:
hirosh
1 Solution
 
stefan73Commented:
Hi hirosh,
There's no direct copy function. You need to use the g_hash_table_foreach() to iterate over the old table to create a copy of it.

Example (haven't tested it):

void copy_hash_table(GHashTable *dest, GHashTable *src){
    g_hash_table_foreach(src,copy_hash_table_iterator,dest);
}

static void copy_hash_table_iterator(gpointer key,gpointer val, gpointer dest){
    g_hash_table_insert((GHashTable*) dest, key,val);
}


(this assumes the dest table is empty when passed)

Cheers!

Stefan
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now