New test.
[mono.git] / mono / utils / monobitset.h
1 #ifndef __MONO_BITSET_H__
2 #define __MONO_BITSET_H__
3
4 #include <glib.h>
5
6 typedef struct MonoBitSet MonoBitSet;
7 typedef void (*MonoBitSetFunc) (guint idx, gpointer data);
8
9 enum {
10         MONO_BITSET_DONT_FREE = 1
11 };
12
13 #define MONO_BITSET_BITS_PER_CHUNK (8 * sizeof (gsize))
14
15 /* Fast access to bits which depends on the implementation of the bitset */
16 #define mono_bitset_test_fast(set,n) (((gsize*)set)[2+(n)/MONO_BITSET_BITS_PER_CHUNK] & ((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)))
17 #define mono_bitset_set_fast(set,n) do { ((gsize*)set)[2+(n)/MONO_BITSET_BITS_PER_CHUNK] |= ((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)); } while (0)
18 #define mono_bitset_clear_fast(set,n) do { ((gsize*)set)[2+(n)/MONO_BITSET_BITS_PER_CHUNK] &= ~((gsize)1 << ((n) % MONO_BITSET_BITS_PER_CHUNK)); } while (0)
19 #define mono_bitset_get_fast(set,n) (((gsize*)set)[2+(n)])
20
21 /*
22  * Interface documentation can be found in the c-file.
23  * Interface documentation by Dennis Haney.
24  */
25
26 guint32     mono_bitset_alloc_size   (guint32 max_size, guint32 flags);
27
28 MonoBitSet* mono_bitset_new          (guint32 max_size, guint32 flags);
29
30 MonoBitSet* mono_bitset_mem_new      (gpointer mem, guint32 max_size, guint32 flags);
31
32 void        mono_bitset_free         (MonoBitSet *set); 
33
34 void        mono_bitset_set          (MonoBitSet *set, guint32 pos);
35
36 void        mono_bitset_set_all      (MonoBitSet *set);
37
38 int         mono_bitset_test         (const MonoBitSet *set, guint32 pos);
39
40 gsize       mono_bitset_test_bulk    (const MonoBitSet *set, guint32 pos);
41
42 void        mono_bitset_clear        (MonoBitSet *set, guint32 pos);
43
44 void        mono_bitset_clear_all    (MonoBitSet *set);
45
46 void        mono_bitset_invert       (MonoBitSet *set);
47
48 guint32     mono_bitset_size         (const MonoBitSet *set);
49
50 guint32     mono_bitset_count        (const MonoBitSet *set);
51
52 void        mono_bitset_low_high     (const MonoBitSet *set, guint32 *low, guint32 *high);
53
54 int         mono_bitset_find_start   (const MonoBitSet *set);
55
56 int         mono_bitset_find_first   (const MonoBitSet *set, gint pos);
57
58 int         mono_bitset_find_last    (const MonoBitSet *set, gint pos);
59
60 int         mono_bitset_find_first_unset (const MonoBitSet *set, gint pos);
61
62 MonoBitSet* mono_bitset_clone        (const MonoBitSet *set, guint32 new_size);
63
64 void        mono_bitset_copyto       (const MonoBitSet *src, MonoBitSet *dest);
65
66 void        mono_bitset_union        (MonoBitSet *dest, const MonoBitSet *src);
67
68 void        mono_bitset_intersection (MonoBitSet *dest, const MonoBitSet *src);
69
70 void        mono_bitset_sub          (MonoBitSet *dest, const MonoBitSet *src);
71
72 gboolean    mono_bitset_equal        (const MonoBitSet *src, const MonoBitSet *src1);
73
74 void        mono_bitset_foreach      (MonoBitSet *set, MonoBitSetFunc func, gpointer data);
75
76 void        mono_bitset_intersection_2 (MonoBitSet *dest, const MonoBitSet *src1, const MonoBitSet *src2);
77
78 #endif /* __MONO_BITSET_H__ */