* adjust backward iterating
authorWilfried Göesgens <willi@citadel.org>
Wed, 24 Dec 2008 10:42:57 +0000 (10:42 +0000)
committerWilfried Göesgens <willi@citadel.org>
Wed, 24 Dec 2008 10:42:57 +0000 (10:42 +0000)
libcitadel/lib/hash.c

index b8ba8c346839ac267ebcad69e39a835e8bfea0f6..616429ca87904aabbe16f21abef5999a28585136 100644 (file)
@@ -575,8 +575,7 @@ HashPos *GetNewHashPos(HashList *Hash, int StepWidth)
        else
                Ret->StepWidth = 1;
        if (Ret->StepWidth <  0) {
-               Ret->Position = (Hash->nMembersUsed % (-Ret->StepWidth)) 
-                       * (-Ret->StepWidth);
+               Ret->Position = Hash->nMembersUsed - 1;
        }
        else {
                Ret->Position = 0;
@@ -626,10 +625,18 @@ int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, const char **HashKe
        PayloadPos = Hash->LookupTable[At->Position]->Position;
        *Data = Hash->Members[PayloadPos]->Data;
 
-       At->Position += At->StepWidth;
+       if (At->Position % abs(At->StepWidth) == 0)
+               At->Position += At->StepWidth;
+       else 
+               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;
 }