From 0c4b256797d4b62aebc3c62dd5430911c0a14a7f Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Mon, 14 Jul 2008 22:09:31 +0000 Subject: [PATCH] * Out with the (unnecessary! as the size guarantee isn't required) WORDs from treap.[ch] * Restructure treapStringCmp to be __readable__ git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5551 4a71c877-e1ca-e34f-864e-861f7616d084 --- lib/framework/treap.c | 19 +++++++++++-------- lib/framework/treap.h | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/framework/treap.c b/lib/framework/treap.c index 3c09e1dd9..29218dea4 100644 --- a/lib/framework/treap.c +++ b/lib/framework/treap.c @@ -37,7 +37,7 @@ typedef struct TREAP_NODE { void *key; //< The key to sort the node on - UDWORD priority; //< Treap priority + unsigned int priority; //< Treap priority void *pObj; //< The object stored in the treap struct TREAP_NODE *psLeft, *psRight; //< The sub trees @@ -76,16 +76,19 @@ void treapSetCallPos(const char* fileName, int lineNumber) } /* A useful comparison function - keys are char pointers */ -SDWORD treapStringCmp(const void *key1, const void *key2) +int treapStringCmp(const void *key1, const void *key2) { - SDWORD result; + int result; const char *pStr1 = (const char *)key1; const char *pStr2 = (const char *)key2; - result = strcmp(pStr1,pStr2); - if (result<0) return -1; - if (result>0) return 1; - return 0; + result = strcmp(pStr1, pStr2); + if (result < 0) + return -1; + else if (result > 0) + return 1; + else + return 0; } @@ -186,7 +189,7 @@ BOOL treapAdd(TREAP *psTreap, void *key, void *pObj) debug(LOG_ERROR, "treapAdd: Out of memory"); return false; } - psNew->priority = (UDWORD)rand(); + psNew->priority = rand(); psNew->key = key; psNew->pObj = pObj; psNew->psLeft = NULL; diff --git a/lib/framework/treap.h b/lib/framework/treap.h index f0f3c24b5..757d02a17 100644 --- a/lib/framework/treap.h +++ b/lib/framework/treap.h @@ -45,7 +45,7 @@ * 1 for more * 0 for equal */ -typedef SDWORD (*TREAP_CMP)(const void *key1, const void *key2); +typedef int (*TREAP_CMP)(const void *key1, const void *key2); /// Forward declaration to allow pointers to this type struct TREAP; @@ -99,7 +99,7 @@ extern void *treapGetSmallest(struct TREAP *psTreap); /* Comparison Functions */ /* A useful comparison function - keys are char pointers */ -extern SDWORD treapStringCmp(const void *key1, const void *key2); +extern int treapStringCmp(const void *key1, const void *key2); /****************************************************************************************/ /* Macro definitions */