From 388b6e6e8f7b95f2c6b67e272470a1f2477965b2 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 1 Nov 2012 15:01:04 +0900 Subject: [PATCH] Add set_size (). Return the number of members in the set. --- tools/qfcc/include/set.h | 1 + tools/qfcc/source/set.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/tools/qfcc/include/set.h b/tools/qfcc/include/set.h index 01d17b4a6..65af7bdc8 100644 --- a/tools/qfcc/include/set.h +++ b/tools/qfcc/include/set.h @@ -69,6 +69,7 @@ int set_is_intersecting (const set_t *s1, const set_t *s2); int set_is_equivalent (const set_t *s1, const set_t *s2); int set_is_subset (const set_t *set, const set_t *sub); int set_is_member (const set_t *set, unsigned x); +unsigned set_size (const set_t *set); setstate_t *set_first (const set_t *set); setstate_t *set_next (setstate_t *setstate); const char *set_as_string (const set_t *set); diff --git a/tools/qfcc/source/set.c b/tools/qfcc/source/set.c index 9ff61ca86..57279bf71 100644 --- a/tools/qfcc/source/set.c +++ b/tools/qfcc/source/set.c @@ -269,6 +269,18 @@ set_is_member (const set_t *set, unsigned x) return (set->map[x / BITS] & (1 << (x % BITS))) != 0; } +unsigned +set_size (const set_t *set) +{ + unsigned count = 0; + unsigned i; + + for (i = 0; i < set->size; i++) + if (set_is_member (set, i)) + count++; + return count; +} + setstate_t * set_first (const set_t *set) {