From bd63dbdecb0610ef7eedd8abc5e3c8f99d2d6d97 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sat, 24 Apr 2010 11:41:33 +0000 Subject: [PATCH] * offer a split version of GetNextHashPos(): GetHashPos() retrieves the item, NextHashPos() moves the iterator forward. --- libcitadel/lib/hash.c | 52 +++++++++++++++++++++++++++++++++++++ libcitadel/lib/libcitadel.h | 2 ++ 2 files changed, 54 insertions(+) diff --git a/libcitadel/lib/hash.c b/libcitadel/lib/hash.c index 2eb5e1a0d..f9ceeced3 100644 --- a/libcitadel/lib/hash.c +++ b/libcitadel/lib/hash.c @@ -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. diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index 4904ff760..83896a344 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -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); -- 2.30.2