Add set_size ().

Return the number of members in the set.
This commit is contained in:
Bill Currie 2012-11-01 15:01:04 +09:00
parent 8567508963
commit 388b6e6e8f
2 changed files with 13 additions and 0 deletions

View file

@ -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);

View file

@ -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)
{