Enlightenment CVS committal

Author  : englebass
Project : e17
Module  : libs/ecore

Dir     : e17/libs/ecore/src/lib/ecore


Modified Files:
        Ecore_Data.h ecore_hash.c ecore_list.c 


Log Message:
Functions to join lists and hashes.

===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore/Ecore_Data.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -3 -r1.28 -r1.29
--- Ecore_Data.h        16 Jan 2007 01:27:01 -0000      1.28
+++ Ecore_Data.h        17 Jan 2007 13:41:08 -0000      1.29
@@ -89,6 +89,8 @@
    EAPI int ecore_list_append(Ecore_List * list, void *_data);
    EAPI int ecore_list_prepend(Ecore_List * list, void *_data);
    EAPI int ecore_list_insert(Ecore_List * list, void *_data);
+   EAPI int ecore_list_append_list(Ecore_List * list, Ecore_List * append);
+   EAPI int ecore_list_prepend_list(Ecore_List * list, Ecore_List * prepend);
    
    /* Removing items from the list */
    EAPI int ecore_list_remove_destroy(Ecore_List *list);
@@ -153,6 +155,8 @@
    EAPI int ecore_dlist_append(Ecore_DList * _e_dlist, void *_data);
    EAPI int ecore_dlist_prepend(Ecore_DList * _e_dlist, void *_data);
    EAPI int ecore_dlist_insert(Ecore_DList * _e_dlist, void *_data);
+   EAPI int ecore_dlist_append_list(Ecore_DList * _e_dlist, Ecore_DList * 
append);
+   EAPI int ecore_dlist_prepend_list(Ecore_DList * _e_dlist, Ecore_DList * 
prepend);
    
    /* Info about list's state */
    EAPI void *ecore_dlist_current(Ecore_DList *list);
@@ -246,6 +250,7 @@
    /* Retrieve and store data into the hash */
    EAPI void *ecore_hash_get(Ecore_Hash *hash, const void *key);
    EAPI int ecore_hash_set(Ecore_Hash *hash, void *key, void *value);
+   EAPI int ecore_hash_set_hash(Ecore_Hash *hash, Ecore_Hash *set);
    EAPI void *ecore_hash_remove(Ecore_Hash *hash, const void *key);
    EAPI void ecore_hash_dump_graph(Ecore_Hash *hash);
    EAPI void ecore_hash_dump_stats(Ecore_Hash *hash);
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore/ecore_hash.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -3 -r1.33 -r1.34
--- ecore_hash.c        16 Jan 2007 01:27:01 -0000      1.33
+++ ecore_hash.c        17 Jan 2007 13:41:08 -0000      1.34
@@ -170,6 +170,49 @@
 }
 
 /**
+ * Sets all key-value pairs from set in the given hash table.
+ * @param   hash    The given hash table.
+ * @param   set     The hash table to import.
+ * @return  @c TRUE if successful, @c FALSE if not.
+ * @ingroup Ecore_Data_Hash_ADT_Data_Group
+ */
+EAPI int
+ecore_hash_set_hash(Ecore_Hash *hash, Ecore_Hash *set)
+{
+   unsigned int i;
+   Ecore_Hash_Node *node, *old;
+
+   CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
+   CHECK_PARAM_POINTER_RETURN("set", set, FALSE);
+
+   for (i = 0; i < ecore_prime_table[set->size]; i++)
+     {
+       /* Hash into a new list to avoid loops of rehashing the same nodes */
+       while ((old = set->buckets[i]))
+         {
+            set->buckets[i] = old->next;
+            old->next = NULL;
+            node = _ecore_hash_get_node(hash, old->key);
+            if (node)
+              {
+                 /* This key already exists. Delete the old and add the new
+                  * value */
+                 if (hash->free_key) hash->free_key(node->key);
+                 if (hash->free_value) hash->free_key(node->value);
+                 node->key = old->key;
+                 node->value = old->value;
+                 free(old);
+              }
+            else
+              _ecore_hash_add_node(hash, old);
+         }
+     }
+   FREE(set->buckets);
+   ecore_hash_init(set, set->hash_func, set->compare);
+   return TRUE;
+}
+
+/**
  * Frees the hash table and the data contained inside it.
  * @param   hash The hash table to destroy.
  * @return  @c TRUE on success, @c FALSE on error.
@@ -694,7 +737,7 @@
  * @brief Rehash the nodes of a table into the hash table
  * @param hash: the hash to place the nodes of the table
  * @param table: the table to remove the nodes from and place in hash
- * @return Returns TRUE on success, FALSE on success
+ * @return Returns TRUE on success, FALSE on error
  */
 inline int
 _ecore_hash_rehash(Ecore_Hash *hash, Ecore_Hash_Node **old_table, int old_size)
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore/ecore_list.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -3 -r1.30 -r1.31
--- ecore_list.c        13 Jan 2007 17:51:10 -0000      1.30
+++ ecore_list.c        17 Jan 2007 13:41:08 -0000      1.31
@@ -494,6 +494,71 @@
 
    return TRUE;
 }
