Enlightenment CVS committal
Author : devilhorns
Project : e17
Module : libs/ecore
Dir : e17/libs/ecore/src/lib/ecore
Modified Files:
ecore_tree.c
Log Message:
Format to 'E' style.
Note: No functional changes, only formatting.
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore/ecore_tree.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -3 -r1.9 -r1.10
--- ecore_tree.c 12 Jan 2006 03:01:58 -0000 1.9
+++ ecore_tree.c 23 Jun 2006 06:42:35 -0000 1.10
@@ -18,29 +18,31 @@
/* Fucntions for executing a specified function on each node of a tree */
static int tree_for_each_node(Ecore_Tree_Node * node, Ecore_For_Each
for_each_func,
- void *user_data);
+ void *user_data);
static int tree_for_each_node_value(Ecore_Tree_Node * node,
- Ecore_For_Each for_each_func, void *user_data);
+ Ecore_For_Each for_each_func, void
*user_data);
/**
* @brief Allocate a new tree structure.
* @param compare_func: function used to compare the two values
* @return Returns NULL if the operation fails, otherwise the new tree
*/
-EAPI Ecore_Tree *ecore_tree_new(Ecore_Compare_Cb compare_func)
+EAPI Ecore_Tree *
+ecore_tree_new(Ecore_Compare_Cb compare_func)
{
- Ecore_Tree *new_tree;
+ Ecore_Tree *new_tree;
- new_tree = ECORE_TREE(malloc(sizeof(Ecore_Tree)));
- if (!new_tree)
- return NULL;
+ new_tree = ECORE_TREE(malloc(sizeof(Ecore_Tree)));
+ if (!new_tree)
+ return NULL;
+
+ if (!ecore_tree_init(new_tree, compare_func))
+ {
+ IF_FREE(new_tree);
+ return NULL;
+ }
- if (!ecore_tree_init(new_tree, compare_func)) {
- IF_FREE(new_tree);
- return NULL;
- }
-
- return new_tree;
+ return new_tree;
}
/**
@@ -49,18 +51,19 @@
* @param compare_func: the function used to compare node keys
* @return Returns TRUE on successful initialization, FALSE on an error
*/
-EAPI int ecore_tree_init(Ecore_Tree * new_tree, Ecore_Compare_Cb compare_func)
+EAPI int
+ecore_tree_init(Ecore_Tree *new_tree, Ecore_Compare_Cb compare_func)
{
- CHECK_PARAM_POINTER_RETURN("new_tree", new_tree, FALSE);
+ CHECK_PARAM_POINTER_RETURN("new_tree", new_tree, FALSE);
- memset(new_tree, 0, sizeof(Ecore_Tree));
+ memset(new_tree, 0, sizeof(Ecore_Tree));
- if (!compare_func)
- new_tree->compare_func = ecore_direct_compare;
- else
- new_tree->compare_func = compare_func;
+ if (!compare_func)
+ new_tree->compare_func = ecore_direct_compare;
+ else
+ new_tree->compare_func = compare_func;
- return TRUE;
+ return TRUE;
}
/*
@@ -69,53 +72,57 @@
* @param free_func: the function that will be passed the node being freed
* @return Returns TRUE on successful set, FALSE otherwise.
*/
-EAPI int ecore_tree_set_free_cb(Ecore_Tree * tree, Ecore_Free_Cb free_func)
+EAPI int
+ecore_tree_set_free_cb(Ecore_Tree *tree, Ecore_Free_Cb free_func)
{
- CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
+ CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
- tree->free_func = free_func;
+ tree->free_func = free_func;
- return TRUE;
+ return TRUE;
}
/*
* @brief Initialize a new tree node
* @return Returns FALSE if the operation fails, otherwise TRUE
*/
-EAPI int ecore_tree_node_init(Ecore_Tree_Node * new_node)
+EAPI int
+ecore_tree_node_init(Ecore_Tree_Node *new_node)
{
- CHECK_PARAM_POINTER_RETURN("new_node", new_node, FALSE);
+ CHECK_PARAM_POINTER_RETURN("new_node", new_node, FALSE);
- new_node->key = NULL;
- new_node->value = NULL;
+ new_node->key = NULL;
+ new_node->value = NULL;
- new_node->parent = NULL;
- new_node->right_child = NULL;
- new_node->left_child = NULL;
+ new_node->parent = NULL;
+ new_node->right_child = NULL;
+ new_node->left_child = NULL;
- new_node->max_left = new_node->max_right = 0;
+ new_node->max_left = new_node->max_right = 0;
- return TRUE;
+ return TRUE;
}
/*
* @brief Allocate a new tree node
* @return Returns NULL if the operation fails, otherwise the new node.
*/
-EAPI Ecore_Tree_Node *ecore_tree_node_new()
+EAPI Ecore_Tree_Node *
+ecore_tree_node_new()
{
- Ecore_Tree_Node *new_node;
-
- new_node = ECORE_TREE_NODE(malloc(sizeof(Ecore_Tree_Node)));
- if (!new_node)
- return NULL;
+ Ecore_Tree_Node *new_node;
- if (!ecore_tree_node_init(new_node)) {
- IF_FREE(new_node);
- return NULL;
- }
+ new_node = ECORE_TREE_NODE(malloc(sizeof(Ecore_Tree_Node)));
+ if (!new_node)
+ return NULL;
+
+ if (!ecore_tree_node_init(new_node))
+ {
+ IF_FREE(new_node);
+ return NULL;
+ }
- return new_node;
+ return new_node;
}
/*
@@ -126,16 +133,17 @@
*
* If you don't want the children free'd then you need to remove the node
first.
*/
-EAPI int ecore_tree_node_destroy(Ecore_Tree_Node * node, Ecore_Free_Cb
data_free)
+EAPI int
+ecore_tree_node_destroy(Ecore_Tree_Node *node, Ecore_Free_Cb data_free)
{
- CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
+ CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
- if (data_free)
- data_free(node->value);
+ if (data_free)
+ data_free(node->value);
- FREE(node);
+ FREE(node);
- return TRUE;
+ return TRUE;
}
/*
@@ -144,14 +152,14 @@
* @param value: the value to set the node to.
* @return Returns TRUE if the node is set successfully, FALSE if not.
*/
-EAPI int ecore_tree_node_value_set(Ecore_Tree_Node * node, void *value)
+EAPI int
+ecore_tree_node_value_set(Ecore_Tree_Node *node, void *value)
{
- CHECK_PARAM_POINTER_RETURN("node", node,
- FALSE);
+ CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
- node->value = value;
+ node->value = value;
- return TRUE;
+ return TRUE;
}
/*
@@ -159,14 +167,15 @@
* @param node: the node that contains the desired value
* @return Returns NULL if an error, otherwise the value associated with node
*/
-EAPI void *ecore_tree_node_value_get(Ecore_Tree_Node * node)
+EAPI void *
+ecore_tree_node_value_get(Ecore_Tree_Node *node)
{
- void *ret;
+ void *ret;
- CHECK_PARAM_POINTER_RETURN("node", node, NULL);
- ret = node->value;
+ CHECK_PARAM_POINTER_RETURN("node", node, NULL);
+ ret = node->value;
- return ret;
+ return ret;
}
/*
@@ -175,29 +184,31 @@
* @param key: the value to set it's key to.
* @return Returns TRUE if the node is set successfully, FALSE if not.
*/
-EAPI int ecore_tree_node_key_set(Ecore_Tree_Node * node, void *key)
+EAPI int
+ecore_tree_node_key_set(Ecore_Tree_Node *node, void *key)
{
- CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
+ CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
- node->key = key;
+ node->key = key;
- return TRUE;
+ return TRUE;
}
/*
- * @brief Get the value of the node's key
+ * @brief Get the value of the node's key
* @param node: the node that contains the desired key
*
* @return Returns NULL if an error occurs, otherwise the key is returned
*/
-EAPI void *ecore_tree_node_key_get(Ecore_Tree_Node * node)
+EAPI void *
+ecore_tree_node_key_get(Ecore_Tree_Node *node)
{
- void *ret;
+ void *ret;
- CHECK_PARAM_POINTER_RETURN("node", node, NULL);
- ret = node->key;
+ CHECK_PARAM_POINTER_RETURN("node", node, NULL);
+ ret = node->key;
- return ret;
+ return ret;
}
/**
@@ -206,20 +217,22 @@
*
* @return Returns TRUE if tree destroyed successfully, FALSE if not.
*/
-EAPI int ecore_tree_destroy(Ecore_Tree * tree)
+EAPI int
+ecore_tree_destroy(Ecore_Tree *tree)
{
- Ecore_Tree_Node *node;
+ Ecore_Tree_Node *node;
- CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
+ CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
- while ((node = tree->tree)) {
- ecore_tree_remove_node(tree, node);
- ecore_tree_node_destroy(node, tree->free_func);
- }
+ while ((node = tree->tree))
+ {
+ ecore_tree_remove_node(tree, node);
+ ecore_tree_node_destroy(node, tree->free_func);
+ }
- FREE(tree);
+ FREE(tree);
- return TRUE;
+ return TRUE;
}
/**
@@ -229,15 +242,16 @@
*
* @return Returns the node corresponding to the key if found, otherwise NULL.
*/
-EAPI Ecore_Tree_Node *ecore_tree_get_node(Ecore_Tree * tree, void *key)
+EAPI Ecore_Tree_Node *
+ecore_tree_get_node(Ecore_Tree *tree, void *key)
{
- Ecore_Tree_Node *ret;
+ Ecore_Tree_Node *ret;
- CHECK_PARAM_POINTER_RETURN("tree", tree, NULL);
+ CHECK_PARAM_POINTER_RETURN("tree", tree, NULL);
- ret = tree_node_find(tree, key);
+ ret = tree_node_find(tree, key);
- return ret;
+ return ret;
}
/**
@@ -246,17 +260,18 @@
* @param key: the key to search for in @a tree
* @return Returns the value corresponding to the key if found, otherwise NULL.
*/
-EAPI void *ecore_tree_get(Ecore_Tree * tree, void *key)
+EAPI void *
+ecore_tree_get(Ecore_Tree *tree, void *key)
{
- void *ret;
- Ecore_Tree_Node *node;
+ void *ret;
+ Ecore_Tree_Node *node;
- CHECK_PARAM_POINTER_RETURN("tree", tree, NULL);
+ CHECK_PARAM_POINTER_RETURN("tree", tree, NULL);
- node = tree_node_find(tree, key);
- ret = (node ? node->value : NULL);
+ node = tree_node_find(tree, key);
+ ret = (node ? node->value : NULL);
- return ret;
+ return ret;
}
/**
@@ -266,25 +281,25 @@
* @return NULL if no valid nodes, otherwise the node greater than or
* equal to the key
*/
-EAPI void *ecore_tree_get_closest_larger(Ecore_Tree * tree, void *key)
+EAPI void *
+ecore_tree_get_closest_larger(Ecore_Tree *tree, void *key)
{
- Ecore_Tree_Node *node;
+ Ecore_Tree_Node *node;
- CHECK_PARAM_POINTER_RETURN("tree", tree, NULL);
+ CHECK_PARAM_POINTER_RETURN("tree", tree, NULL);
- node = tree_node_find(tree, key);
- if (node)
- return node;
+ node = tree_node_find(tree, key);
+ if (node)
+ return node;
- node = tree_node_find_parent(tree, key);
- if (!node) {
- return NULL;
- }
+ node = tree_node_find_parent(tree, key);
+ if (!node)
+ return NULL;
- if (tree->compare_func(node->key, key) < 0)
- return NULL;
+ if (tree->compare_func(node->key, key) < 0)
+ return NULL;
- return node;
+ return node;
}
/**
@@ -293,21 +308,22 @@
* @param key the key to search for in tree
* @return Returns NULL if no valid nodes, otherwise the node <= key
*/
-EAPI void *ecore_tree_get_closest_smaller(Ecore_Tree * tree, void *key)
+EAPI void *
+ecore_tree_get_closest_smaller(Ecore_Tree *tree, void *key)
{
- Ecore_Tree_Node *node;
+ Ecore_Tree_Node *node;
- CHECK_PARAM_POINTER_RETURN("tree", tree, NULL);
+ CHECK_PARAM_POINTER_RETURN("tree", tree, NULL);
- node = tree_node_find(tree, key);
- if (node)
- return node;
+ node = tree_node_find(tree, key);
+ if (node)
+ return node;
- node = tree_node_find_parent(tree, key);
- if (node)
- node = node->right_child;
+ node = tree_node_find_parent(tree, key);
+ if (node)
+ node = node->right_child;
- return node;
+ return node;
}
/**
@@ -317,25 +333,27 @@
* @param value Value to set the found node.
* @return TRUE if successful, FALSE if not.
*/
-EAPI int ecore_tree_set(Ecore_Tree * tree, void *key, void *value)
+EAPI int
+ecore_tree_set(Ecore_Tree *tree, void *key, void *value)
{
- Ecore_Tree_Node *node = NULL;
+ Ecore_Tree_Node *node = NULL;
- CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
+ CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
- node = tree_node_find(tree, key);
- if (!node) {
- node = ecore_tree_node_new();
- ecore_tree_node_key_set(node, key);
- if (!ecore_tree_add_node(tree, node))
- return FALSE;
- }
- ecore_tree_node_value_set(node, value);
+ node = tree_node_find(tree, key);
+ if (!node)
+ {
+ node = ecore_tree_node_new();
+ ecore_tree_node_key_set(node, key);
+ if (!ecore_tree_add_node(tree, node))
+ return FALSE;
+ }
+ ecore_tree_node_value_set(node, value);
- for (; node; node = node->parent)
- tree_node_balance(tree, node);
+ for (; node; node = node->parent)
+ tree_node_balance(tree, node);
- return TRUE;
+ return TRUE;
}
/**
@@ -344,141 +362,156 @@
* @param node The node to add to @a tree.
* @return TRUE on a successful add, FALSE otherwise.
*/
-EAPI int ecore_tree_add_node(Ecore_Tree * tree, Ecore_Tree_Node * node)
+EAPI int
+ecore_tree_add_node(Ecore_Tree *tree, Ecore_Tree_Node *node)
{
- Ecore_Tree_Node *travel = NULL;
+ Ecore_Tree_Node *travel = NULL;
- CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
- CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
+ CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
+ CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
- /* Find where to put this new node. */
- if (!tree->tree) {
- tree->tree = node;
- } else {
- travel = tree_node_find_parent(tree, node->key);
- node->parent = travel;
-
- /* The node is less than travel */
- if (tree->compare_func(node->key, travel->key) < 0) {
- travel->right_child = node;
- travel->max_left = 1;
- /* The node is greater than travel */
- } else {
- travel->left_child = node;
- travel->max_right = 1;
- }
- }
+ /* Find where to put this new node. */
+ if (!tree->tree)
+ tree->tree = node;
+ else
+ {
+ travel = tree_node_find_parent(tree, node->key);
+ node->parent = travel;
+
+ /* The node is less than travel */
+ if (tree->compare_func(node->key, travel->key) < 0)
+ {
+ travel->right_child = node;
+ travel->max_left = 1;
+ /* The node is greater than travel */
+ }
+ else
+ {
+ travel->left_child = node;
+ travel->max_right = 1;
+ }
+ }
- return TRUE;
+ return TRUE;
}
-
/**
* Remove the node from the tree.
* @param tree The tree to remove @a node from.
* @param node The node to remove from @a tree.
* @return TRUE on a successful remove, FALSE otherwise.
*/
-EAPI int ecore_tree_remove_node(Ecore_Tree * tree, Ecore_Tree_Node * node)
+EAPI int
+ecore_tree_remove_node(Ecore_Tree *tree, Ecore_Tree_Node *node)
{
- Ecore_Tree_Node *traverse;
+ Ecore_Tree_Node *traverse;
+
+ CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
+ CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
- CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
- CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
+ /*
+ * Find the nearest value to the balanced one.
+ */
+ if (node->left_child)
+ {
+ traverse = node->left_child;
+
+ /* Now work our way down right side of the traverse node.
+ * This will give us the node with the next closest value
+ * to the current node. If traverse had no right node, then
+ * this will stop at node's left node. */
+ while (traverse->right_child)
+ {
+ traverse = traverse->right_child;
+ }
/*
- * Find the nearest value to the balanced one.
+ * Hook any dropped leaves into the moved nodes spot
*/
- if (node->left_child) {
- traverse = node->left_child;
-
- /* Now work our way down right side of the traverse node.
- * This will give us the node with the next closest value
- * to the current node. If traverse had no right node, then
- * this will stop at node's left node. */
- while (traverse->right_child) {
- traverse = traverse->right_child;
- }
-
- /*
- * Hook any dropped leaves into the moved nodes spot
- */
- if (traverse->parent)
- traverse->parent->left_child = traverse->left_child;
- }
- else if (node->right_child) {
- traverse = node->right_child;
-
- /* Now work our way down left side of the traverse node.
- * This will give us the node with the next closest value
- * to the current node. If traverse had no left node, then
- * this will stop at node's right node. */
- while (traverse->left_child) {
- traverse = traverse->left_child;
- }
-
- /*
- * Hook any dropped leaves into the moved nodes spot
- */
- if (traverse->right_child)
- traverse->right_child->parent = traverse->parent;
-
- if (traverse->parent)
- traverse->parent->right_child = traverse->right_child;
- else
- tree->tree = traverse->right_child;
- }
- else
- traverse = NULL;
+ if (traverse->parent)
+ traverse->parent->left_child = traverse->left_child;
+ }
+ else if (node->right_child)
+ {
+ traverse = node->right_child;
+
+ /* Now work our way down left side of the traverse node.
+ * This will give us the node with the next closest value
+ * to the current node. If traverse had no left node, then
+ * this will stop at node's right node. */
+ while (traverse->left_child)
+ {
+ traverse = traverse->left_child;
+ }
- if (traverse) {
+ /*
+ * Hook any dropped leaves into the moved nodes spot
+ */
+ if (traverse->right_child)
+ traverse->right_child->parent = traverse->parent;
- /*
- * Ensure that we don't get a recursive reference.
- */
- if (node->right_child && node->right_child != traverse) {
- node->right_child->parent = traverse;
- traverse->right_child = node->right_child;
- }
-
- if (node->left_child && node->left_child != traverse) {
- node->left_child->parent = traverse;
- traverse->left_child = node->left_child;
- }
-
- /*
- * Unlink the node to be moved from it's parent.
- */
- if (traverse->parent) {
- if (traverse->parent->left_child == traverse)
- traverse->parent->left_child = NULL;
- else
- traverse->parent->right_child = NULL;
- }
- traverse->parent = node->parent;
- }
-
- if (node->parent) {
- if (node == node->parent->left_child)
- node->parent->left_child = traverse;
- else
- node->parent->right_child = traverse;
- }
+ if (traverse->parent)
+ traverse->parent->right_child = traverse->right_child;
+ else
+ tree->tree = traverse->right_child;
+ }
+ else
+ traverse = NULL;
- if (tree->tree == node)
- tree->tree = traverse;
+ if (traverse)
+ {
- node->parent = node->left_child = node->right_child = NULL;
+ /*
+ * Ensure that we don't get a recursive reference.
+ */
+ if (node->right_child && node->right_child != traverse)
+ {
+ node->right_child->parent = traverse;
+ traverse->right_child = node->right_child;
+ }
+
+ if (node->left_child && node->left_child != traverse)
+ {
+ node->left_child->parent = traverse;
+ traverse->left_child = node->left_child;
+ }
/*
- * Rebalance the tree to ensure short search paths.
+ * Unlink the node to be moved from it's parent.
*/
- while (traverse) {
- tree_node_balance(tree, traverse);
- traverse = traverse->parent;
- }
+ if (traverse->parent)
+ {
+ if (traverse->parent->left_child == traverse)
+ traverse->parent->left_child = NULL;
+ else
+ traverse->parent->right_child = NULL;
+ }
+ traverse->parent = node->parent;
+ }
+
+ if (node->parent)
+ {
+ if (node == node->parent->left_child)
+ node->parent->left_child = traverse;
+ else
+ node->parent->right_child = traverse;
+ }
+
+ if (tree->tree == node)
+ tree->tree = traverse;
+
+ node->parent = node->left_child = node->right_child = NULL;
- return TRUE;
+ /*
+ * Rebalance the tree to ensure short search paths.
+ */
+ while (traverse)
+ {
+ tree_node_balance(tree, traverse);
+ traverse = traverse->parent;
+ }
+
+ return TRUE;
}
/**
@@ -487,25 +520,26 @@
* @param key The key to remove from @a tree.
* @return TRUE on a successful remove, FALSE otherwise.
*/
-EAPI int ecore_tree_remove(Ecore_Tree * tree, void *key)
+EAPI int
+ecore_tree_remove(Ecore_Tree *tree, void *key)
{
- Ecore_Tree_Node *node;
+ Ecore_Tree_Node *node;
- CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
- if (!tree->tree)
- return FALSE;
+ CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
+ if (!tree->tree)
+ return FALSE;
- /* Find the node we need to remove */
- node = tree_node_find(tree, key);
- if (!node)
- return FALSE;
+ /* Find the node we need to remove */
+ node = tree_node_find(tree, key);
+ if (!node)
+ return FALSE;
- if (!ecore_tree_remove_node(tree, node))
- return FALSE;
+ if (!ecore_tree_remove_node(tree, node))
+ return FALSE;
- ecore_tree_node_destroy(node, tree->free_func);
+ ecore_tree_node_destroy(node, tree->free_func);
- return TRUE;
+ return TRUE;
}
/**
@@ -513,14 +547,15 @@
* @param tree: the tree to check for nodes
* @return Returns TRUE if no nodes exist, FALSE otherwise
*/
-EAPI int ecore_tree_is_empty(Ecore_Tree * tree)
+EAPI int
+ecore_tree_is_empty(Ecore_Tree *tree)
{
- CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
+ CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
- if (!tree->tree)
- return TRUE;
+ if (!tree->tree)
+ return TRUE;
- return FALSE;
+ return FALSE;
}
/**
@@ -530,16 +565,16 @@
* @param user_data: data passed to each for_each_func call
* @return Returns TRUE on success, FALSE on failure.
*/
-EAPI int ecore_tree_for_each_node_value(Ecore_Tree * tree,
- Ecore_For_Each for_each_func, void *user_data)
+EAPI int
+ecore_tree_for_each_node_value(Ecore_Tree *tree, Ecore_For_Each for_each_func,
void *user_data)
{
- CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
- CHECK_PARAM_POINTER_RETURN("for_each_func", for_each_func, FALSE);
+ CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
+ CHECK_PARAM_POINTER_RETURN("for_each_func", for_each_func, FALSE);
- if (!tree->tree)
- return FALSE;
+ if (!tree->tree)
+ return FALSE;
- return tree_for_each_node_value(tree->tree, for_each_func, user_data);
+ return tree_for_each_node_value(tree->tree, for_each_func, user_data);
}
/**
@@ -549,178 +584,191 @@
* @param user_data: data passed to each for_each_func call
* @return Returns TRUE on success, FALSE on failure.
*/
-EAPI int ecore_tree_for_each_node(Ecore_Tree * tree, Ecore_For_Each
for_each_func,
- void *user_data)
+EAPI int
+ecore_tree_for_each_node(Ecore_Tree *tree, Ecore_For_Each for_each_func, void
*user_data)
{
- CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
- CHECK_PARAM_POINTER_RETURN("for_each_func", for_each_func, FALSE);
+ CHECK_PARAM_POINTER_RETURN("tree", tree, FALSE);
+ CHECK_PARAM_POINTER_RETURN("for_each_func", for_each_func, FALSE);
- if (!tree->tree)
- return FALSE;
+ if (!tree->tree)
+ return FALSE;
- return tree_for_each_node(tree->tree, for_each_func, user_data);
+ return tree_for_each_node(tree->tree, for_each_func, user_data);
}
/* Find the parent for the key */
-static Ecore_Tree_Node *tree_node_find_parent(Ecore_Tree * tree, void *key)
+static Ecore_Tree_Node *
+tree_node_find_parent(Ecore_Tree *tree, void *key)
{
- Ecore_Tree_Node *parent, *travel;
+ Ecore_Tree_Node *parent, *travel;
+
+ CHECK_PARAM_POINTER_RETURN("tree", tree, NULL);
+
+ parent = tree_node_find(tree, key);
+ if (parent)
+ parent = parent->parent;
- CHECK_PARAM_POINTER_RETURN("tree", tree, NULL);
+ travel = tree->tree;
+ if (!travel)
+ return NULL;
- parent = tree_node_find(tree, key);
- if (parent)
- parent = parent->parent;
-
- travel = tree->tree;
- if (!travel)
- return NULL;
-
- while (!parent) {
- int compare;
-
- if ((compare = tree->compare_func(key, travel->key)) < 0) {
- if (!travel->right_child)
- parent = travel;
- travel = travel->right_child;
- } else {
- if (!travel->left_child)
- parent = travel;
- travel = travel->left_child;
- }
- }
+ while (!parent)
+ {
+ int compare;
+
+ if ((compare = tree->compare_func(key, travel->key)) < 0)
+ {
+ if (!travel->right_child)
+ parent = travel;
+ travel = travel->right_child;
+ }
+ else
+ {
+ if (!travel->left_child)
+ parent = travel;
+ travel = travel->left_child;
+ }
+ }
- return parent;
+ return parent;
}
/* Search for the node with a specified key */
-static Ecore_Tree_Node *tree_node_find(Ecore_Tree * tree, void *key)
+static Ecore_Tree_Node *
+tree_node_find(Ecore_Tree *tree, void *key)
{
- int compare;
- Ecore_Tree_Node *node;
+ int compare;
+ Ecore_Tree_Node *node;
- CHECK_PARAM_POINTER_RETURN("tree", tree, NULL);
+ CHECK_PARAM_POINTER_RETURN("tree", tree, NULL);
- node = tree->tree;
- while (node && (compare = tree->compare_func(key, node->key)) != 0) {
+ node = tree->tree;
+ while (node && (compare = tree->compare_func(key, node->key)) != 0)
+ {
- if (compare < 0) {
- if (!node->right_child) {
- return NULL;
- }
+ if (compare < 0)
+ {
+ if (!node->right_child)
+ return NULL;
- node = node->right_child;
- } else {
- if (!node->left_child) {
- return NULL;
- }
-
- node = node->left_child;
- }
- }
+ node = node->right_child;
+ }
+ else
+ {
+ if (!node->left_child)
+ return NULL;
+
+ node = node->left_child;
+ }
+ }
- return node;
+ return node;
}
/* Balance the tree with respect to node */
-static int tree_node_balance(Ecore_Tree * tree, Ecore_Tree_Node * top_node)
+static int
+tree_node_balance(Ecore_Tree *tree, Ecore_Tree_Node *top_node)
{
- int balance;
+ int balance;
- CHECK_PARAM_POINTER_RETURN("top_node", top_node, FALSE);
+ CHECK_PARAM_POINTER_RETURN("top_node", top_node, FALSE);
- /* Get the height of the left branch. */
- if (top_node->right_child) {
- top_node->max_left = MAX_HEIGHT(top_node->right_child) + 1;
- } else
- top_node->max_left = 0;
-
- /* Get the height of the right branch. */
- if (top_node->left_child) {
- top_node->max_right = MAX_HEIGHT(top_node->left_child) + 1;
- } else
- top_node->max_right = 0;
-
- /* Determine which side has a larger height. */
- balance = top_node->max_right - top_node->max_left;
-
- /* if the left side has a height advantage >1 rotate right */
- if (balance < -1)
- tree_node_rotate_right(tree, top_node);
- /* else if the left side has a height advantage >1 rotate left */
- else if (balance > 1)
- tree_node_rotate_left(tree, top_node);
+ /* Get the height of the left branch. */
+ if (top_node->right_child)
+ top_node->max_left = MAX_HEIGHT(top_node->right_child) + 1;
+ else
+ top_node->max_left = 0;
+
+ /* Get the height of the right branch. */
+ if (top_node->left_child)
+ top_node->max_right = MAX_HEIGHT(top_node->left_child) + 1;
+ else
+ top_node->max_right = 0;
+
+ /* Determine which side has a larger height. */
+ balance = top_node->max_right - top_node->max_left;
+
+ /* if the left side has a height advantage >1 rotate right */
+ if (balance < -1)
+ tree_node_rotate_right(tree, top_node);
+ /* else if the left side has a height advantage >1 rotate left */
+ else if (balance > 1)
+ tree_node_rotate_left(tree, top_node);
- return TRUE;
+ return TRUE;
}
/* Tree is overbalanced to the left, so rotate nodes to the right. */
-static int tree_node_rotate_right(Ecore_Tree * tree, Ecore_Tree_Node *
top_node)
+static int
+tree_node_rotate_right(Ecore_Tree *tree, Ecore_Tree_Node *top_node)
{
- Ecore_Tree_Node *temp;
+ Ecore_Tree_Node *temp;
- CHECK_PARAM_POINTER_RETURN("top_node", top_node, FALSE);
+ CHECK_PARAM_POINTER_RETURN("top_node", top_node, FALSE);
- /* The left branch's right branch becomes the nodes left branch,
- * the left branch becomes the top node, and the node becomes the
- * right branch. */
- temp = top_node->right_child;
- top_node->right_child = temp->left_child;
- temp->left_child = top_node;
-
- /* Make sure the nodes know who their new parents are and the tree
- * structure knows the start of the tree. */
- temp->parent = top_node->parent;
- if (temp->parent == NULL)
- tree->tree = temp;
- else {
- if (temp->parent->left_child == top_node)
- temp->parent->left_child = temp;
- else
- temp->parent->right_child = temp;
- }
- top_node->parent = temp;
-
- /* And recalculate node heights */
- tree_node_balance(tree, top_node);
- tree_node_balance(tree, temp);
+ /* The left branch's right branch becomes the nodes left branch,
+ * the left branch becomes the top node, and the node becomes the
+ * right branch. */
+ temp = top_node->right_child;
+ top_node->right_child = temp->left_child;
+ temp->left_child = top_node;
+
+ /* Make sure the nodes know who their new parents are and the tree
+ * structure knows the start of the tree. */
+ temp->parent = top_node->parent;
+ if (temp->parent == NULL)
+ tree->tree = temp;
+ else
+ {
+ if (temp->parent->left_child == top_node)
+ temp->parent->left_child = temp;
+ else
+ temp->parent->right_child = temp;
+ }
+ top_node->parent = temp;
+
+ /* And recalculate node heights */
+ tree_node_balance(tree, top_node);
+ tree_node_balance(tree, temp);
- return TRUE;
+ return TRUE;
}
/* The tree is overbalanced to the right, so we rotate nodes to the left */
-static int tree_node_rotate_left(Ecore_Tree * tree, Ecore_Tree_Node * top_node)
+static int
+tree_node_rotate_left(Ecore_Tree *tree, Ecore_Tree_Node *top_node)
{
- Ecore_Tree_Node *temp;
+ Ecore_Tree_Node *temp;
- CHECK_PARAM_POINTER_RETURN("top_node", top_node, FALSE);
+ CHECK_PARAM_POINTER_RETURN("top_node", top_node, FALSE);
- /*
- * The right branch's left branch becomes the nodes right branch,
- * the right branch becomes the top node, and the node becomes the
- * left branch.
- */
- temp = top_node->left_child;
- top_node->left_child = temp->right_child;
- temp->right_child = top_node;
-
- /* Make sure the nodes know who their new parents are. */
- temp->parent = top_node->parent;
- if (temp->parent == NULL)
- tree->tree = temp;
- else {
- if (temp->parent->left_child == top_node)
- temp->parent->left_child = temp;
- else
- temp->parent->right_child = temp;
- }
- top_node->parent = temp;
-
- /* And recalculate node heights */
- tree_node_balance(tree, top_node);
- tree_node_balance(tree, temp);
+ /*
+ * The right branch's left branch becomes the nodes right branch,
+ * the right branch becomes the top node, and the node becomes the
+ * left branch.
+ */
+ temp = top_node->left_child;
+ top_node->left_child = temp->right_child;
+ temp->right_child = top_node;
+
+ /* Make sure the nodes know who their new parents are. */
+ temp->parent = top_node->parent;
+ if (temp->parent == NULL)
+ tree->tree = temp;
+ else
+ {
+ if (temp->parent->left_child == top_node)
+ temp->parent->left_child = temp;
+ else
+ temp->parent->right_child = temp;
+ }
+ top_node->parent = temp;
+
+ /* And recalculate node heights */
+ tree_node_balance(tree, top_node);
+ tree_node_balance(tree, temp);
- return TRUE;
+ return TRUE;
}
/*
@@ -730,41 +778,40 @@
* @param user_data: data passed to each for_each_func call
* @return Returns FALSE if an error condition occurs, otherwise TRUE
*/
-static int tree_for_each_node(Ecore_Tree_Node * node, Ecore_For_Each
for_each_func,
- void *user_data)
+static int
+tree_for_each_node(Ecore_Tree_Node * node, Ecore_For_Each for_each_func, void
*user_data)
{
- CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
+ CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
- if (node->right_child)
- tree_for_each_node(node->right_child, for_each_func, user_data);
+ if (node->right_child)
+ tree_for_each_node(node->right_child, for_each_func, user_data);
- if (node->left_child)
- tree_for_each_node(node->left_child, for_each_func, user_data);
+ if (node->left_child)
+ tree_for_each_node(node->left_child, for_each_func, user_data);
- for_each_func(node, user_data);
+ for_each_func(node, user_data);
- return TRUE;
+ return TRUE;
}
-
/*
* @brief Execute a function for each node below this point in the tree.
* @param node: the highest node in the tree the function will be executed for
* @param for_each_func: the function to pass the nodes values as data
* @return Returns FALSE if an error condition occurs, otherwise TRUE
*/
-static int tree_for_each_node_value(Ecore_Tree_Node * node,
- Ecore_For_Each for_each_func, void *user_data)
+static int
+tree_for_each_node_value(Ecore_Tree_Node *node, Ecore_For_Each for_each_func,
void *user_data)
{
- CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
+ CHECK_PARAM_POINTER_RETURN("node", node, FALSE);
- if (node->right_child)
- tree_for_each_node_value(node->right_child, for_each_func,
user_data);
+ if (node->right_child)
+ tree_for_each_node_value(node->right_child, for_each_func, user_data);
- if (node->left_child)
- tree_for_each_node_value(node->left_child, for_each_func,
user_data);
+ if (node->left_child)
+ tree_for_each_node_value(node->left_child, for_each_func, user_data);
- for_each_func(node->value, user_data);
+ for_each_func(node->value, user_data);
- 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
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs