Skip to content

Commit f1dc033

Browse files
committed
pmix3x: add the PMIX_HASH_TABLE_FOREACH macro
this is a convenience macro similar to the PMIX_LIST_FOREACH macro, that can be used to iterate on all the key/value pairs of a pmix_hash_table_t (back-ported from upstream commit openpmix/openpmix@349971c)
1 parent 73298ad commit f1dc033

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

opal/mca/pmix/pmix3x/pmix/src/class/pmix_hash_table.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
1212
* Copyright (c) 2015-2016 Intel, Inc. All rights reserved.
13-
* Copyright (c) 2015 Research Organization for Information Science
13+
* Copyright (c) 2015-2016 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
1515
* Copyright (c) 2016 Mellanox Technologies, Inc.
1616
* All rights reserved.
@@ -371,6 +371,29 @@ static inline int pmix_next_poweroftwo(int value)
371371
}
372372

373373

374+
/**
375+
* Loop over a hash table.
376+
*
377+
* @param[in] key Key for each item
378+
* @param[in] type Type of key (ui32|ui64|ptr)
379+
* @param[in] value Storage for each item
380+
* @param[in] ht Hash table to iterate over
381+
*
382+
* This macro provides a simple way to loop over the items in a pmix_hash_table_t. It
383+
* is not safe to call pmix_hash_table_remove* from within the loop.
384+
*
385+
* Example Usage:
386+
*
387+
* uint64_t key;
388+
* void * value;
389+
* PMIX_HASH_TABLE_FOREACH(key, uint64, value, ht) {
390+
* do_something(key, value);
391+
* }
392+
*/
393+
#define PMIX_HASH_TABLE_FOREACH(key, type, value, ht) \
394+
for (void *_nptr=NULL; \
395+
PMIX_SUCCESS == pmix_hash_table_get_next_key_##type(ht, &key, (void **)&value, _nptr, &_nptr);)
396+
374397
END_C_DECLS
375398

376399
#endif /* PMIX_HASH_TABLE_H */

0 commit comments

Comments
 (0)