From 1956b32b1653ba3fe39876aee793ed9dbf488222 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Wed, 31 Aug 2011 08:02:42 +0000 Subject: [PATCH] Add function to do some revalidations on hashlists; Attention; this can be cpu intense; don't use for production code. --- libcitadel/lib/hash.c | 24 ++++++++++++++++++++++++ libcitadel/lib/libcitadel.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/libcitadel/lib/hash.c b/libcitadel/lib/hash.c index e5093b7e4..e8cd6b29c 100644 --- a/libcitadel/lib/hash.c +++ b/libcitadel/lib/hash.c @@ -203,6 +203,30 @@ int dbg_PrintHash(HashList *Hash, PrintHashContent First, PrintHashContent Secon } +int TestValidateHash(HashList *TestHash) +{ + long i; + + if (TestHash->nMembersUsed != TestHash->nLookupTableItems) + return 1; + + if (TestHash->nMembersUsed > TestHash->MemberSize) + return 2; + + for (i=0; i < TestHash->nMembersUsed; i++) + { + + if (TestHash->LookupTable[i]->Position > TestHash->nMembersUsed) + return 3; + + if (TestHash->Members[TestHash->LookupTable[i]->Position] == NULL) + return 4; + if (TestHash->Members[TestHash->LookupTable[i]->Position]->Data == NULL) + return 5; + } + return 0; +} + /** * @ingroup HashListAccess * @brief instanciate a new hashlist diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index 6624510b0..efd3caba0 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -479,6 +479,8 @@ long lFlathash(const char *str, long len); #define IKEY(a) (const char*) &a, sizeof(a) #define LKEY(a) (const char*) &a, sizeof(a) +int TestValidateHash(HashList *TestHash); + HashList *NewHash(int Uniq, HashFunc F); void DeleteHash(HashList **Hash); void DeleteHashContent(HashList **Hash); -- 2.30.2