Add set_as_string for debug output.

This commit is contained in:
Bill Currie 2012-10-30 20:10:25 +09:00
parent d2fab28d01
commit 964ea7f9fe
2 changed files with 22 additions and 0 deletions

View file

@ -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);
const char *set_as_string (const set_t *set);
//@}
#endif//set_h

View file

@ -40,6 +40,7 @@
#include <stdlib.h>
#include "QF/dstring.h"
#include "QF/mathlib.h"
#include "set.h"
@ -243,3 +244,23 @@ set_is_member (const set_t *set, unsigned x)
return 0;
return (set->map[x / BITS] & (1 << (x % BITS))) != 0;
}
const char *
set_as_string (const set_t *set)
{
static dstring_t *str;
unsigned i;
if (!str)
str = dstring_new ();
dstring_clearstr (str);
for (i = 0; i < set->size; i++) {
if (set_is_member (set, i)) {
if (str->str[0])
dasprintf (str, " %d", i);
else
dsprintf (str, "%d", i);
}
}
return str->str;
}