* offer a split version of GetNextHashPos(): GetHashPos() retrieves the item, NextHas...
authorWilfried Göesgens <willi@citadel.org>
Sat, 24 Apr 2010 11:41:33 +0000 (11:41 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 24 Apr 2010 11:41:33 +0000 (11:41 +0000)
libcitadel/lib/hash.c
libcitadel/lib/libcitadel.h

index 2eb5e1a0d11f77834c4a7c55f949dcf42d8bdbe7..f9ceeced3d82fe94cd282c56d7d970af5f24ff81 100644 (file)
@@ -715,6 +715,7 @@ void DeleteHashPos(HashPos **DelMe)
 /**
  * @brief Get the data located where HashPos Iterator points at, and Move HashPos one forward
  * @param Hash your Hashlist to follow
+ * @param At the position to retrieve the Item from and move forward afterwards
  * @param HKLen returns Length of Hashkey Returned
  * @param HashKey returns the Hashkey corrosponding to HashPos
  * @param Data returns the Data found at HashPos
@@ -743,6 +744,57 @@ int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, const char **HashKe
        return 1;
 }
 
+/**
+ * @brief Get the data located where HashPos Iterator points at
+ * @param Hash your Hashlist to follow
+ * @param At the position retrieve the data from
+ * @param HKLen returns Length of Hashkey Returned
+ * @param HashKey returns the Hashkey corrosponding to HashPos
+ * @param Data returns the Data found at HashPos
+ * \returns whether the item was found or not.
+ */
+int GetHashPos(HashList *Hash, HashPos *At, long *HKLen, const char **HashKey, void **Data)
+{
+       long PayloadPos;
+
+       if ((Hash == NULL) || 
+           (At->Position >= Hash->nLookupTableItems) || 
+           (At->Position < 0) ||
+           (At->Position > Hash->nLookupTableItems))
+               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;
+
+       return 1;
+}
+
+/**
+ * @brief Move HashPos one forward
+ * @param Hash your Hashlist to follow
+ * @param At the position to move forward
+ * \returns whether there is a next item or not.
+ */
+int NextHashPos(HashList *Hash, HashPos *At)
+{
+       if ((Hash == NULL) || 
+           (At->Position >= Hash->nLookupTableItems) || 
+           (At->Position < 0) ||
+           (At->Position > Hash->nLookupTableItems))
+               return 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->StepWidth / abs(At->StepWidth));
+       return !((At->Position >= Hash->nLookupTableItems) || 
+                (At->Position < 0) ||
+                (At->Position > Hash->nLookupTableItems));
+}
+
 /**
  * @brief Get the data located where At points to
  * note: you should prefer iterator operations instead of using me.
index 4904ff760ce01240ff6e8305af9832ebe8ff2f65..83896a344ba87ed6fc0d2e52000ce1479ea26b51 100644 (file)
@@ -402,6 +402,8 @@ int GetHashPosFromKey(HashList *Hash, const char *HKey, long HKLen, HashPos *At)
 int DeleteEntryFromHash(HashList *Hash, HashPos *At);
 int GetHashPosCounter(HashList *Hash, HashPos *At);
 void DeleteHashPos(HashPos **DelMe);
+int NextHashPos(HashList *Hash, HashPos *At);
+int GetHashPos(HashList *Hash, HashPos *At, long *HKLen, const char **HashKey, void **Data);
 int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, const char **HashKey, void **Data);
 int GetHashAt(HashList *Hash,long At, long *HKLen, const char **HashKey, void **Data);
 void SortByHashKey(HashList *Hash, int Order);