HASH: add a way to reset an iterator
authorWilfried Goesgens <dothebart@citadel.org>
Thu, 27 Dec 2012 23:00:26 +0000 (00:00 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Thu, 27 Dec 2012 23:00:26 +0000 (00:00 +0100)
libcitadel/lib/hash.c
libcitadel/lib/libcitadel.h

index 38d780ed4f4695ace5a61a24dda0f9b02ca85a28..0eedcab41c3850fd35746079009842e8a97050d3 100644 (file)
@@ -809,6 +809,30 @@ HashPos *GetNewHashPos(const HashList *Hash, int StepWidth)
        return Ret;
 }
 
+/**
+ * @ingroup HashListAccess
+ * @brief resets a hash-linear iterator object
+ * @param Hash the list we reference
+ * @param StepWidth in which step width should we iterate?
+ * @param it the iterator object to manipulate
+ *  If negative, the last position matching the 
+ *  step-raster is provided.
+ * @return the hash iterator
+ */
+void RewindHashPos(const HashList *Hash, HashPos *it, int StepWidth)
+{
+       if (StepWidth != 0)
+               it->StepWidth = StepWidth;
+       else
+               it->StepWidth = 1;
+       if (it->StepWidth <  0) {
+               it->Position = Hash->nLookupTableItems - 1;
+       }
+       else {
+               it->Position = 0;
+       }
+}
+
 /**
  * @ingroup HashListAccess
  * @brief Set iterator object to point to key. If not found, don't change iterator
index ce9baf9dd1ef7da4bbb914427dcf40448f614711..02b9c9a4755352b5e3fdedec9daac474e41fdc99 100644 (file)
@@ -48,7 +48,7 @@ typedef enum AXLevel {
        AxAideU = 6
 }eUsrAxlvl;
 
-enum RoomNetCfg {
+typedef enum __RoomNetCfg {
        subpending,
        unsubpending,
        lastsent, /* Server internal use only */
@@ -60,7 +60,7 @@ enum RoomNetCfg {
        participate,
        roommailalias,
        maxRoomNetCfg
-};
+} RoomNetCfg;
 
 enum GNET_POP3_PARTS { /* pop3client splits into these columns: */
        GNET_POP3_HOST = 1,
@@ -514,6 +514,7 @@ int GetHashKeys(HashList *Hash, char ***List);
 int dbg_PrintHash(HashList *Hash, PrintHashContent first, PrintHashContent Second);
 int PrintHash(HashList *Hash, TransitionFunc Trans, PrintHashDataFunc PrintEntry);
 HashPos *GetNewHashPos(const HashList *Hash, int StepWidth);
+void RewindHashPos(const HashList *Hash, HashPos *it, int StepWidth);
 int GetHashPosFromKey(HashList *Hash, const char *HKey, long HKLen, HashPos *At);
 int DeleteEntryFromHash(HashList *Hash, HashPos *At);
 int GetHashPosCounter(HashList *Hash, HashPos *At);