+/**
+ * Append a list to the list.
+ * @param   list The list.
+ * @param   append The list to append.
+ * @return  @c FALSE if an error occurs, @c TRUE if appended successfully
+ * @ingroup Ecore_Data_List_Add_Item_Group
+ */
+
+EAPI int 
+ecore_list_append_list(Ecore_List *list, Ecore_List *append)
+{
+   CHECK_PARAM_POINTER_RETURN("list", list, FALSE);
+   CHECK_PARAM_POINTER_RETURN("append", append, FALSE);
+
+   if (ecore_list_is_empty(append)) return TRUE;
+
+   if (ecore_list_is_empty(list))
+     {
+       list->first = append->first;
+       list->current = NULL;
+       list->last = append->last;
+       list->nodes = append->nodes;
+     }
+   else
+     {
+       list->last->next = append->first;
+       list->last = append->last;
+       list->nodes += append->nodes;
+     }
+   ecore_list_init(append);
+   return TRUE;
+}
+
+/**
+ * Prepend a list to the beginning of the list.
+ * @param  list The list.
+ * @param  prepend The list to prepend.
+ * @return @c FALSE if an error occurs, @c TRUE if prepended successfully.
+ * @ingroup Ecore_Data_List_Add_Item_Group
+ */
+EAPI int 
+ecore_list_prepend_list(Ecore_List *list, Ecore_List *prepend)
+{
+   CHECK_PARAM_POINTER_RETURN("list", list, FALSE);
+   CHECK_PARAM_POINTER_RETURN("prepend", prepend, FALSE);
+
+   if (ecore_list_is_empty(prepend)) return TRUE;
+
+   if (ecore_list_is_empty(list))
+     {
+       list->first = prepend->first;
+       list->current = NULL;
+       list->last = prepend->last;
+       list->nodes = prepend->nodes;
+     }
+   else
+     {
+       prepend->last->next = list->first;
+       list->first = prepend->first;
+       list->nodes += prepend->nodes;
+       list->index += prepend->nodes;
+     }
+   ecore_list_init(prepend);
+   return TRUE;
+}
 
 /**
 @defgroup Ecore_Data_List_Remove_Item_Group List Item Removing Functions
@@ -1327,6 +1392,73 @@
    ECORE_LIST(list)->nodes++;
 
    return ret;
+}
+
+/**
+ * Appends a list to the given doubly linked list.
+ * @param   list The given doubly linked list.
+ * @param   append The list to append.
+ * @return  @c TRUE if the data is successfully appended, @c FALSE otherwise.
+ * @ingroup Ecore_Data_DList_Add_Item_Group
+ */
+EAPI int 
+ecore_dlist_append_list(Ecore_DList *list, Ecore_DList *append)
+{
+   CHECK_PARAM_POINTER_RETURN("list", list, FALSE);
+   CHECK_PARAM_POINTER_RETURN("append", append, FALSE);
+
+   if (ecore_dlist_is_empty(append)) return TRUE;
+
+   if (ecore_dlist_is_empty(list))
+     {
+       list->first = append->first;
+       list->current = NULL;
+       list->last = append->last;
+       list->nodes = append->nodes;
+     }
+   else
+     {
+       list->last->next = append->first;
+       ECORE_DLIST_NODE(append->first)->previous = 
ECORE_DLIST_NODE(list->last);
+       list->last = append->last;
+       list->nodes += append->nodes;
+     }
+   ecore_dlist_init(append);
+   return TRUE;
+}
+
+/**
+ * Adds a list to the very beginning of the given doubly linked list.
+ * @param   list The given doubly linked list.
+ * @param   prepend The list to prepend.
+ * @return  @c TRUE if the data is successfully prepended, @c FALSE otherwise.
+ * @ingroup Ecore_Data_DList_Add_Item_Group
+ */
+EAPI int 
+ecore_dlist_prepend_list(Ecore_DList *list, Ecore_DList *prepend)
+{
+   CHECK_PARAM_POINTER_RETURN("list", list, FALSE);
+   CHECK_PARAM_POINTER_RETURN("prepend", prepend, FALSE);
+
+   if (ecore_dlist_is_empty(prepend)) return TRUE;
+
+   if (ecore_dlist_is_empty(list))
+     {
+       list->first = prepend->first;
+       list->current = NULL;
+       list->last = prepend->last;
+       list->nodes = prepend->nodes;
+     }
+   else
+     {
+       prepend->last->next = list->first;
+       ECORE_DLIST_NODE(list->first)->previous = 
ECORE_DLIST_NODE(prepend->last);
+       list->first = prepend->first;
+       list->nodes += prepend->nodes;
+       list->index += prepend->nodes;
+     }
+   ecore_dlist_init(prepend);
+   return TRUE;
 }
 
 /**



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to