* 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
master
Giel van Schijndel 2008-07-14 22:09:31 +00:00
parent 8db7c031ff
commit 0c4b256797
2 changed files with 13 additions and 10 deletions

View File

@ -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,15 +76,18 @@ 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;
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;

View File

@ -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 */