From 6822daf20693ae6b6b98bb4a5c44b67793e16792 Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Wed, 31 Oct 2012 23:08:32 -0700 Subject: [PATCH] sset: Add sset_at_position() function. This will be useful in a future commit. Suggested-by: Ben Pfaff Signed-off-by: Justin Pettit --- lib/sset.c | 19 +++++++++++++++++++ lib/sset.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/lib/sset.c b/lib/sset.c index ee4224a4..04039a7c 100644 --- a/lib/sset.c +++ b/lib/sset.c @@ -251,3 +251,22 @@ sset_equals(const struct sset *a, const struct sset *b) return true; } + +/* Returns the next node in 'set' in hash order, or NULL if no nodes remain in + * 'set'. Uses '*bucketp' and '*offsetp' to determine where to begin + * iteration, and stores new values to pass on the next iteration into them + * before returning. + * + * It's better to use plain SSET_FOR_EACH and related functions, since they are + * faster and better at dealing with ssets that change during iteration. + * + * Before beginning iteration, store 0 into '*bucketp' and '*offsetp'. + */ +struct sset_node * +sset_at_position(const struct sset *set, uint32_t *bucketp, uint32_t *offsetp) +{ + struct hmap_node *hmap_node; + + hmap_node = hmap_at_position(&set->map, bucketp, offsetp); + return SSET_NODE_FROM_HMAP_NODE(hmap_node); +} diff --git a/lib/sset.h b/lib/sset.h index f63f4ab9..327074c9 100644 --- a/lib/sset.h +++ b/lib/sset.h @@ -64,6 +64,8 @@ char *sset_pop(struct sset *); struct sset_node *sset_find(const struct sset *, const char *); bool sset_contains(const struct sset *, const char *); bool sset_equals(const struct sset *, const struct sset *); +struct sset_node *sset_at_position(const struct sset *, + uint32_t *bucketp, uint32_t *offsetp); /* Iteration macros. */ #define SSET_FOR_EACH(NAME, SSET) \ -- 2.30.2