1 #ifndef __MONO_BITSET_H__
2 #define __MONO_BITSET_H__
5 #ifdef SGEN_WITHOUT_MONO
6 #include "mono/utils/mono-compiler.h"
9 #include <mono/utils/mono-publib.h>
13 * When embedding, you have to define MONO_ZERO_LEN_ARRAY before including any
14 * other Mono header file if you use a different compiler from the one used to
17 #ifndef MONO_ZERO_LEN_ARRAY
19 #define MONO_ZERO_LEN_ARRAY 0
21 #define MONO_ZERO_LEN_ARRAY 1
25 #define MONO_BITSET_BITS_PER_CHUNK (8 * sizeof (gsize))
30 gsize data [MONO_ZERO_LEN_ARRAY];
33 typedef void (*MonoBitSetFunc) (guint idx, gpointer data);
36 MONO_BITSET_DONT_FREE = 1
39 /* Fast access to bits which depends on the implementation of the bitset */
40 #define mono_bitset_test_fast(set,n) ((set)->data [(n)/MONO_BITSET_BITS_PER_CHUNK] & ((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)))
41 #define mono_bitset_test_fast(set,n) ((set)->data [(n)/MONO_BITSET_BITS_PER_CHUNK] & ((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)))
42 #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)
43 #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)
44 #define mono_bitset_get_fast(set,n) ((set)->data[(n)])
46 #define mono_bitset_copyto_fast(src,dest) do { memcpy (&(dest)->data, &(src)->data, (dest)->size / 8); } while (0)
48 #define mono_bitset_union_fast(dest,src) do { \
49 MonoBitSet *tmp_src = (src); \
50 MonoBitSet *tmp_dest = (dest); \
52 size = tmp_dest->size / MONO_BITSET_BITS_PER_CHUNK; \
53 for (i = 0; i < size; ++i) \
54 tmp_dest->data [i] |= tmp_src->data [i]; \
57 #define mono_bitset_sub_fast(dest,src) do { \
58 MonoBitSet *tmp_src = (src); \
59 MonoBitSet *tmp_dest = (dest); \
61 size = tmp_dest->size / MONO_BITSET_BITS_PER_CHUNK; \
62 for (i = 0; i < size; ++i) \
63 tmp_dest->data [i] &= ~tmp_src->data [i]; \
67 * Interface documentation can be found in the c-file.
68 * Interface documentation by Dennis Haney.
71 MONO_API guint32 mono_bitset_alloc_size (guint32 max_size, guint32 flags);
73 MONO_API MonoBitSet* mono_bitset_new (guint32 max_size, guint32 flags);
75 MONO_API MonoBitSet* mono_bitset_mem_new (gpointer mem, guint32 max_size, guint32 flags);
77 MONO_API void mono_bitset_free (MonoBitSet *set);
79 MONO_API void mono_bitset_set (MonoBitSet *set, guint32 pos);
81 MONO_API void mono_bitset_set_all (MonoBitSet *set);
83 MONO_API int mono_bitset_test (const MonoBitSet *set, guint32 pos);
85 MONO_API gsize mono_bitset_test_bulk (const MonoBitSet *set, guint32 pos);
87 MONO_API void mono_bitset_clear (MonoBitSet *set, guint32 pos);
89 MONO_API void mono_bitset_clear_all (MonoBitSet *set);
91 MONO_API void mono_bitset_invert (MonoBitSet *set);
93 MONO_API guint32 mono_bitset_size (const MonoBitSet *set);
95 MONO_API guint32 mono_bitset_count (const MonoBitSet *set);
97 MONO_API void mono_bitset_low_high (const MonoBitSet *set, guint32 *low, guint32 *high);
99 MONO_API int mono_bitset_find_start (const MonoBitSet *set);
101 MONO_API int mono_bitset_find_first (const MonoBitSet *set, gint pos);
103 MONO_API int mono_bitset_find_last (const MonoBitSet *set, gint pos);
105 MONO_API int mono_bitset_find_first_unset (const MonoBitSet *set, gint pos);
107 MONO_API MonoBitSet* mono_bitset_clone (const MonoBitSet *set, guint32 new_size);
109 MONO_API void mono_bitset_copyto (const MonoBitSet *src, MonoBitSet *dest);
111 MONO_API void mono_bitset_union (MonoBitSet *dest, const MonoBitSet *src);
113 MONO_API void mono_bitset_intersection (MonoBitSet *dest, const MonoBitSet *src);
115 MONO_API void mono_bitset_sub (MonoBitSet *dest, const MonoBitSet *src);
117 MONO_API gboolean mono_bitset_equal (const MonoBitSet *src, const MonoBitSet *src1);
119 MONO_API void mono_bitset_foreach (MonoBitSet *set, MonoBitSetFunc func, gpointer data);
121 MONO_API void mono_bitset_intersection_2 (MonoBitSet *dest, const MonoBitSet *src1, const MonoBitSet *src2);
123 #endif /* __MONO_BITSET_H__ */