diff --git a/include/QF/set.h b/include/QF/set.h index e0160c61c..0fc200cb5 100644 --- a/include/QF/set.h +++ b/include/QF/set.h @@ -428,6 +428,9 @@ set_iter_t *set_first_r (set_pool_t *set_pool, const set_t *set); set_iter_t *set_next (set_iter_t *set_iter); set_iter_t *set_next_r (set_pool_t *set_pool, set_iter_t *set_iter); +set_iter_t *set_while (set_iter_t *set_iter); +set_iter_t *set_while_r (set_pool_t *set_pool, set_iter_t *set_iter); + struct dstring_s; /** Return a human-readable string representing the set. diff --git a/libs/util/set.c b/libs/util/set.c index c4dc8ab94..e391583a6 100644 --- a/libs/util/set.c +++ b/libs/util/set.c @@ -734,6 +734,36 @@ set_next (set_iter_t *set_iter) return set_next_r (&static_set_pool, set_iter); } +set_iter_t * +set_while_r (set_pool_t *set_pool, set_iter_t *set_iter) +{ + unsigned x; + + if (_set_is_member (set_iter->set, set_iter->element)) { + for (x = set_iter->element + 1; x < set_iter->set->size; x++) { + if (!_set_is_member (set_iter->set, x)) { + set_iter->element = x; + return set_iter; + } + } + } else { + for (x = set_iter->element + 1; x < set_iter->set->size; x++) { + if (_set_is_member (set_iter->set, x)) { + set_iter->element = x; + return set_iter; + } + } + } + delete_setiter (set_pool, set_iter); + return 0; +} + +set_iter_t * +set_while (set_iter_t *set_iter) +{ + return set_while_r (&static_set_pool, set_iter); +} + const char * set_to_dstring_r (set_pool_t *set_pool, dstring_t *str, const set_t *set) {