]> code.citadel.org Git - citadel.git/blobdiff - libcitadel/lib/hash.c
* handle negative index condition
[citadel.git] / libcitadel / lib / hash.c
index fd8916f1757988627045b9dca75f7088e5b6025f..b8ba8c346839ac267ebcad69e39a835e8bfea0f6 100644 (file)
@@ -619,7 +619,7 @@ int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, const char **HashKe
 {
        long PayloadPos;
 
-       if ((Hash == NULL) || (At->Position >= Hash->nMembersUsed))
+       if ((Hash == NULL) || (At->Position >= Hash->nMembersUsed) || (At->Position < 0))
                return 0;
        *HKLen = Hash->LookupTable[At->Position]->HKLen;
        *HashKey = Hash->LookupTable[At->Position]->HashKey;
@@ -634,6 +634,28 @@ int GetNextHashPos(HashList *Hash, HashPos *At, long *HKLen, const char **HashKe
        return 1;
 }
 
+/**
+ * \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
+ * \returns 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 >= Hash->nMembersUsed))
+               return 0;
+       *HKLen = Hash->LookupTable[At]->HKLen;
+       *HashKey = Hash->LookupTable[At]->HashKey;
+       PayloadPos = Hash->LookupTable[At]->Position;
+       *Data = Hash->Members[PayloadPos]->Data;
+       return 1;
+}
+
 /**
  * \brief sorting function for sorting the Hash alphabeticaly by their strings
  * \param Key1 first item