Skip to content
Snippets Groups Projects
Commit b93efce5 authored by edgrif's avatar edgrif
Browse files

add an insertlist and merge function to the hashlist utils.

parent 7d0f9fa2
No related branches found
No related tags found
No related merge requests found
......@@ -26,9 +26,9 @@
* glib but not included with their distribution.
*
* HISTORY:
* Last edited: Apr 22 11:51 2009 (edgrif)
* Last edited: Jun 11 15:52 2009 (edgrif)
* Created: Thu Oct 13 15:56:54 2005 (edgrif)
* CVS info: $Id: zmapGLibUtils.h,v 1.21 2009-04-22 16:25:00 edgrif Exp $
* CVS info: $Id: zmapGLibUtils.h,v 1.22 2009-06-12 07:45:22 edgrif Exp $
*-------------------------------------------------------------------
*/
#ifndef ZMAP_GLIBUTILS_H
......@@ -81,12 +81,14 @@ GList *zMap_g_list_raise(GList *move, int positions);
GList *zMap_g_list_split(GList *list, GList *new_list_head) ;
gpointer zMap_g_hash_table_nth(GHashTable *hash_table, int nth) ;
GHashTable *zMap_g_hashlist_create(void) ;
gboolean zMap_g_string_replace(GString *string, char *target, char *source) ;
GHashTable *zMap_g_hashlist_create(void) ;
void zMap_g_hashlist_insert(GHashTable *hashlist, GQuark key, gpointer value) ;
void zMap_g_hashlist_insert_list(GHashTable *hashlist, GQuark key, GList *key_values, gboolean replace) ;
GHashTable *zMap_g_hashlist_copy(GHashTable *orig_hashlist) ;
void zMap_g_hashlist_merge(GHashTable *in_out, GHashTable *in) ;
void zMap_g_hashlist_print(GHashTable *hashlist) ;
void zMap_g_hashlist_destroy(GHashTable *hashlist) ;
......
......@@ -26,9 +26,9 @@
*
* Exported functions: See ZMap/zmapGLibUtils.h
* HISTORY:
* Last edited: May 5 18:07 2009 (rds)
* Last edited: Jun 12 08:44 2009 (edgrif)
* Created: Thu Oct 13 15:22:35 2005 (edgrif)
* CVS info: $Id: zmapGLibUtils.c,v 1.29 2009-05-05 18:12:15 rds Exp $
* CVS info: $Id: zmapGLibUtils.c,v 1.30 2009-06-12 07:45:22 edgrif Exp $
*-------------------------------------------------------------------
*/
......@@ -85,6 +85,8 @@ static gboolean getNthHashElement(gpointer key, gpointer value, gpointer user_da
static void hashCopyListCB(gpointer key, gpointer value, gpointer user_data) ;
static void hashPrintListCB(gpointer key, gpointer value, gpointer user_data_unused) ;
static void destroyList(gpointer data) ;
static void mergehashCB(gpointer key, gpointer value, gpointer user_data) ;
/*! @defgroup zmapGLibutils zMapGLibUtils: glib-derived utilities for ZMap
......@@ -553,7 +555,7 @@ void zMap_g_hashlist_insert(GHashTable *hashlist, GQuark key, gpointer value)
list = (GList *)g_hash_table_lookup(hashlist, GINT_TO_POINTER(key)) ;
/* This makes this as bad as a g_datalist... Well nearly. */
if(!g_list_find(list, value))
if (!g_list_find(list, value))
{
list = g_list_copy(list) ;
......@@ -566,6 +568,20 @@ void zMap_g_hashlist_insert(GHashTable *hashlist, GQuark key, gpointer value)
}
/* ! Insert a list of key values into the keyed list, if replace is TRUE then the list
* replaces any existing list, if FALSE and a list already exists then the function simply
* returns. */
void zMap_g_hashlist_insert_list(GHashTable *hashlist, GQuark key, GList *key_values, gboolean replace)
{
/* Slightly tricky coding, the existing copy of the list will automatically
* be free'd by g_hash_table calling our registered hash delete function. */
if (replace || !(g_hash_table_lookup(hashlist, GINT_TO_POINTER(key))))
g_hash_table_insert(hashlist, GINT_TO_POINTER(key), key_values) ;
return ;
}
/*! Make a copy of the hash table of featureset names to styles lists. */
GHashTable *zMap_g_hashlist_copy(GHashTable *orig_hashlist)
{
......@@ -579,6 +595,19 @@ GHashTable *zMap_g_hashlist_copy(GHashTable *orig_hashlist)
}
/*! Merge two featureset/style hashes, any elements from "in" are merged into
* in_out, in is left unaltered. */
void zMap_g_hashlist_merge(GHashTable *in_out, GHashTable *in)
{
g_hash_table_foreach(in, mergehashCB, in_out) ;
return ;
}
/*! Print out the featureset -> styles lists. */
void zMap_g_hashlist_print(GHashTable *hashlist)
{
......@@ -993,3 +1022,30 @@ static void destroyList(gpointer data)
}
static void mergehashCB(gpointer key, gpointer value, gpointer user_data)
{
GHashTable *hash = (GHashTable *)user_data ;
/* If the feature set id is not in the hash then copy its list of styles and add it to the
* target hash. */
if (!(g_hash_table_lookup(hash, key)))
{
GList *copy ;
copy = g_list_copy((GList *)value) ;
zMap_g_hashlist_insert_list(hash, GPOINTER_TO_INT(key), copy, TRUE) ;
}
return ;
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment