Enlightenment CVS committal

Author  : devilhorns
Project : e17
Module  : libs/ecore

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


Modified Files:
        ecore_hash.c 


Log Message:
Formatting like 'E' format.

Note: No function changes, only formatting.

===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore/ecore_hash.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -3 -r1.25 -r1.26
--- ecore_hash.c        15 Feb 2006 05:06:01 -0000      1.25
+++ ecore_hash.c        23 Jun 2006 06:39:24 -0000      1.26
@@ -18,7 +18,6 @@
                (double)hash->nodes / (double)ecore_prime_table[hash->size-1] \
                < ((double)ECORE_HASH_CHAIN_MAX * 0.375) : FALSE)
 
-
 /* Private hash manipulation functions */
 static int _ecore_hash_add_node(Ecore_Hash *hash, Ecore_Hash_Node *node);
 static Ecore_Hash_Node * _ecore_hash_get_node(Ecore_Hash *hash, void *key);
@@ -26,14 +25,14 @@
 static int _ecore_hash_decrease(Ecore_Hash *hash);
 inline int _ecore_hash_rehash(Ecore_Hash *hash, Ecore_Hash_Node **old_table, 
int old_size);
 static int _ecore_hash_bucket_destroy(Ecore_Hash_Node *list, Ecore_Free_Cb 
keyd,
-               Ecore_Free_Cb valued);
+                                     Ecore_Free_Cb valued);
 inline Ecore_Hash_Node * _ecore_hash_get_bucket(Ecore_Hash *hash,
-               Ecore_Hash_Node *bucket, void *key);
+                                               Ecore_Hash_Node *bucket, void 
*key);
 
 static Ecore_Hash_Node *_ecore_hash_node_new(void *key, void *value);
 static int _ecore_hash_node_init(Ecore_Hash_Node *node, void *key, void 
*value);
 static int _ecore_hash_node_destroy(Ecore_Hash_Node *node, Ecore_Free_Cb keyd,
-               Ecore_Free_Cb valued);
+                                   Ecore_Free_Cb valued);
 
 /**
  * @defgroup Ecore_Data_Hash_ADT_Creation_Group Hash Creation Functions
@@ -48,18 +47,20 @@
  * @return @c NULL on error, a new hash on success.
  * @ingroup Ecore_Data_Hash_ADT_Creation_Group
  */
-EAPI Ecore_Hash *ecore_hash_new(Ecore_Hash_Cb hash_func, Ecore_Compare_Cb 
compare)
+EAPI Ecore_Hash *
+ecore_hash_new(Ecore_Hash_Cb hash_func, Ecore_Compare_Cb compare)
 {
-       Ecore_Hash *new_hash = (Ecore_Hash *)malloc(sizeof(Ecore_Hash));
-       if (!new_hash)
-               return NULL;
-
-       if (!ecore_hash_init(new_hash, hash_func, compare)) {
-               FREE(new_hash);
-               return NULL;
-       }
+   Ecore_Hash *new_hash = (Ecore_Hash *)malloc(sizeof(Ecore_Hash));
+   if (!new_hash)
+     return NULL;
+
+   if (!ecore_hash_init(new_hash, hash_func, compare))
+     {
+       FREE(new_hash);
+       return NULL;
+     }
 
-       return new_hash;
+   return new_hash;
 }
 
 /**
@@ -70,19 +71,20 @@
  * @return  @c TRUE on success, @c FALSE on an error.
  * @ingroup Ecore_Data_Hash_ADT_Creation_Group
  */
-EAPI int ecore_hash_init(Ecore_Hash *hash, Ecore_Hash_Cb hash_func, 
Ecore_Compare_Cb compare)
+EAPI int
+ecore_hash_init(Ecore_Hash *hash, Ecore_Hash_Cb hash_func, Ecore_Compare_Cb 
compare)
 {
-       CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
+   CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
 
-       memset(hash, 0, sizeof(Ecore_Hash));
+   memset(hash, 0, sizeof(Ecore_Hash));
 
-       hash->hash_func = hash_func;
-       hash->compare = compare;
+   hash->hash_func = hash_func;
+   hash->compare = compare;
 
-       hash->buckets = (Ecore_Hash_Node **)calloc(ecore_prime_table[0],
-                       sizeof(Ecore_Hash_Node *));
+   hash->buckets = (Ecore_Hash_Node **)calloc(ecore_prime_table[0],
+                                             sizeof(Ecore_Hash_Node *));
 
-       return TRUE;
+   return TRUE;
 }
 
 /**
@@ -98,14 +100,15 @@
  * @return  @c TRUE on success, @c FALSE on error.
  * @ingroup Ecore_Data_Hash_ADT_Destruction_Group
  */
-EAPI int ecore_hash_set_free_key(Ecore_Hash *hash, Ecore_Free_Cb function)
+EAPI int
+ecore_hash_set_free_key(Ecore_Hash *hash, Ecore_Free_Cb function)
 {
-       CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
-       CHECK_PARAM_POINTER_RETURN("function", function, FALSE);
+   CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
+   CHECK_PARAM_POINTER_RETURN("function", function, FALSE);
 
-       hash->free_key = function;
+   hash->free_key = function;
 
-       return TRUE;
+   return TRUE;
 }
 
 /**
@@ -115,14 +118,15 @@
  * @return  @c TRUE on success, @c FALSE on error
  * @ingroup Ecore_Data_Hash_ADT_Destruction_Group
  */
-EAPI int ecore_hash_set_free_value(Ecore_Hash *hash, Ecore_Free_Cb function)
+EAPI int
+ecore_hash_set_free_value(Ecore_Hash *hash, Ecore_Free_Cb function)
 {
-       CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
-       CHECK_PARAM_POINTER_RETURN("function", function, FALSE);
+   CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
+   CHECK_PARAM_POINTER_RETURN("function", function, FALSE);
 
-       hash->free_value = function;
+   hash->free_value = function;
 
-       return TRUE;
+   return TRUE;
 }
 
 /**
@@ -139,25 +143,28 @@
  * @return  @c TRUE if successful, @c FALSE if not.
  * @ingroup Ecore_Data_Hash_ADT_Data_Group
  */
-EAPI int ecore_hash_set(Ecore_Hash *hash, void *key, void *value)
+EAPI int
+ecore_hash_set(Ecore_Hash *hash, void *key, void *value)
 {
-       int ret = FALSE;
-       Ecore_Hash_Node *node;
+   int ret = FALSE;
+   Ecore_Hash_Node *node;
 
-       CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
+   CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
 
-       node = _ecore_hash_get_node(hash, key);
-       if (node) {
-               node->value = value;
-               ret = TRUE;
-       }
-       else {
-               node = _ecore_hash_node_new(key, value);
-               if (node)
-                       ret = _ecore_hash_add_node(hash, node);
-       }
+   node = _ecore_hash_get_node(hash, key);
+   if (node)
+     {
+       node->value = value;
+       ret = TRUE;
+     }
+   else
+     {
+       node = _ecore_hash_node_new(key, value);
+       if (node)
+         ret = _ecore_hash_add_node(hash, node);
+     }
 
-       return ret;
+   return ret;
 }
 
 /**
@@ -166,35 +173,39 @@
  * @return  @c TRUE on success, @c FALSE on error.
  * @ingroup Ecore_Data_Hash_ADT_Destruction_Group
  */
-EAPI void ecore_hash_destroy(Ecore_Hash *hash)
+EAPI void 
+ecore_hash_destroy(Ecore_Hash *hash)
 {
-       unsigned int i = 0;
+   unsigned int i = 0;
 
-       CHECK_PARAM_POINTER("hash", hash);
+   CHECK_PARAM_POINTER("hash", hash);
 
-       if (hash->buckets) {
-               while (i < ecore_prime_table[hash->size]) {
-                       if (hash->buckets[i]) {
-                               Ecore_Hash_Node *bucket;
+   if (hash->buckets)
+     {
+       while (i < ecore_prime_table[hash->size])
+         {
+            if (hash->buckets[i])
+              {
+                 Ecore_Hash_Node *bucket;
 
                                /*
                                 * Remove the bucket list to avoid possible 
recursion
                                 * on the free callbacks.
                                 */
-                               bucket = hash->buckets[i];
-                               hash->buckets[i] = NULL;
-                               _ecore_hash_bucket_destroy(bucket,
-                                               hash->free_key,
-                                               hash->free_value);
-                       }
-                       i++;
-               }
-
-               FREE(hash->buckets);
-       }
-       FREE(hash);
+                 bucket = hash->buckets[i];
+                 hash->buckets[i] = NULL;
+                 _ecore_hash_bucket_destroy(bucket,
+                                            hash->free_key,
+                                            hash->free_value);
+              }
+            i++;
+         }
+
+       FREE(hash->buckets);
+     }
+   FREE(hash);
 
-       return;
+   return;
 }
 
 /**
@@ -211,26 +222,29 @@
  * @return  TRUE on success, FALSE otherwise.
  * @ingroup Ecore_Data_Hash_ADT_Traverse_Group
  */
-EAPI int ecore_hash_for_each_node(Ecore_Hash *hash, Ecore_For_Each 
for_each_func,
-                                                                               
                                 void *user_data)
+EAPI int 
+ecore_hash_for_each_node(Ecore_Hash *hash, Ecore_For_Each for_each_func, void 
*user_data)
 {
-       unsigned int i = 0;
+   unsigned int i = 0;
 
-       CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
-       CHECK_PARAM_POINTER_RETURN("for_each_func", for_each_func, FALSE);
+   CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
+   CHECK_PARAM_POINTER_RETURN("for_each_func", for_each_func, FALSE);
 
-       while (i < ecore_prime_table[hash->size]) {
-               if (hash->buckets[i]) {
-                       Ecore_Hash_Node *node;
-
-                       for (node = hash->buckets[i]; node; node = node->next) {
-                               for_each_func(node, user_data);
-                       }
-               }
-               i++;
-       }
+   while (i < ecore_prime_table[hash->size])
+     {
+       if (hash->buckets[i])
+         {
+            Ecore_Hash_Node *node;
+
+            for (node = hash->buckets[i]; node; node = node->next)
+              {
+                 for_each_func(node, user_data);
+              }
+         }
+       i++;
+     }
 
-       return TRUE;
+   return TRUE;
 }
 
 /**
@@ -239,27 +253,31 @@
  * @return  new ecore_list on success, NULL otherwise
  * @ingroup Ecore_Data_Hash_ADT_Traverse_Group
  */
-EAPI Ecore_List *ecore_hash_keys(Ecore_Hash *hash)
+EAPI Ecore_List *
+ecore_hash_keys(Ecore_Hash *hash)
 {
-       unsigned int i = 0;
-       Ecore_List *keys;
+   unsigned int i = 0;
+   Ecore_List *keys;
 
-       CHECK_PARAM_POINTER_RETURN("hash", hash, NULL);
+   CHECK_PARAM_POINTER_RETURN("hash", hash, NULL);
 
-       keys = ecore_list_new();
-       while (i < ecore_prime_table[hash->size]) {
-               if (hash->buckets[i]) {
-                       Ecore_Hash_Node *node;
-
-                       for (node = hash->buckets[i]; node; node = node->next) {
-                               ecore_list_append(keys, node->key);
-                       }
-               }
-               i++;
-       }
-       ecore_list_goto_first(keys);
+   keys = ecore_list_new();
+   while (i < ecore_prime_table[hash->size])
+     {
+       if (hash->buckets[i])
+         {
+            Ecore_Hash_Node *node;
+
+            for (node = hash->buckets[i]; node; node = node->next)
+              {
+                 ecore_list_append(keys, node->key);
+              }
+         }
+       i++;
+     }
+   ecore_list_goto_first(keys);
 
-       return keys;
+   return keys;
 }
 
 /**
@@ -269,33 +287,35 @@
 EAPI void
 ecore_hash_dump_graph(Ecore_Hash *hash)
 {
-       unsigned int i;
+   unsigned int i;
 
-       for (i = 0; i < ecore_prime_table[hash->size]; i++)
-               if (hash->buckets[i]) {
-                       int n = 0;
-                       Ecore_Hash_Node *node;
-                       for (node = hash->buckets[i]; node; node = node->next)
-                               n++;
-                       printf("%d\t%u\n", i, n);
-               }
-               else
-                       printf("%d\t0\n", i);
+   for (i = 0; i < ecore_prime_table[hash->size]; i++)
+     if (hash->buckets[i])
+       {
+         int n = 0;
+         Ecore_Hash_Node *node;
+         for (node = hash->buckets[i]; node; node = node->next)
+           n++;
+         printf("%d\t%u\n", i, n);
+       }
+   else
+     printf("%d\t0\n", i);
 }
 
 static int
 _ecore_hash_bucket_destroy(Ecore_Hash_Node *list, Ecore_Free_Cb keyd, 
Ecore_Free_Cb valued)
 {
-       Ecore_Hash_Node *node;
+   Ecore_Hash_Node *node;
 
-       CHECK_PARAM_POINTER_RETURN("list", list, FALSE);
+   CHECK_PARAM_POINTER_RETURN("list", list, FALSE);
 
-       for (node = list; node; node = list) {
-               list = list->next;
-               _ecore_hash_node_destroy(node, keyd, valued);
-       }
+   for (node = list; node; node = list)
+     {
+       list = list->next;
+       _ecore_hash_node_destroy(node, keyd, valued);
+     }
 
-       return TRUE;
+   return TRUE;
 }
 
 /*
@@ -307,27 +327,27 @@
 static int
 _ecore_hash_add_node(Ecore_Hash *hash, Ecore_Hash_Node *node)
 {
-       unsigned int hash_val;
-               
-       CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
-       CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
-
-       /* Check to see if the hash needs to be resized */
-       if (ECORE_HASH_INCREASE(hash))
-               _ecore_hash_increase(hash);
-
-       /* Compute the position in the table */
-       if (!hash->hash_func)
-               hash_val = (unsigned int)node->key % 
ecore_prime_table[hash->size];
-       else
-               hash_val = ECORE_COMPUTE_HASH(hash, node->key);
+   unsigned int hash_val;
 
-       /* Prepend the node to the list at the index position */
-       node->next = hash->buckets[hash_val];
-       hash->buckets[hash_val] = node;
-       hash->nodes++;
+   CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
+   CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
 
-       return TRUE;
+   /* Check to see if the hash needs to be resized */
+   if (ECORE_HASH_INCREASE(hash))
+     _ecore_hash_increase(hash);
+
+   /* Compute the position in the table */
+   if (!hash->hash_func)
+     hash_val = (unsigned int)node->key % ecore_prime_table[hash->size];
+   else
+     hash_val = ECORE_COMPUTE_HASH(hash, node->key);
+
+   /* Prepend the node to the list at the index position */
+   node->next = hash->buckets[hash_val];
+   hash->buckets[hash_val] = node;
+   hash->nodes++;
+
+   return TRUE;
 }
 
 /**
@@ -338,23 +358,23 @@
  * @return  The value corresponding to key on success, @c NULL otherwise.
  * @ingroup Ecore_Data_Hash_ADT_Data_Group
  */
-EAPI void *ecore_hash_get(Ecore_Hash *hash, void *key)
+EAPI void *
+ecore_hash_get(Ecore_Hash *hash, void *key)
 {
-       void *data;
-       Ecore_Hash_Node *node;
+   void *data;
+   Ecore_Hash_Node *node;
 
-       CHECK_PARAM_POINTER_RETURN("hash", hash, NULL);
+   CHECK_PARAM_POINTER_RETURN("hash", hash, NULL);
 
-       node = _ecore_hash_get_node(hash, key);
-       if (!node)
-               return NULL;
+   node = _ecore_hash_get_node(hash, key);
+   if (!node)
+     return NULL;
 
-       data = node->value;
+   data = node->value;
 
-       return data;
+   return data;
 }
 
-
 /**
  * Removes the value associated with the given key in the given hash
  * table.
@@ -364,65 +384,71 @@
  *          returned if there is an error.
  * @ingroup Ecore_Data_Hash_ADT_Data_Group
  */
-EAPI void *ecore_hash_remove(Ecore_Hash *hash, void *key)
+EAPI void *
+ecore_hash_remove(Ecore_Hash *hash, void *key)
 {
-       Ecore_Hash_Node *node = NULL;
-       Ecore_Hash_Node *list;
-       unsigned int hash_val;
-       void *ret = NULL;
-
-       CHECK_PARAM_POINTER_RETURN("hash", hash, NULL);
-
-       /* Compute the position in the table */
-       if (!hash->hash_func)
-               hash_val = (unsigned int )key % ecore_prime_table[hash->size];
+   Ecore_Hash_Node *node = NULL;
+   Ecore_Hash_Node *list;
+   unsigned int hash_val;
+   void *ret = NULL;
+
+   CHECK_PARAM_POINTER_RETURN("hash", hash, NULL);
+
+   /* Compute the position in the table */
+   if (!hash->hash_func)
+     hash_val = (unsigned int )key % ecore_prime_table[hash->size];
+   else
+     hash_val = ECORE_COMPUTE_HASH(hash, key);
+
+   /*
+    * If their is a list that could possibly hold the key/value pair
+    * traverse it and remove the hash node.
+    */
+   if (hash->buckets[hash_val])
+     {
+       list = hash->buckets[hash_val];
+
+       /*
+        * Traverse the list to find the specified key
+        */
+       node = list;
+       if (hash->compare)
+         {
+            while ((node) && (hash->compare(node->key, key) != 0))
+              {
+                 list = node;
+                 node = node->next;
+              }
+         }
        else
-               hash_val = ECORE_COMPUTE_HASH(hash, key);
-
-       /*
-        * If their is a list that could possibly hold the key/value pair
-        * traverse it and remove the hash node.
-        */
-       if (hash->buckets[hash_val]) {
-               list = hash->buckets[hash_val];
+         {
+            while ((node) && (node->key != key))
+              {
+                 list = node;
+                 node = node->next;
+              }
+         }
+
+       /*
+        * Remove the node with the matching key and free it's memory
+        */
+       if (node)
+         {
+            if (list == node)
+              hash->buckets[hash_val] = node->next;
+            else
+              list->next = node->next;
+            ret = node->value;
+            node->value = NULL;
+            _ecore_hash_node_destroy(node, hash->free_key, NULL);
+            hash->nodes--;
+         }
+     }
 
-               /*
-                * Traverse the list to find the specified key
-                */
-               node = list;
-               if (hash->compare) {
-                       while ((node) && (hash->compare(node->key, key) != 0)) {
-                               list = node;
-                               node = node->next;
-                       }
-               }
-               else {
-                       while ((node) && (node->key != key)) {
-                               list = node;
-                               node = node->next;
-                       }
-               }
-
-               /*
-                * Remove the node with the matching key and free it's memory
-                */
-               if (node) {
-                       if (list == node)
-                               hash->buckets[hash_val] = node->next;
-                       else
-                               list->next = node->next;
-                       ret = node->value;
-                       node->value = NULL;
-                       _ecore_hash_node_destroy(node, hash->free_key,
-                                                NULL);
-                       hash->nodes--;
-               }
-       }
+   if (ECORE_HASH_REDUCE(hash))
+     _ecore_hash_decrease(hash);
 
-       if (ECORE_HASH_REDUCE(hash))
-               _ecore_hash_decrease(hash);
-
-       return ret;
+   return ret;
 }
 
 /*
@@ -434,35 +460,38 @@
 static Ecore_Hash_Node *
 _ecore_hash_get_node(Ecore_Hash *hash, void *key)
 {
-       unsigned int hash_val;
-       Ecore_Hash_Node *node = NULL;
+   unsigned int hash_val;
+   Ecore_Hash_Node *node = NULL;
 
-       CHECK_PARAM_POINTER_RETURN("hash", hash, NULL);
+   CHECK_PARAM_POINTER_RETURN("hash", hash, NULL);
 
-       if (!hash->buckets) {
-               return NULL;
-       }
-
-       /* Compute the position in the table */
-       if (!hash->hash_func)
-               hash_val = (unsigned int )key % ecore_prime_table[hash->size];
-       else
-               hash_val = ECORE_COMPUTE_HASH(hash, key);
+   if (!hash->buckets)
+     {
+       return NULL;
+     }
+
+   /* Compute the position in the table */
+   if (!hash->hash_func)
+     hash_val = (unsigned int )key % ecore_prime_table[hash->size];
+   else
+     hash_val = ECORE_COMPUTE_HASH(hash, key);
+
+   /* Grab the bucket at the specified position */
+   if (hash->buckets[hash_val])
+     {
+       node = _ecore_hash_get_bucket(hash, hash->buckets[hash_val], key);
+       /*
+        * Move matched node to the front of the list as it's likely
+        * to be searched for again soon.
+        */
+       if (node && node != hash->buckets[hash_val])
+         {
+            node->next = hash->buckets[hash_val];
+            hash->buckets[hash_val] = node;
+         }
+     }
 
-       /* Grab the bucket at the specified position */
-       if (hash->buckets[hash_val]) {
-               node = _ecore_hash_get_bucket(hash, hash->buckets[hash_val], 
key);
-               /*
-                * Move matched node to the front of the list as it's likely
-                * to be searched for again soon.
-                */
-               if (node && node != hash->buckets[hash_val]) {
-                       node->next = hash->buckets[hash_val];
-                       hash->buckets[hash_val] = node;
-               }
-       }
-
-       return node;
+   return node;
 }
 
 /*
@@ -475,37 +504,42 @@
 inline Ecore_Hash_Node *
 _ecore_hash_get_bucket(Ecore_Hash *hash, Ecore_Hash_Node *bucket, void *key)
 {
-       Ecore_Hash_Node *prev = NULL;
-       Ecore_Hash_Node *node = NULL;
-
-       /*
-        * Traverse the list to find the desired node, if the node is in the
-        * list, then return the node.
-        */
-       if (hash->compare) {
-               for (node = bucket; node; node = node->next) {
-                       if (hash->compare(node->key, key) == 0)
-                               break;
-                       prev = node;
-               }
-       }
-       else {
-               for (node = bucket; node; node = node->next) {
-                       if (node->key == key)
-                               break;
-                       prev = node;
-               }
-       }
+   Ecore_Hash_Node *prev = NULL;
+   Ecore_Hash_Node *node = NULL;
 
-       /*
-        * Remove node from the list to replace it at the beginning.
-        */
-       if (node && prev) {
-               prev->next = node->next;
-               node->next = NULL;
-       }
+   /*
+    * Traverse the list to find the desired node, if the node is in the
+    * list, then return the node.
+    */
+   if (hash->compare)
+     {
+       for (node = bucket; node; node = node->next)
+         {
+            if (hash->compare(node->key, key) == 0)
+              break;
+            prev = node;
+         }
+     }
+   else
+     {
+       for (node = bucket; node; node = node->next)
+         {
+            if (node->key == key)
+              break;
+            prev = node;
+         }
+     }
+
+   /*
+    * Remove node from the list to replace it at the beginning.
+    */
+   if (node && prev)
+     {
+       prev->next = node->next;
+       node->next = NULL;
+     }
 
-       return node;
+   return node;
 }
 
 /*
@@ -516,51 +550,52 @@
 static int
 _ecore_hash_increase(Ecore_Hash *hash)
 {
-       void *old;
+   void *old;
 
-       CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
+   CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
 
-       /* Max size reached so return FALSE */
-       if (hash->size == PRIME_TABLE_MAX)
-               return FALSE;
-
-       /*
-        * Increase the size of the hash and save a pointer to the old data
-        */
-       hash->size++;
-       old = hash->buckets;
-
-       /*
-        * Allocate a new bucket area, of the new larger size
-        */
-       hash->buckets = calloc(ecore_prime_table[hash->size],
-                       sizeof(Ecore_Hash_Node *));
-
-       /*
-        * Make sure the allocation succeeded, if not replace the old data and
-        * return a failure.
-        */
-       if (!hash->buckets) {
-               hash->buckets = old;
-               hash->size--;
-               return FALSE;
-       }
-       hash->nodes = 0;
-
-       /*
-        * Now move all of the old data into the new bucket area
-        */
-       if (_ecore_hash_rehash(hash, old, hash->size - 1)) {
-               FREE(old);
-               return TRUE;
-       }
+   /* Max size reached so return FALSE */
+   if (hash->size == PRIME_TABLE_MAX)
+     return FALSE;
+
+   /*
+    * Increase the size of the hash and save a pointer to the old data
+    */
+   hash->size++;
+   old = hash->buckets;
+
+   /*
+    * Allocate a new bucket area, of the new larger size
+    */
+   hash->buckets = calloc(ecore_prime_table[hash->size], 
sizeof(Ecore_Hash_Node *));
+
+   /*
+    * Make sure the allocation succeeded, if not replace the old data and
+    * return a failure.
+    */
+   if (!hash->buckets)
+     {
+       hash->buckets = old;
+       hash->size--;
+       return FALSE;
+     }
+   hash->nodes = 0;
 
-       /*
-        * Free the old buckets regardless of success.
-        */
+   /*
+    * Now move all of the old data into the new bucket area
+    */
+   if (_ecore_hash_rehash(hash, old, hash->size - 1))
+     {
        FREE(old);
+       return TRUE;
+     }
 
-       return FALSE;
+   /*
+    * Free the old buckets regardless of success.
+    */
+   FREE(old);
+
+   return FALSE;
 }
 
 /*
@@ -571,43 +606,45 @@
 static int
 _ecore_hash_decrease(Ecore_Hash *hash)
 {
-       Ecore_Hash_Node **old;
+   Ecore_Hash_Node **old;
 
-       CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
+   CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
 
-       if (ecore_prime_table[hash->size] == PRIME_MIN)
-               return FALSE;
+   if (ecore_prime_table[hash->size] == PRIME_MIN)
+     return FALSE;
 
-       /*
-        * Decrease the hash size and store a pointer to the old data
-        */
-       hash->size--;
-       old = hash->buckets;
+   /*
+    * Decrease the hash size and store a pointer to the old data
+    */
+   hash->size--;
+   old = hash->buckets;
+
+   /*
+    * Allocate a new area to store the data
+    */
+   hash->buckets = (Ecore_Hash_Node **)calloc(ecore_prime_table[hash->size],
+                                             sizeof(Ecore_Hash_Node *));
+
+   /*
+    * Make sure allocation succeeded otherwise rreturn to the previous
+    * state
+    */
+   if (!hash->buckets)
+     {
+       hash->buckets = old;
+       hash->size++;
+       return FALSE;
+     }
 
-       /*
-        * Allocate a new area to store the data
-        */
-       hash->buckets = (Ecore_Hash_Node 
**)calloc(ecore_prime_table[hash->size],
-                       sizeof(Ecore_Hash_Node *));
+   hash->nodes = 0;
 
