diff --git a/include/tr/hash.h b/include/tr/hash.h
index 9792d3d..f95689c 100644
--- a/include/tr/hash.h
+++ b/include/tr/hash.h
@@ -37,16 +37,16 @@ TR_CLASS(TR_Hash) {
TR_INSTANCE_INIT(TR_Hash);
TR_CLASSVARS_DECL(TR_Hash) {};
-//#define TR_hashEmpty(hash) (NULL == (hash)->tree->root)
-
-void * TR_hashAdd(TR_Hash, void *);
-void * TR_hashDelete(TR_Hash, const char *, size_t);
-void * TR_hashGet(TR_Hash, const char *, size_t);
-void * TR_hashGetFirst(TR_Hash);
-void * TR_hashDeleteByVal(TR_Hash, unsigned long);
-void * TR_hashGetByVal(TR_Hash, unsigned long);
-unsigned long TR_hashEach(TR_Hash, const void *, void (*)(const void *, const void *));
-void TR_hashCleanup(TR_Hash);
+#define TR_hashEmpty(hash) (NULL == (hash)->tree->root)
+
+void * TR_hashAdd(TR_Hash, void *);
+void * TR_hashDelete(TR_Hash, const char *, size_t);
+void * TR_hashGet(TR_Hash, const char *, size_t);
+void * TR_hashGetFirst(TR_Hash);
+void * TR_hashDeleteByVal(TR_Hash, unsigned long);
+void * TR_hashGetByVal(TR_Hash, unsigned long);
+void TR_hashEach(TR_Hash, const void *, void (*)(const void *, const void *));
+void TR_hashCleanup(TR_Hash);
#endif // __TR_HASH_H__
diff --git a/include/tr/tree.h b/include/tr/tree.h
index cb475b0..67e761d 100644
--- a/include/tr/tree.h
+++ b/include/tr/tree.h
@@ -50,11 +50,11 @@ TR_CLASSVARS_DECL(TR_Tree) {};
typedef int (*TR_TreeComp)(const void *, const void *);
typedef void (*TR_TreeAction)(const void *, const void *, const int);
-void * TR_treeFind(TR_Tree, const void *, TR_TreeComp);
-void * TR_treeInsert(TR_Tree, const void *, TR_TreeComp);
-void * TR_treeDelete(TR_Tree, const void *, TR_TreeComp);
-unsigned long TR_treeWalk(TR_Tree, const void *, TR_TreeAction);
-void TR_treeDestroy(TR_Tree, TR_TreeAction);
+void * TR_treeFind(TR_Tree, const void *, TR_TreeComp);
+void * TR_treeInsert(TR_Tree, const void *, TR_TreeComp);
+void * TR_treeDelete(TR_Tree, const void *, TR_TreeComp);
+void TR_treeWalk(TR_Tree, const void *, TR_TreeAction);
+void TR_treeDestroy(TR_Tree, TR_TreeAction);
#endif // __TR_TREE_H__
diff --git a/src/hash/each.c b/src/hash/each.c
index 33f68b7..2a6d605 100644
--- a/src/hash/each.c
+++ b/src/hash/each.c
@@ -34,7 +34,7 @@ walk(const void * node, const void * data, const int depth)
cb(node, data);
}
-unsigned long
+void
TR_hashEach(
TR_Hash this,
const void * data,
@@ -42,7 +42,7 @@ TR_hashEach(
{
cb = callback;
- return TR_treeWalk(this->tree, data, walk);
+ TR_treeWalk(this->tree, data, walk);
}
// vim: set ts=4 sw=4:
diff --git a/src/queue/destroy.c b/src/queue/destroy.c
index 8dda38b..e320afa 100644
--- a/src/queue/destroy.c
+++ b/src/queue/destroy.c
@@ -29,12 +29,10 @@
void
TR_queueDestroy(TR_Queue this)
{
- TR_Queue node;
+ TR_Queue node = this->first;
pthread_mutex_lock(&(this->lock));
- node = this->first;
-
while (NULL != node) {
TR_Queue next = node->next;
if (this->free_msgs) {
diff --git a/src/queue/find.c b/src/queue/find.c
index 790733e..67f51d3 100644
--- a/src/queue/find.c
+++ b/src/queue/find.c
@@ -20,8 +20,6 @@
* along with this program. If not, see .
*/
-#include
-
#include "trbase.h"
#include "tr/queue.h"
@@ -30,9 +28,7 @@ TR_queueFind(TR_Queue this, void * msg)
{
TR_Queue node;
- pthread_mutex_lock(&(this->lock));
for (node = this->first; node && node->msg != msg; node = node->next);
- pthread_mutex_unlock(&(this->lock));
return node;
}
diff --git a/src/queue/find_parent.c b/src/queue/find_parent.c
index 58e971a..707c29b 100644
--- a/src/queue/find_parent.c
+++ b/src/queue/find_parent.c
@@ -20,8 +20,6 @@
* along with this program. If not, see .
*/
-#include
-
#include "trbase.h"
#include "tr/queue.h"
@@ -30,9 +28,7 @@ TR_queueFindParent(TR_Queue this, void * msg)
{
TR_Queue node;
- pthread_mutex_lock(&(this->lock));
for (node = this; node->next && node->next->msg != msg; node = node->next);
- pthread_mutex_unlock(&(this->lock));
return node->next ? node : NULL;
}
diff --git a/src/queue/put.c b/src/queue/put.c
index 1e12e74..833e386 100644
--- a/src/queue/put.c
+++ b/src/queue/put.c
@@ -28,12 +28,10 @@
void
TR_queuePut(TR_Queue this, void * msg)
{
- TR_Queue node;
+ TR_Queue node = (this->last)? this->last : this;
pthread_mutex_lock(&(this->lock));
- node = (this->last)? this->last : this;
-
node->next = TR_new(TR_Queue);
this->last = node->next;
diff --git a/src/queue/put_first.c b/src/queue/put_first.c
index dda90bd..f474e71 100644
--- a/src/queue/put_first.c
+++ b/src/queue/put_first.c
@@ -28,12 +28,10 @@
void
TR_queuePutFirst(TR_Queue this, void * msg)
{
- TR_Queue current_first;
+ TR_Queue current_first = this->first;
pthread_mutex_lock(&(this->lock));
- current_first = this->first;
-
this->first = this->next = TR_new(TR_Queue);
this->first->next = current_first;
this->first->msg = msg;
diff --git a/src/tree/delete.c b/src/tree/delete.c
index 44b524d..6b548d4 100644
--- a/src/tree/delete.c
+++ b/src/tree/delete.c
@@ -28,7 +28,7 @@
void *
TR_treeDelete(TR_Tree this, const void * search, TR_TreeComp comp)
{
- TR_TreeNode node;
+ TR_TreeNode node = this->root;
TR_TreeNode del_node;
TR_TreeNode sibling;
int found;
@@ -36,8 +36,6 @@ TR_treeDelete(TR_Tree this, const void * search, TR_TreeComp comp)
pthread_mutex_lock(&(this->lock));
- node = this->root;
-
TR_TREE_FIND(node, search, found, comp);
/*
diff --git a/src/tree/destroy.c b/src/tree/destroy.c
index 3272be2..be623e1 100644
--- a/src/tree/destroy.c
+++ b/src/tree/destroy.c
@@ -26,15 +26,10 @@
void
TR_treeDestroy(TR_Tree this, TR_TreeAction action)
{
- TR_TreeNode previous;
- TR_TreeNode node;
- int depth = 1;
+ TR_TreeNode previous = this->root;
+ TR_TreeNode node = this->root;
+ int depth = 1;
- pthread_mutex_lock(&(this->lock));
-
- previous = this->root;
- node = this->root;
-
/*
* I think this has something like O(n+log(n)) on a ballanced
* tree because I have to traverse back the rightmost leaf to
@@ -88,8 +83,6 @@ TR_treeDestroy(TR_Tree this, TR_TreeAction action)
}
this->root = NULL;
-
- pthread_mutex_unlock(&(this->lock));
}
// vim: set ts=4 sw=4:
diff --git a/src/tree/find.c b/src/tree/find.c
index f7be76d..2518822 100644
--- a/src/tree/find.c
+++ b/src/tree/find.c
@@ -25,19 +25,16 @@
void *
TR_treeFind(TR_Tree this, const void * search, TR_TreeComp comp)
{
- int found;
- TR_TreeNode node;
- void * retval;
+ int found;
+ TR_TreeNode node = this->root;
pthread_mutex_lock(&(this->lock));
- node = this->root;
TR_TREE_FIND(node, search, found, comp);
- retval = found == 0 ? node->data : NULL;
pthread_mutex_unlock(&(this->lock));
- return retval;
+ return found == 0 ? node->data : NULL;
}
// vim: set ts=4 sw=4:
diff --git a/src/tree/insert.c b/src/tree/insert.c
index f8955a3..449f416 100644
--- a/src/tree/insert.c
+++ b/src/tree/insert.c
@@ -28,15 +28,12 @@
void *
TR_treeInsert(TR_Tree this, const void * search, TR_TreeComp comp)
{
- TR_TreeNode new_node = NULL;
- TR_TreeNode node;
- int found;
- void * retval;
+ TR_TreeNode node = this->root;
+ TR_TreeNode new_node = NULL;
+ int found;
pthread_mutex_lock(&(this->lock));
- node = this->root;
-
/*
* insert the node or return the one in tree if comparison
* succeeds.
@@ -80,11 +77,10 @@ TR_treeInsert(TR_Tree this, const void * search, TR_TreeComp comp)
* new node at this point...now rabalance the tree
*/
TR_TREE_BALANCE_INSERT(&(this->root), node);
- retval = new_node->data;
pthread_mutex_unlock(&(this->lock));
- return retval;
+ return new_node->data;
}
// vim: set ts=4 sw=4:
diff --git a/src/tree/walk.c b/src/tree/walk.c
index f650fd8..d9608ea 100644
--- a/src/tree/walk.c
+++ b/src/tree/walk.c
@@ -20,22 +20,14 @@
* along with this program. If not, see .
*/
-#include
-
#include "tr/tree.h"
-unsigned long
+void
TR_treeWalk(TR_Tree this, const void * data, TR_TreeAction action)
{
- TR_TreeNode previous;
- TR_TreeNode node;
- int depth = 1;
- unsigned long processed = 0;
-
- pthread_mutex_lock(&(this->lock));
-
- previous = this->root;
- node = this->root;
+ TR_TreeNode previous = this->root;
+ TR_TreeNode node = this->root;
+ int depth = 1;
while (NULL != node) {
if (previous == TR_TREE_RIGHT(node)) {
@@ -48,7 +40,6 @@ TR_treeWalk(TR_Tree this, const void * data, TR_TreeAction action)
if (NULL == TR_TREE_LEFT(node) || previous == TR_TREE_LEFT(node)) {
if (action) {
action(node->data, data, depth);
- processed++;
}
previous = node;
@@ -65,10 +56,6 @@ TR_treeWalk(TR_Tree this, const void * data, TR_TreeAction action)
depth++;
}
}
-
- pthread_mutex_unlock(&(this->lock));
-
- return processed;
}
// vim: set ts=4 sw=4: