From 101a56a24149e797b4f8ae555f9aa004cb5f446d Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Fri, 28 Dec 2012 00:00:26 +0100 Subject: [PATCH] HASH: add a way to reset an iterator --- libcitadel/lib/hash.c | 24 ++++++++++++++++++++++++ libcitadel/lib/libcitadel.h | 5 +++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/libcitadel/lib/hash.c b/libcitadel/lib/hash.c index 38d780ed4..0eedcab41 100644 --- a/libcitadel/lib/hash.c +++ b/libcitadel/lib/hash.c @@ -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 diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index ce9baf9dd..02b9c9a47 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -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); -- 2.30.2