mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-27 06:34:11 +00:00
Add set_first.
It returns the first element of a set. If the set is empty, -1 (unsigned) is returned.
This commit is contained in:
parent
4cc8d4a04b
commit
8fb958603c
2 changed files with 12 additions and 0 deletions
|
@ -59,6 +59,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_first (const set_t *set);
|
||||
const char *set_as_string (const set_t *set);
|
||||
|
||||
//@}
|
||||
|
|
|
@ -245,6 +245,17 @@ set_is_member (const set_t *set, unsigned x)
|
|||
return (set->map[x / BITS] & (1 << (x % BITS))) != 0;
|
||||
}
|
||||
|
||||
unsigned
|
||||
set_first (const set_t *set)
|
||||
{
|
||||
unsigned x;
|
||||
|
||||
for (x = 0; x < set->size; x++)
|
||||
if (set_is_member (set, x))
|
||||
return x;
|
||||
return -1; // FIXME error?
|
||||
}
|
||||
|
||||
const char *
|
||||
set_as_string (const set_t *set)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue