1 #ifndef __MONO_BITSET_H__
2 #define __MONO_BITSET_H__
5 #include <mono/utils/mono-publib.h>
7 #define MONO_BITSET_BITS_PER_CHUNK (8 * sizeof (gsize))
12 gsize data
[MONO_ZERO_LEN_ARRAY
];
15 typedef void (*MonoBitSetFunc
) (guint idx
, gpointer data
);
18 MONO_BITSET_DONT_FREE
= 1
21 /* Fast access to bits which depends on the implementation of the bitset */
22 #define mono_bitset_test_fast(set,n) ((set)->data [(n)/MONO_BITSET_BITS_PER_CHUNK] & ((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)))
23 #define mono_bitset_set_fast(set,n) do { (set)->data [(n)/MONO_BITSET_BITS_PER_CHUNK] |= ((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)); } while (0)
24 #define mono_bitset_clear_fast(set,n) do { (set)->data [(n)/MONO_BITSET_BITS_PER_CHUNK] &= ~((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)); } while (0)
25 #define mono_bitset_get_fast(set,n) ((set)->data[(n)])
27 #define mono_bitset_copyto_fast(src,dest) do { memcpy (&(dest)->data, &(src)->data, (dest)->size / 8); } while (0)
29 #define MONO_BITSET_FOREACH(set,idx,/*stmt*/...) \
32 MonoBitSet *set__ = (set); \
33 for (int i__ = 0; i__ < set__->size / MONO_BITSET_BITS_PER_CHUNK; i__++) { \
34 if (set__->data [i__]) { \
35 for (int j__ = 0; j__ < MONO_BITSET_BITS_PER_CHUNK; j__++) { \
36 if (set__->data [i__] & ((gsize) 1 << j__)) { \
37 guint idx = j__ + i__ * MONO_BITSET_BITS_PER_CHUNK; \
45 #define mono_bitset_union_fast(dest,src) do { \
46 MonoBitSet *tmp_src = (src); \
47 MonoBitSet *tmp_dest = (dest); \
49 size = tmp_dest->size / MONO_BITSET_BITS_PER_CHUNK; \
50 for (i = 0; i < size; ++i) \
51 tmp_dest->data [i] |= tmp_src->data [i]; \
54 #define mono_bitset_sub_fast(dest,src) do { \
55 MonoBitSet *tmp_src = (src); \
56 MonoBitSet *tmp_dest = (dest); \
58 size = tmp_dest->size / MONO_BITSET_BITS_PER_CHUNK; \
59 for (i = 0; i < size; ++i) \
60 tmp_dest->data [i] &= ~tmp_src->data [i]; \
64 * Interface documentation can be found in the c-file.
65 * Interface documentation by Dennis Haney.
68 MONO_API guint32
mono_bitset_alloc_size (guint32 max_size
, guint32 flags
);
70 MONO_API MonoBitSet
* mono_bitset_new (guint32 max_size
, guint32 flags
);
72 MONO_API MonoBitSet
* mono_bitset_mem_new (gpointer mem
, guint32 max_size
, guint32 flags
);
74 MONO_API
void mono_bitset_free (MonoBitSet
*set
);
76 MONO_API
void mono_bitset_set (MonoBitSet
*set
, guint32 pos
);
78 MONO_API
void mono_bitset_set_all (MonoBitSet
*set
);
80 MONO_API
int mono_bitset_test (const MonoBitSet
*set
, guint32 pos
);
82 MONO_API gsize
mono_bitset_test_bulk (const MonoBitSet
*set
, guint32 pos
);
84 MONO_API
void mono_bitset_clear (MonoBitSet
*set
, guint32 pos
);
86 MONO_API
void mono_bitset_clear_all (MonoBitSet
*set
);
88 MONO_API
void mono_bitset_invert (MonoBitSet
*set
);
90 MONO_API guint32
mono_bitset_size (const MonoBitSet
*set
);
92 MONO_API guint32
mono_bitset_count (const MonoBitSet
*set
);
94 MONO_API
void mono_bitset_low_high (const MonoBitSet
*set
, guint32
*low
, guint32
*high
);
96 MONO_API
int mono_bitset_find_start (const MonoBitSet
*set
);
98 MONO_API
int mono_bitset_find_first (const MonoBitSet
*set
, gint pos
);
100 MONO_API
int mono_bitset_find_last (const MonoBitSet
*set
, gint pos
);
102 MONO_API
int mono_bitset_find_first_unset (const MonoBitSet
*set
, gint pos
);
104 MONO_API MonoBitSet
* mono_bitset_clone (const MonoBitSet
*set
, guint32 new_size
);
106 MONO_API
void mono_bitset_copyto (const MonoBitSet
*src
, MonoBitSet
*dest
);
108 MONO_API
void mono_bitset_union (MonoBitSet
*dest
, const MonoBitSet
*src
);
110 MONO_API
void mono_bitset_intersection (MonoBitSet
*dest
, const MonoBitSet
*src
);
112 MONO_API
void mono_bitset_sub (MonoBitSet
*dest
, const MonoBitSet
*src
);
114 MONO_API gboolean
mono_bitset_equal (const MonoBitSet
*src
, const MonoBitSet
*src1
);
116 MONO_API
void mono_bitset_foreach (MonoBitSet
*set
, MonoBitSetFunc func
, gpointer data
);
118 MONO_API
void mono_bitset_intersection_2 (MonoBitSet
*dest
, const MonoBitSet
*src1
, const MonoBitSet
*src2
);
120 #endif /* __MONO_BITSET_H__ */