diff options
author | allen <allen@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2000-02-03 12:26:29 +0000 |
---|---|---|
committer | allen <allen@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2000-02-03 12:26:29 +0000 |
commit | 3bb9e9b1df7059b4684e70be812781aafe42346e (patch) | |
tree | 9f6a6da6126bdfdb827fafcf1ec63e0a339b2b81 /src | |
parent | ca5f0941438bf3341f7457578ac53c6dffa969d9 (diff) |
Standardising function and structure names
git-svn-id: http://svn.cactuscode.org/flesh/trunk@1347 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src')
-rw-r--r-- | src/util/BinaryTree.c | 71 | ||||
-rw-r--r-- | src/util/Hash.c | 111 |
2 files changed, 93 insertions, 89 deletions
diff --git a/src/util/BinaryTree.c b/src/util/BinaryTree.c index ceab4dac..1c194e77 100644 --- a/src/util/BinaryTree.c +++ b/src/util/BinaryTree.c @@ -11,13 +11,13 @@ #include <stdlib.h> #include <string.h> -#include "BinaryTree.h" +#include "util_BinaryTree.h" static char *rcsid = "$Header$"; /*@@ - @routine TreeStoreData + @routine Util_BinTreeStoreData @date Mon Oct 5 11:04:55 1998 @author Tom Goodale @desc @@ -30,14 +30,14 @@ static char *rcsid = "$Header$"; @endhistory @@*/ -t_tree *TreeStoreData(t_tree *root, t_tree *subtree, void *data, int (*compare)(const void *, const void *)) +uBinTree *Util_BinTreeStoreData(uBinTree *root, uBinTree *subtree, void *data, int (*compare)(const void *, const void *)) { int order; if(!subtree) { /* Create a new element. */ - subtree = (t_tree *)malloc(sizeof(t_tree)); + subtree = (uBinTree *)malloc(sizeof(uBinTree)); if(subtree) { subtree->left=NULL; @@ -63,11 +63,11 @@ t_tree *TreeStoreData(t_tree *root, t_tree *subtree, void *data, int (*compare)( /* Go down left or right branch. */ if((order = compare(data, root->data)) < 0) { - subtree = TreeStoreData(subtree, subtree->left, data, compare); + subtree = Util_BinTreeStoreData(subtree, subtree->left, data, compare); } else if(order > 0) { - subtree = TreeStoreData(subtree, subtree->right, data, compare); + subtree = Util_BinTreeStoreData(subtree, subtree->right, data, compare); } else if(order==0) { @@ -85,7 +85,7 @@ t_tree *TreeStoreData(t_tree *root, t_tree *subtree, void *data, int (*compare)( } /*@@ - @routine TreeTraverseInorder + @routine Util_BinTreeTraverseInorder @date Mon Oct 5 11:05:54 1998 @author Tom Goodale @desc @@ -98,7 +98,7 @@ t_tree *TreeStoreData(t_tree *root, t_tree *subtree, void *data, int (*compare)( @endhistory @@*/ -int TreeTraverseInorder(t_tree *root, int (*process)(void *, void *), void *info) +int Util_BinTreeTraverseInorder(uBinTree *root, int (*process)(void *, void *), void *info) { int terminate; @@ -106,16 +106,16 @@ int TreeTraverseInorder(t_tree *root, int (*process)(void *, void *), void *info if(root) { - terminate = TreeTraverseInorder(root->left, process, info); + terminate = Util_BinTreeTraverseInorder(root->left, process, info); if(!terminate) terminate = process(root->data,info); - if(!terminate) terminate = TreeTraverseInorder(root->right, process, info); + if(!terminate) terminate = Util_BinTreeTraverseInorder(root->right, process, info); } return terminate; } /*@@ - @routine TreeTraversePreorder + @routine Util_BinTreeTraversePreorder @date Mon Oct 5 11:05:54 1998 @author Tom Goodale @desc @@ -128,7 +128,7 @@ int TreeTraverseInorder(t_tree *root, int (*process)(void *, void *), void *info @endhistory @@*/ -int TreeTraversePreorder(t_tree *root, int (*process)(void *, void *), void *info) +int Util_BinTreeTraversePreorder(uBinTree *root, int (*process)(void *, void *), void *info) { int terminate; @@ -137,15 +137,15 @@ int TreeTraversePreorder(t_tree *root, int (*process)(void *, void *), void *inf if(root) { terminate = process(root->data, info); - if(!terminate) terminate = TreeTraversePreorder(root->left, process, info); - if(!terminate) terminate = TreeTraversePreorder(root->right, process,info); + if(!terminate) terminate = Util_BinTreeTraversePreorder(root->left, process, info); + if(!terminate) terminate = Util_BinTreeTraversePreorder(root->right, process,info); } return terminate; } /*@@ - @routine TreeTraversePostorder + @routine Util_BinTreeTraversePostorder @date Mon Oct 5 11:05:54 1998 @author Tom Goodale @desc @@ -158,7 +158,7 @@ int TreeTraversePreorder(t_tree *root, int (*process)(void *, void *), void *inf @endhistory @@*/ -int TreeTraversePostorder(t_tree *root, int (*process)(void *, void *), void *info) +int Util_BinTreeTraversePostorder(uBinTree *root, int (*process)(void *, void *), void *info) { int terminate; @@ -166,8 +166,8 @@ int TreeTraversePostorder(t_tree *root, int (*process)(void *, void *), void *in if(root) { - terminate = TreeTraversePostorder(root->left, process, info); - if(!terminate) terminate = TreeTraversePostorder(root->right, process, info); + terminate = Util_BinTreeTraversePostorder(root->left, process, info); + if(!terminate) terminate = Util_BinTreeTraversePostorder(root->right, process, info); if(!terminate) terminate = process(root->data, info); } @@ -175,7 +175,7 @@ int TreeTraversePostorder(t_tree *root, int (*process)(void *, void *), void *in } /*@@ - @routine TreePrintNodes + @routine Util_BinTreePrintNodes @date Mon Oct 5 11:06:52 1998 @author Tom Goodale @desc @@ -188,19 +188,22 @@ int TreeTraversePostorder(t_tree *root, int (*process)(void *, void *), void *in @endhistory @@*/ -void TreePrintNodes(t_tree *root, int depth, void (*print_node)(void *, int)) +int Util_BinTreePrintNodes(uBinTree *root, + int depth, + void (*print_node)(void *, int)) { if(root) { - TreePrintNodes(root->left, depth+1,print_node); + Util_BinTreePrintNodes(root->left, depth+1,print_node); print_node(root->data,depth); - TreePrintNodes(root->right, depth+1, print_node); + Util_BinTreePrintNodes(root->right, depth+1, print_node); } + return 0; } /*@@ - @routine TreeFindNode + @routine Util_BinTreeFindNode @date Mon Oct 5 11:06:52 1998 @author Tom Goodale @desc @@ -213,20 +216,20 @@ void TreePrintNodes(t_tree *root, int depth, void (*print_node)(void *, int)) @endhistory @@*/ -t_tree *TreeFindNode(t_tree *root, void *data, int (*compare)(const void *, const void *)) +uBinTree *TreeFindNode(uBinTree *root, void *data, int (*compare)(const void *, const void *)) { int order; - t_tree *node; + uBinTree *node; /* Go down left or right branch. */ if((order = compare(data, root->data)) < 0) { - node = TreeFindNode(root->left, data, compare); + node = Util_BinTreeFindNode(root->left, data, compare); } else if(order > 0) { - node = TreeFindNode(root->right, data, compare); + node = Util_BinTreeFindNode(root->right, data, compare); } else if(order==0) { @@ -270,11 +273,11 @@ void print_node(char *data, int depth) int main(void) { - t_tree *root; + uBinTree *root; t_infodata infodata; char instring[500]; char *newstring; - t_tree *node; + uBinTree *node; infodata.i=0; @@ -287,22 +290,22 @@ int main(void) if(!root) { - root = TreeStoreData(root, root, newstring, (int (*)(const void *, const void *))strcmp); + root = Util_BinTreeStoreData(root, root, newstring, (int (*)(const void *, const void *))strcmp); } else { - TreeStoreData(root, root, newstring, (int (*)(const void *, const void *))strcmp); + Util_BinTreeStoreData(root, root, newstring, (int (*)(const void *, const void *))strcmp); } } - TreeTraverseInorder(root, (int (*)(void *, void *))process, (void *)&infodata); + Util_BinTreeTraverseInorder(root, (int (*)(void *, void *))process, (void *)&infodata); - TreePrintNodes(root, 0, (void (*)(void *, int))print_node); + Util_BinTreePrintNodes(root, 0, (void (*)(void *, int))print_node); printf("String to find ? "); scanf("%s", instring); - node = TreeFindNode(root, instring, (int (*)(const void *, const void *))strcmp); + node = Util_BinTreeFindNode(root, instring, (int (*)(const void *, const void *))strcmp); if(node) { diff --git a/src/util/Hash.c b/src/util/Hash.c index 0f708480..d3101f9c 100644 --- a/src/util/Hash.c +++ b/src/util/Hash.c @@ -11,17 +11,17 @@ #include <stdlib.h> #include <string.h> -#include "Hash.h" +#include "util_Hash.h" static char *rcsid = "$Header$"; /* Local routine prototypes */ -static t_hash_entry *HashFind(t_hash *hash, - unsigned int klen, - char *key, - unsigned int hashval); -static int HashRehash(t_hash *hash); +static iHashEntry *HashFind(uHash *hash, + unsigned int klen, + char *key, + unsigned int hashval); +static int HashRehash(uHash *hash); /******************************************************************** ******************** External Routines ************************ @@ -29,7 +29,7 @@ static int HashRehash(t_hash *hash); /*@@ - @routine HashCreate + @routine Util_HashCreate @date Wed Oct 27 23:31:11 1999 @author Tom Goodale @desc @@ -42,11 +42,11 @@ static int HashRehash(t_hash *hash); @endhistory @@*/ -t_hash *HashCreate(unsigned int initial_size) +uHash *HashCreate(unsigned int initial_size) { - t_hash *retval; + uHash *retval; - retval = (t_hash *)malloc(sizeof(t_hash)); + retval = (uHash *)malloc(sizeof(uHash)); if(retval) { @@ -60,7 +60,7 @@ t_hash *HashCreate(unsigned int initial_size) retval->fill = 0; retval->keys = 0; - retval->array = (t_hash_entry **)calloc(sizeof(t_hash_entry *), retval->size); + retval->array = (iHashEntry **)calloc(sizeof(iHashEntry *), retval->size); if(! retval->array) { @@ -75,7 +75,7 @@ t_hash *HashCreate(unsigned int initial_size) } /*@@ - @routine HashDestroy + @routine Util_HashDestroy @date Wed Oct 27 23:32:12 1999 @author Tom Goodale @desc @@ -88,12 +88,12 @@ t_hash *HashCreate(unsigned int initial_size) @endhistory @@*/ -void HashDestroy(t_hash *hash) +int Util_HashDestroy(uHash *hash) { unsigned int size; - t_hash_entry **array; - t_hash_entry *entry; + iHashEntry **array; + iHashEntry *entry; unsigned int location; @@ -109,10 +109,11 @@ void HashDestroy(t_hash *hash) } } free(hash->array); + return 0; } /*@@ - @routine HashStore + @routine Util_HashStore @date Wed Oct 27 23:44:14 1999 @author Tom Goodale @desc @@ -125,14 +126,14 @@ void HashDestroy(t_hash *hash) @endhistory @@*/ -int HashStore(t_hash *hash, +int Util_HashStore(uHash *hash, unsigned int klen, char *key, unsigned int hashval, void *data) { int retval; - t_hash_entry *entry; + iHashEntry *entry; entry = HashFind(hash, klen, key, hashval); @@ -143,14 +144,14 @@ int HashStore(t_hash *hash, } else { - retval = HashAdd(hash, klen, key, hashval, data); + retval = Util_HashAdd(hash, klen, key, hashval, data); } return retval; } /*@@ - @routine HashAdd + @routine Util_HashAdd @date Wed Oct 27 23:32:40 1999 @author Tom Goodale @desc @@ -163,15 +164,15 @@ int HashStore(t_hash *hash, @endhistory @@*/ -int HashAdd(t_hash *hash, +int Util_HashAdd(uHash *hash, unsigned int klen, char *key, unsigned int hashval, void *data) { int retval; - t_hash_entry *entry; - t_hash_entry *lastentry; + iHashEntry *entry; + iHashEntry *lastentry; unsigned int location; int duplicate; int i; @@ -179,7 +180,7 @@ int HashAdd(t_hash *hash, /* Calculate the hash value if necessary */ if(!hashval) { - hashval = HashHash(klen, key); + hashval = Util_HashHash(klen, key); } /* Get its location in the table */ @@ -211,7 +212,7 @@ int HashAdd(t_hash *hash, if(!duplicate) { /* Create a new entry */ - entry = (t_hash_entry *)malloc(sizeof(t_hash_entry)); + entry = (iHashEntry *)malloc(sizeof(iHashEntry)); if(entry) { @@ -269,7 +270,7 @@ int HashAdd(t_hash *hash, } /*@@ - @routine HashDelete + @routine Util_HashDelete @date Wed Oct 27 23:33:42 1999 @author Tom Goodale @desc @@ -282,18 +283,18 @@ int HashAdd(t_hash *hash, @endhistory @@*/ -int HashDelete(t_hash *hash, +int Util_HashDelete(uHash *hash, unsigned int klen, char *key, unsigned int hashval) { - t_hash_entry *entry; + iHashEntry *entry; unsigned int location; /* Calculate the hash value if necessary */ if(!hashval) { - hashval = HashHash(klen, key); + hashval = Util_HashHash(klen, key); } /* Get its location in the table */ @@ -345,7 +346,7 @@ int HashDelete(t_hash *hash, } /*@@ - @routine HashGet + @routine Util_HashData @date Wed Oct 27 23:35:17 1999 @author Tom Goodale @desc @@ -358,13 +359,13 @@ int HashDelete(t_hash *hash, @endhistory @@*/ -void *HashGet(t_hash *hash, +void *Util_HashData(uHash *hash, unsigned int klen, char *key, unsigned int hashval) { void *retval; - t_hash_entry *entry; + iHashEntry *entry; entry = HashFind(hash, klen, key, hashval); @@ -383,11 +384,11 @@ void *HashGet(t_hash *hash, /*@@ - @routine HashHash + @routine Util_HashHash @date Wed Oct 27 22:15:17 1999 @author Tom Goodale @desc - Hashing function. I took this from the book + Util_Hashing function. I took this from the book 'Advanced Perl Programming' published by O'Reilly, and it is apparently the algorithm used in Perl, and that is GPL. @@ -399,7 +400,7 @@ void *HashGet(t_hash *hash, @endhistory @@*/ -unsigned int HashHash(unsigned int klen, +unsigned int Util_HashHash(unsigned int klen, char *key) { unsigned int hash; @@ -442,18 +443,18 @@ unsigned int HashHash(unsigned int klen, @endhistory @@*/ -static t_hash_entry *HashFind(t_hash *hash, - unsigned int klen, - char *key, - unsigned int hashval) +static iHashEntry *HashFind(uHash *hash, + unsigned int klen, + char *key, + unsigned int hashval) { - t_hash_entry *entry; + iHashEntry *entry; unsigned int location; /* Calculate the hash value if necessary */ if(!hashval) { - hashval = HashHash(klen, key); + hashval = Util_HashHash(klen, key); } /* Get its location in the table */ @@ -489,7 +490,7 @@ static t_hash_entry *HashFind(t_hash *hash, @endhistory @@*/ -static int HashRehash(t_hash *hash) +static int HashRehash(uHash *hash) { int retval; @@ -501,18 +502,18 @@ static int HashRehash(t_hash *hash) unsigned int new_fill; - t_hash_entry **oldarray; - t_hash_entry **newarray; + iHashEntry **oldarray; + iHashEntry **newarray; - t_hash_entry *entry; - t_hash_entry *next; - t_hash_entry *entry2; + iHashEntry *entry; + iHashEntry *next; + iHashEntry *entry2; if(hash->keys > hash->fill) { old_size = hash->size; new_size = hash->size*2; - newarray = (t_hash_entry **)calloc(sizeof(t_hash_entry *), new_size); + newarray = (iHashEntry **)calloc(sizeof(iHashEntry *), new_size); oldarray = hash->array; new_fill = 0; @@ -578,11 +579,11 @@ static int HashRehash(t_hash *hash) ********************* Test Routines ************************* ********************************************************************/ -#ifdef TEST_HASH +#ifdef TESUHASH int main(int argc, char *argv[]) { - t_hash *hash; + uHash *hash; char key[40]; char *value; @@ -600,7 +601,7 @@ int main(int argc, char *argv[]) case 2: n_strings = atoi(argv[1]); } - hash = HashCreate(initial_size); + hash = Util_HashCreate(initial_size); for(i = 0; i < n_strings; i++) { @@ -612,27 +613,27 @@ int main(int argc, char *argv[]) printf("Adding key %d\n", i); - HashStore(hash, strlen(key), key, 0, (void *)value); + Util_HashStore(hash, strlen(key), key, 0, (void *)value); } for(i = 0; i < n_strings; i++) { sprintf(key, "key_%d", i); - printf("Key %s -> '%s'\n", key, (char *)HashGet(hash, strlen(key), key, 0)); + printf("Key %s -> '%s'\n", key, (char *)Util_HashData(hash, strlen(key), key, 0)); } for(i = 0; i < n_strings; i++) { sprintf(key, "key_%d", i); - HashDelete(hash, strlen(key), key, 0); + Util_HashDelete(hash, strlen(key), key, 0); } for(i = 0; i < n_strings; i++) { sprintf(key, "key_%d", i); - value = (char *)HashGet(hash, strlen(key), key, 0); + value = (char *)Util_HashData(hash, strlen(key), key, 0); if(value) { |