return NULL;
}
+
+struct getKeysIter
+{
+ virHashKeyValuePair *sortArray;
+ unsigned arrayIdx;
+};
+
+static void virHashGetKeysIterator(void *payload,
+ const void *key, void *data)
+{
+ struct getKeysIter *iter = data;
+
+ iter->sortArray[iter->arrayIdx].key = key;
+ iter->sortArray[iter->arrayIdx].value = payload;
+
+ iter->arrayIdx++;
+}
+
+typedef int (*qsort_comp)(const void *, const void *);
+
+virHashKeyValuePairPtr virHashGetItems(virHashTablePtr table,
+ virHashKeyComparator compar)
+{
+ int numElems = virHashSize(table);
+ struct getKeysIter iter = {
+ .arrayIdx = 0,
+ .sortArray = NULL,
+ };
+
+ if (numElems < 0)
+ return NULL;
+
+ if (VIR_ALLOC_N(iter.sortArray, numElems + 1)) {
+ virReportOOMError();
+ return NULL;
+ }
+
+ virHashForEach(table, virHashGetKeysIterator, &iter);
+
+ if (compar)
+ qsort(&iter.sortArray[0], numElems, sizeof(iter.sortArray[0]),
+ (qsort_comp)compar);
+
+ return iter.sortArray;
+}
*/
void *virHashSteal(virHashTablePtr table, const void *name);
+/*
+ * Get the hash table's key/value pairs and have them optionally sorted.
+ * The returned array contains virHashSize() elements. Additionally,
+ * an empty element has been added to the end of the array (with key == NULL)
+ * to indicate the end of the array.
+ * The key/value pairs are only valid as long as the underlying hash
+ * table is not modified, i.e., no keys are removed or inserted, and
+ * the hash table is not deleted.
+ * The caller must only free the returned array using VIR_FREE().
+ * The caller must make copies of all returned keys and values if they are
+ * to be used somewhere else.
+ */
+typedef struct _virHashKeyValuePair virHashKeyValuePair;
+typedef virHashKeyValuePair *virHashKeyValuePairPtr;
+struct _virHashKeyValuePair {
+ const void *key;
+ const void *value;
+};
+typedef int (*virHashKeyComparator)(const virHashKeyValuePairPtr,
+ const virHashKeyValuePairPtr);
+virHashKeyValuePairPtr virHashGetItems(virHashTablePtr table,
+ virHashKeyComparator compar);
/*
* Iterators