Add function to do some revalidations on hashlists; Attention; this can be cpu intens...
authorWilfried Goesgens <dothebart@citadel.org>
Wed, 31 Aug 2011 08:02:42 +0000 (08:02 +0000)
committerWilfried Goesgens <dothebart@citadel.org>
Wed, 31 Aug 2011 08:02:42 +0000 (08:02 +0000)
libcitadel/lib/hash.c
libcitadel/lib/libcitadel.h

index e5093b7e4b9d43d394164bf59e810d1cf4a38d76..e8cd6b29c19932f9cf19e697fd50e37e0b290626 100644 (file)
@@ -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
index 6624510b07019d09e603092ab6a93a27f5904567..efd3caba047c6da923d0e59643de3bdebb5d4960 100644 (file)
@@ -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);