From 39ad3d6da084640e4b16e6cbb3ac37ea46e541d8 Mon Sep 17 00:00:00 2001 From: cuz Date: Thu, 23 Oct 2003 14:54:58 +0000 Subject: [PATCH] Change API for the Compare function git-svn-id: svn://svn.cc65.org/cc65/trunk@2573 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/filetab.c | 12 +++++++++--- src/ca65/macro.c | 12 +++++++++--- src/common/hashtab.c | 2 +- src/common/hashtab.h | 5 ++++- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/ca65/filetab.c b/src/ca65/filetab.c index 05d065f32..b055428f5 100644 --- a/src/ca65/filetab.c +++ b/src/ca65/filetab.c @@ -65,7 +65,10 @@ static HashNode* HT_GetHashNode (void* Entry); /* Given a pointer to the user entry data, return a pointer to the hash node */ static int HT_Compare (const void* Key1, const void* Key2); -/* Compare two keys for equality */ +/* Compare two keys. The function must return a value less than zero if + * Key1 is smaller than Key2, zero if both are equal, and a value greater + * than zero if Key1 is greater then Key2. + */ @@ -136,9 +139,12 @@ static HashNode* HT_GetHashNode (void* Entry) static int HT_Compare (const void* Key1, const void* Key2) -/* Compare two keys for equality */ +/* Compare two keys. The function must return a value less than zero if + * Key1 is smaller than Key2, zero if both are equal, and a value greater + * than zero if Key1 is greater then Key2. + */ { - return (*(const unsigned*)Key1 == *(const unsigned*)Key2); + return (int)*(const unsigned*)Key1 - (int)*(const unsigned*)Key2; } diff --git a/src/ca65/macro.c b/src/ca65/macro.c index 649427770..a819c3c5f 100644 --- a/src/ca65/macro.c +++ b/src/ca65/macro.c @@ -70,7 +70,10 @@ static HashNode* HT_GetHashNode (void* Entry); /* Given a pointer to the user entry data, return a pointer to the hash node */ static int HT_Compare (const void* Key1, const void* Key2); -/* Compare two keys for equality */ +/* Compare two keys. The function must return a value less than zero if + * Key1 is smaller than Key2, zero if both are equal, and a value greater + * than zero if Key1 is greater then Key2. + */ @@ -175,9 +178,12 @@ static HashNode* HT_GetHashNode (void* Entry) static int HT_Compare (const void* Key1, const void* Key2) -/* Compare two keys for equality */ +/* Compare two keys. The function must return a value less than zero if + * Key1 is smaller than Key2, zero if both are equal, and a value greater + * than zero if Key1 is greater then Key2. + */ { - return (strcmp (Key1, Key2) == 0); + return strcmp (Key1, Key2); } diff --git a/src/common/hashtab.c b/src/common/hashtab.c index 3572086ed..7c7f0e229 100644 --- a/src/common/hashtab.c +++ b/src/common/hashtab.c @@ -96,7 +96,7 @@ HashNode* HT_Find (const HashTable* T, const void* Key) * if it is not really necessary. */ if (N->Hash == Hash && - T->Func->Compare (Key, T->Func->GetKey (N->Entry))) { + T->Func->Compare (Key, T->Func->GetKey (N->Entry)) == 0) { /* Found */ break; } diff --git a/src/common/hashtab.h b/src/common/hashtab.h index b50acee42..fb8ece3fa 100644 --- a/src/common/hashtab.h +++ b/src/common/hashtab.h @@ -75,7 +75,10 @@ struct HashFunctions { /* Given a pointer to the user entry data, return a pointer to the hash node */ int (*Compare) (const void* Key1, const void* Key2); - /* Compare two keys for equality */ + /* Compare two keys. The function must return a value less than zero if + * Key1 is smaller than Key2, zero if both are equal, and a value greater + * than zero if Key1 is greater then Key2. + */ }; /* Hash table */ -- 2.39.5