-       /*
-        * Make sure allocation succeeded otherwise rreturn to the previous
-        * state
-        */
-       if (!hash->buckets) {
-               hash->buckets = old;
-               hash->size++;
-               return FALSE;
-       }
-
-       hash->nodes = 0;
-
-       if (_ecore_hash_rehash(hash, old, hash->size - 1)) {
-               FREE(old);
-               return TRUE;
-       }
+   if (_ecore_hash_rehash(hash, old, hash->size - 1))
+     {
+       FREE(old);
+       return TRUE;
+     }
 
-       return FALSE;
+   return FALSE;
 }
 
 /*
@@ -619,23 +656,24 @@
 inline int
 _ecore_hash_rehash(Ecore_Hash *hash, Ecore_Hash_Node **old_table, int old_size)
 {
-       unsigned int i;
-       Ecore_Hash_Node *old;
+   unsigned int i;
+   Ecore_Hash_Node *old;
 
-       CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
-       CHECK_PARAM_POINTER_RETURN("old_table", old_table, FALSE);
+   CHECK_PARAM_POINTER_RETURN("hash", hash, FALSE);
+   CHECK_PARAM_POINTER_RETURN("old_table", old_table, FALSE);
 
-       for (i = 0; i < ecore_prime_table[old_size]; i++) {
-               /* Hash into a new list to avoid loops of rehashing the same
-                * nodes */
-               while ((old = old_table[i])) {
-                       old_table[i] = old->next;
-                       old->next = NULL;
-                       _ecore_hash_add_node(hash, old);
-               }
-       }
+   for (i = 0; i < ecore_prime_table[old_size]; i++)
+     {
+       /* Hash into a new list to avoid loops of rehashing the same nodes */
+       while ((old = old_table[i]))
+         {
+            old_table[i] = old->next;
+            old->next = NULL;
+            _ecore_hash_add_node(hash, old);
+         }
+     }
 
-       return TRUE;
+   return TRUE;
 }
 
 /*
@@ -647,18 +685,19 @@
 static Ecore_Hash_Node *
 _ecore_hash_node_new(void *key, void *value)
 {
-       Ecore_Hash_Node *node;
+   Ecore_Hash_Node *node;
+
+   node = (Ecore_Hash_Node *)malloc(sizeof(Ecore_Hash_Node));
+   if (!node)
+     return NULL;
 
-       node = (Ecore_Hash_Node *)malloc(sizeof(Ecore_Hash_Node));
-       if (!node)
-               return NULL;
-
-       if (!_ecore_hash_node_init(node, key, value)) {
-               FREE(node);
-               return NULL;
-       }
+   if (!_ecore_hash_node_init(node, key, value))
+     {
+       FREE(node);
+       return NULL;
+     }
 
-       return node;
+   return node;
 }
 
 /*
@@ -671,12 +710,12 @@
 static int
 _ecore_hash_node_init(Ecore_Hash_Node *node, void *key, void *value)
 {
-       CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
+   CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
 
-       node->key = key;
-       node->value = value;
+   node->key = key;
+   node->value = value;
 
-       return TRUE;
+   return TRUE;
 }
 
 /*
@@ -687,18 +726,17 @@
  * @return Returns TRUE on success, FALSE on error
  */
 static int
-_ecore_hash_node_destroy(Ecore_Hash_Node *node, Ecore_Free_Cb keyd,
-               Ecore_Free_Cb valued)
+_ecore_hash_node_destroy(Ecore_Hash_Node *node, Ecore_Free_Cb keyd, 
Ecore_Free_Cb valued)
 {
-       CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
+   CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
 
-       if (keyd)
-               keyd(node->key);
+   if (keyd)
+     keyd(node->key);
 
-       if (valued)
-               valued(node->value);
+   if (valued)
+     valued(node->value);
 
-       FREE(node);
+   FREE(node);
 
-       return TRUE;
+   return TRUE;
 }



Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to