[xbuild] Vbc task - make error column check a little non-specific.
[mono.git] / mono / utils / monobitset.h
1 #ifndef __MONO_BITSET_H__
2 #define __MONO_BITSET_H__
3
4 #include <glib.h>
5
6 /*
7  * When embedding, you have to define MONO_ZERO_LEN_ARRAY before including any
8  * other Mono header file if you use a different compiler from the one used to
9  * build Mono.
10  */
11 #ifndef MONO_ZERO_LEN_ARRAY
12 #ifdef __GNUC__
13 #define MONO_ZERO_LEN_ARRAY 0
14 #else
15 #define MONO_ZERO_LEN_ARRAY 1
16 #endif
17 #endif
18
19 #define MONO_BITSET_BITS_PER_CHUNK (8 * sizeof (gsize))
20
21 typedef struct {
22         gsize size;
23         gsize flags;
24         gsize data [MONO_ZERO_LEN_ARRAY];
25 } MonoBitSet;
26
27 typedef void (*MonoBitSetFunc) (guint idx, gpointer data);
28
29 enum {
30         MONO_BITSET_DONT_FREE = 1
31 };
32
33 /* Fast access to bits which depends on the implementation of the bitset */
34 #define mono_bitset_test_fast(set,n) ((set)->data [(n)/MONO_BITSET_BITS_PER_CHUNK] & ((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)))
35 #define mono_bitset_test_fast(set,n) ((set)->data [(n)/MONO_BITSET_BITS_PER_CHUNK] & ((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)))
36 #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)
37 #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)
38 #define mono_bitset_get_fast(set,n) ((set)->data[(n)])
39
40 #define mono_bitset_copyto_fast(src,dest) do { memcpy (&(dest)->data, &(src)->data, (dest)->size / 8); } while (0)
41
42 #define mono_bitset_union_fast(dest,src) do { \
43     MonoBitSet *tmp_src = (src); \
44     MonoBitSet *tmp_dest = (dest); \
45     int i, size; \
46         size = tmp_dest->size / MONO_BITSET_BITS_PER_CHUNK; \
47         for (i = 0; i < size; ++i) \
48                 tmp_dest->data [i] |= tmp_src->data [i]; \
49 } while (0)
50
51 #define mono_bitset_sub_fast(dest,src) do { \
52     MonoBitSet *tmp_src = (src); \
53     MonoBitSet *tmp_dest = (dest); \
54     int i, size; \
55         size = tmp_dest->size / MONO_BITSET_BITS_PER_CHUNK; \
56         for (i = 0; i < size; ++i) \
57                 tmp_dest->data [i] &= ~tmp_src->data [i]; \
58 } while (0)
59
60 /*
61  * Interface documentation can be found in the c-file.
62  * Interface documentation by Dennis Haney.
63  */
64
65 guint32     mono_bitset_alloc_size   (guint32 max_size, guint32 flags);
66
67 MonoBitSet* mono_bitset_new          (guint32 max_size, guint32 flags);
68
69 MonoBitSet* mono_bitset_mem_new      (gpointer mem, guint32 max_size, guint32 flags);
70
71 void        mono_bitset_free         (MonoBitSet *set); 
72
73 void        mono_bitset_set          (MonoBitSet *set, guint32 pos);
74
75 void        mono_bitset_set_all      (MonoBitSet *set);
76
77 int         mono_bitset_test         (const MonoBitSet *set, guint32 pos);
78
79 gsize       mono_bitset_test_bulk    (const MonoBitSet *set, guint32 pos);
80
81 void        mono_bitset_clear        (MonoBitSet *set, guint32 pos);
82
83 void        mono_bitset_clear_all    (MonoBitSet *set);
84
85 void        mono_bitset_invert       (MonoBitSet *set);
86
87 guint32     mono_bitset_size         (const MonoBitSet *set);
88
89 guint32     mono_bitset_count        (const MonoBitSet *set);
90
91 void        mono_bitset_low_high     (const MonoBitSet *set, guint32 *low, guint32 *high);
92
93 int         mono_bitset_find_start   (const MonoBitSet *set);
94
95 int         mono_bitset_find_first   (const MonoBitSet *set, gint pos);
96
97 int         mono_bitset_find_last    (const MonoBitSet *set, gint pos);
98
99 int         mono_bitset_find_first_unset (const MonoBitSet *set, gint pos);
100
101 MonoBitSet* mono_bitset_clone        (const MonoBitSet *set, guint32 new_size);
102
103 void        mono_bitset_copyto       (const MonoBitSet *src, MonoBitSet *dest);
104
105 void        mono_bitset_union        (MonoBitSet *dest, const MonoBitSet *src);
106
107 void        mono_bitset_intersection (MonoBitSet *dest, const MonoBitSet *src);
108
109 void        mono_bitset_sub          (MonoBitSet *dest, const MonoBitSet *src);
110
111 gboolean    mono_bitset_equal        (const MonoBitSet *src, const MonoBitSet *src1);
112
113 void        mono_bitset_foreach      (MonoBitSet *set, MonoBitSetFunc func, gpointer data);
114
115 void        mono_bitset_intersection_2 (MonoBitSet *dest, const MonoBitSet *src1, const MonoBitSet *src2);
116
117 #endif /* __MONO_BITSET_H__ */