]> code.citadel.org Git - citadel.git/blobdiff - libcitadel/lib/hash.c
* remove unneded code
[citadel.git] / libcitadel / lib / hash.c
index 616429ca87904aabbe16f21abef5999a28585136..21076b22e3426e3e3b7e71c2b0a8f225924680ef 100644 (file)
@@ -588,8 +588,13 @@ HashPos *GetNewHashPos(HashList *Hash, int StepWidth)
  * \param the Iterator to analyze
  * \returns the n'th hashposition we point at
  */
-int GetHashPosCounter(HashPos *At)
+int GetHashPosCounter(HashList *Hash, HashPos *At)
 {
+       if ((Hash == NULL) || 
+           (At->Position >= Hash->nMembersUsed) || 
+           (At->Position < 0) ||
+           (At->Position > Hash->nMembersUsed))
+               return 0;
        return At->Position;
 }
 
@@ -618,26 +623,22 @@ int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, const char **HashKe
 {
        long PayloadPos;
 
-       if ((Hash == NULL) || (At->Position >= Hash->nMembersUsed) || (At->Position < 0))
+       if ((Hash == NULL) || 
+           (At->Position >= Hash->nMembersUsed) || 
+           (At->Position < 0) ||
+           (At->Position > Hash->nMembersUsed))
                return 0;
        *HKLen = Hash->LookupTable[At->Position]->HKLen;
        *HashKey = Hash->LookupTable[At->Position]->HashKey;
        PayloadPos = Hash->LookupTable[At->Position]->Position;
        *Data = Hash->Members[PayloadPos]->Data;
 
-       if (At->Position % abs(At->StepWidth) == 0)
+       /* Position is NULL-Based, while Stepwidth is not... */
+       if ((At->Position % abs(At->StepWidth)) == 0)
                At->Position += At->StepWidth;
        else 
-               At->Position += (At->Position % abs(At->StepWidth)) * 
+               At->Position += ((At->Position) % abs(At->StepWidth)) * 
                        (At->StepWidth / abs(At->StepWidth));
-
-       if (At->Position > Hash->nMembersUsed) {
-               At->Position = Hash->nMembersUsed;
-               return 0;
-       } else if (At->Position <= 0) {
-               At->Position = 0;
-               return 0;
-       }
        return 1;
 }
 
@@ -654,7 +655,9 @@ int GetHashAt(HashList *Hash,long At, long *HKLen, const char **HashKey, void **
 {
        long PayloadPos;
 
-       if ((Hash == NULL) || (At >= Hash->nMembersUsed))
+       if ((Hash == NULL) || 
+           (At < 0) || 
+           (At > Hash->nMembersUsed))
                return 0;
        *HKLen = Hash->LookupTable[At]->HKLen;
        *HashKey = Hash->LookupTable[At]->HashKey;
@@ -795,4 +798,10 @@ void reference_free_handler(void *ptr)
 }
 
 
+/*
+ * This exposes the hashlittle() function to consumers.
+ */
+int HashLittle(const void *key, size_t length) {
+       return (int)hashlittle(key, length, 1);
+}