+
+/**
+ * \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);
+}
+
+/**
+ * \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;
+}
+
+
+/**
+ * \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
+ */
+void SortByHashKey(HashList *Hash)
+{
+ if (Hash->nMembersUsed < 2)
+ return;
+ qsort(Hash->LookupTable, Hash->nMembersUsed, sizeof(HashKey*), SortByKeys);
+ Hash->tainted = 1;
+}
+
+/**
+ * \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->nMembersUsed < 2)
+ return;
+ qsort(Hash->LookupTable, Hash->nMembersUsed, sizeof(HashKey*), SortByHashKeys);
+}
+
+
+/**
+ * \brief gives user sort routines access to the hash payload
+ * \param Searchentry to retrieve Data to
+ * \returns Data belonging to HashVoid
+ */
+const void *GetSearchPayload(const void *HashVoid)
+{
+ return (*(HashKey**)HashVoid)->PL->Data;
+}
+
+/**
+ * \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->nMembersUsed < 2)
+ return;
+ qsort(Hash->LookupTable, Hash->nMembersUsed, 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);
+ * }
+ */