+
+ return 1;
+}
+
+/**
+ * @ingroup HashListAccess
+ * @brief Move HashPos one forward
+ * @param Hash your Hashlist to follow
+ * @param At the position to move forward
+ * @return 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));
+}
+
+/**
+ * @ingroup HashListAccess
+ * @brief Get the data located where At points to
+ * note: you should prefer iterator operations instead of using me.
+ * @param Hash your Hashlist peek from
+ * @param At get the item in the position At.
+ * @param HKLen returns Length of Hashkey Returned
+ * @param HashKey returns the Hashkey corrosponding to HashPos
+ * @param Data returns the Data found at HashPos
+ * @return whether the item was found or not.
+ */
+int GetHashAt(HashList *Hash,long At, long *HKLen, const char **HashKey, void **Data)
+{
+ long PayloadPos;
+
+ if ((Hash == NULL) ||
+ (At < 0) ||
+ (At >= Hash->nLookupTableItems))
+ return 0;
+ *HKLen = Hash->LookupTable[At]->HKLen;
+ *HashKey = Hash->LookupTable[At]->HashKey;
+ PayloadPos = Hash->LookupTable[At]->Position;
+ *Data = Hash->Members[PayloadPos]->Data;
+ return 1;
+}
+
+/**
+ * @ingroup HashListSort
+ * @brief Get the data located where At points to
+ * note: you should prefer iterator operations instead of using me.
+ * @param Hash your Hashlist peek from
+ * @param HKLen returns Length of Hashkey Returned
+ * @param HashKey returns the Hashkey corrosponding to HashPos
+ * @param Data returns the Data found at HashPos
+ * @return whether the item was found or not.
+ */
+/*
+long GetHashIDAt(HashList *Hash,long At)
+{
+ if ((Hash == NULL) ||
+ (At < 0) ||
+ (At > Hash->nLookupTableItems))
+ return 0;
+
+ return Hash->LookupTable[At]->Key;
+}
+*/
+
+
+/**
+ * @ingroup HashListSort
+ * @brief sorting function for sorting the Hash alphabeticaly by their strings
+ * @param Key1 first item
+ * @param Key2 second item
+ */
+static int SortByKeys(const void *Key1, const void* Key2)
+{
+ HashKey *HKey1, *HKey2;
+ HKey1 = *(HashKey**) Key1;
+ HKey2 = *(HashKey**) Key2;
+
+ return strcasecmp(HKey1->HashKey, HKey2->HashKey);
+}
+
+/**
+ * @ingroup HashListSort
+ * @brief sorting function for sorting the Hash alphabeticaly reverse by their strings
+ * @param Key1 first item
+ * @param Key2 second item
+ */
+static int SortByKeysRev(const void *Key1, const void* Key2)
+{
+ HashKey *HKey1, *HKey2;
+ HKey1 = *(HashKey**) Key1;
+ HKey2 = *(HashKey**) Key2;
+
+ return strcasecmp(HKey2->HashKey, HKey1->HashKey);
+}
+
+/**
+ * @ingroup HashListSort
+ * @brief sorting function to regain hash-sequence and revert tainted status
+ * @param Key1 first item
+ * @param Key2 second item
+ */
+static int SortByHashKeys(const void *Key1, const void* Key2)
+{
+ HashKey *HKey1, *HKey2;
+ HKey1 = *(HashKey**) Key1;
+ HKey2 = *(HashKey**) Key2;
+
+ return HKey1->Key > HKey2->Key;
+}
+
+
+/**
+ * @ingroup HashListSort
+ * @brief sort the hash alphabeticaly by their keys.
+ * Caution: This taints the hashlist, so accessing it later
+ * will be significantly slower! You can un-taint it by SortByHashKeyStr
+ * @param Hash the list to sort
+ * @param Order 0/1 Forward/Backward
+ */
+void SortByHashKey(HashList *Hash, int Order)
+{
+ if (Hash->nLookupTableItems < 2)
+ return;
+ qsort(Hash->LookupTable, Hash->nLookupTableItems, sizeof(HashKey*),
+ (Order)?SortByKeys:SortByKeysRev);
+ Hash->tainted = 1;
+}
+
+/**
+ * @ingroup HashListSort
+ * @brief sort the hash by their keys (so it regains untainted state).
+ * this will result in the sequence the hashing allgorithm produces it by default.
+ * @param Hash the list to sort
+ */
+void SortByHashKeyStr(HashList *Hash)
+{
+ Hash->tainted = 0;
+ if (Hash->nLookupTableItems < 2)
+ return;
+ qsort(Hash->LookupTable, Hash->nLookupTableItems, sizeof(HashKey*), SortByHashKeys);
+}
+
+
+/**
+ * @ingroup HashListSort
+ * @brief gives user sort routines access to the hash payload
+ * @param HashVoid to retrieve Data to
+ * @return Data belonging to HashVoid
+ */
+const void *GetSearchPayload(const void *HashVoid)
+{
+ return (*(HashKey**)HashVoid)->PL->Data;
+}
+
+/**
+ * @ingroup HashListSort
+ * @brief sort the hash by your sort function. see the following sample.
+ * this will result in the sequence the hashing allgorithm produces it by default.
+ * @param Hash the list to sort
+ * @param SortBy Sortfunction; see below how to implement this
+ */
+void SortByPayload(HashList *Hash, CompareFunc SortBy)
+{
+ if (Hash->nLookupTableItems < 2)
+ return;
+ qsort(Hash->LookupTable, Hash->nLookupTableItems, sizeof(HashKey*), SortBy);
+ Hash->tainted = 1;
+}
+
+
+
+
+/**
+ * given you've put char * into your hash as a payload, a sort function might
+ * look like this:
+ * int SortByChar(const void* First, const void* Second)
+ * {
+ * char *a, *b;
+ * a = (char*) GetSearchPayload(First);
+ * b = (char*) GetSearchPayload(Second);
+ * return strcmp (a, b);
+ * }
+ */
+
+
+/**
+ * @ingroup HashListAccess
+ * @brief Generic function to free a reference.
+ * since a reference actualy isn't needed to be freed, do nothing.
+ */
+void reference_free_handler(void *ptr)
+{
+ return;
+}
+
+
+/**
+ * @ingroup HashListAlgorithm
+ * This exposes the hashlittle() function to consumers.
+ */
+int HashLittle(const void *key, size_t length) {
+ return (int)hashlittle(key, length, 1);
+}
+
+
+/**
+ * @ingroup HashListMset
+ * @brief parses an MSet string into a list for later use
+ * @param MSetList List to be read from MSetStr
+ * @param MSetStr String containing the list
+ */
+int ParseMSet(MSet **MSetList, StrBuf *MSetStr)
+{
+ const char *POS = NULL, *SetPOS = NULL;
+ StrBuf *OneSet;
+ HashList *ThisMSet;
+ long StartSet, EndSet;
+ long *pEndSet;
+
+ *MSetList = NULL;
+ if ((MSetStr == NULL) || (StrLength(MSetStr) == 0))
+ return 0;
+
+ OneSet = NewStrBufPlain(NULL, StrLength(MSetStr));
+
+ ThisMSet = NewHash(0, lFlathash);
+
+ *MSetList = (MSet*) ThisMSet;
+
+ /* an MSet is a coma separated value list. */
+ StrBufExtract_NextToken(OneSet, MSetStr, &POS, ',');
+ do {
+ SetPOS = NULL;
+
+ /* One set may consist of two Numbers: Start + optional End */
+ StartSet = StrBufExtractNext_long(OneSet, &SetPOS, ':');
+ EndSet = 0; /* no range is our default. */
+ /* do we have an end (aka range?) */
+ if ((SetPOS != NULL) && (SetPOS != StrBufNOTNULL))
+ {
+ if (*(SetPOS) == '*')
+ EndSet = LONG_MAX; /* ranges with '*' go until infinity */
+ else
+ /* in other cases, get the EndPoint */
+ EndSet = StrBufExtractNext_long(OneSet, &SetPOS, ':');
+ }
+
+ pEndSet = (long*) malloc (sizeof(long));
+ *pEndSet = EndSet;
+
+ Put(ThisMSet, LKEY(StartSet), pEndSet, NULL);
+ /* if we don't have another, we're done. */
+ if (POS == StrBufNOTNULL)
+ break;
+ StrBufExtract_NextToken(OneSet, MSetStr, &POS, ',');
+ } while (1);
+ FreeStrBuf(&OneSet);
+