Re: [Multi-valued V2 (grilo) 08/12] core: Use a representative element when handling multivalued data




On Tue, 1 Mar 2011 10:50:27 +0100, "Juan A. Suarez Romero" <jasuarez igalia com> wrote:
Each time a new value is inserted for a property, store the value in the list
of values of the representative element of related keys.

That is, instead of operating on "key", operate on
"representative(key)", which
is "representative(key) = head(related_keys(key))".

Signed-off-by: Juan A. Suarez Romero <jasuarez igalia com>
---
 src/data/grl-data-multi.c |  123
+++++++++++++++++++++++++++++----------------
 1 files changed, 80 insertions(+), 43 deletions(-)

diff --git a/src/data/grl-data-multi.c b/src/data/grl-data-multi.c
index 819e5e7..0d4e9d3 100644
--- a/src/data/grl-data-multi.c
+++ b/src/data/grl-data-multi.c
@@ -148,20 +148,25 @@ grl_data_multi_add (GrlDataMulti *mdata,
   l = grl_data_multi_length (mdata, keys->data);

   if (l > 0) {
-    /* Add it in extended data */
+    /* Get the representative element of key */
     registry = grl_plugin_registry_get_default ();
- related_keys = grl_plugin_registry_lookup_metadata_relation (registry,
-
keys->data);
-    while (related_keys) {
-      values = g_hash_table_lookup (mdata->priv->extended_data,
-                                    related_keys->data);
-      values = g_list_append (values, g_object_ref (prop));
-      g_hash_table_insert (mdata->priv->extended_data,
-                           related_keys->data,
-                           values);
-      related_keys = g_list_next (related_keys);
+    related_keys =
+      grl_plugin_registry_lookup_metadata_key_relation (registry,
+                                                        keys->data);
+
+    if (!related_keys) {
+      GRL_WARNING ("Related keys not found for key: %s",
+                   grl_metadata_key_get_name (related_keys->data));
+      g_list_free (keys);
+      return;
     }
-    g_list_free (keys);
+
+    values = g_hash_table_lookup (mdata->priv->extended_data,
+                                  related_keys->data);
+    values = g_list_append (values, prop);
+    g_hash_table_insert (mdata->priv->extended_data,
+                         related_keys->data,
+                         values);
   } else {
     /* Insert it as single valued data */
     for (key = keys; key; key = g_list_next (key)) {

We discussed last week that all the elements would be multi-valued. I guess you address this in later patches that I have not checked yet, but just in case I mention it here now...

Iago


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