Debian Codegraph @

contrib/eggbitset/eggbitset.h

raw
1 /*
2 * Copyright © 2020 Benjamin Otte
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors: Benjamin Otte <[email protected]>
18 */
19
20
21 #pragma once
22
23 #include <glib-object.h>
24
25 G_BEGIN_DECLS
26
27 #define EGG_TYPE_BITSET (egg_bitset_get_type ())
28
29 typedef struct _EggBitset EggBitset;
30
31 GType egg_bitset_get_type (void) G_GNUC_CONST;
32 EggBitset * egg_bitset_ref (EggBitset *self);
33 void egg_bitset_unref (EggBitset *self);
34 G_DEFINE_AUTOPTR_CLEANUP_FUNC(EggBitset, egg_bitset_unref)
35
36 gboolean egg_bitset_contains (const EggBitset *self,
37 guint value);
38 gboolean egg_bitset_is_empty (const EggBitset *self);
39 gboolean egg_bitset_equals (const EggBitset *self,
40 const EggBitset *other);
41 guint64 egg_bitset_get_size (const EggBitset *self);
42 guint64 egg_bitset_get_size_in_range (const EggBitset *self,
43 guint first,
44 guint last);
45 guint egg_bitset_get_nth (const EggBitset *self,
46 guint nth);
47 guint egg_bitset_get_minimum (const EggBitset *self);
48 guint egg_bitset_get_maximum (const EggBitset *self);
49
50 EggBitset * egg_bitset_new_empty (void);
51 EggBitset * egg_bitset_copy (const EggBitset *self);
52 EggBitset * egg_bitset_new_range (guint start,
53 guint n_items);
54
55 void egg_bitset_remove_all (EggBitset *self);
56 gboolean egg_bitset_add (EggBitset *self,
57 guint value);
58 gboolean egg_bitset_remove (EggBitset *self,
59 guint value);
60 void egg_bitset_add_range (EggBitset *self,
61 guint start,
62 guint n_items);
63 void egg_bitset_remove_range (EggBitset *self,
64 guint start,
65 guint n_items);
66 void egg_bitset_add_range_closed (EggBitset *self,
67 guint first,
68 guint last);
69 void egg_bitset_remove_range_closed (EggBitset *self,
70 guint first,
71 guint last);
72 void egg_bitset_add_rectangle (EggBitset *self,
73 guint start,
74 guint width,
75 guint height,
76 guint stride);
77 void egg_bitset_remove_rectangle (EggBitset *self,
78 guint start,
79 guint width,
80 guint height,
81 guint stride);
82
83 void egg_bitset_union (EggBitset *self,
84 const EggBitset *other);
85 void egg_bitset_intersect (EggBitset *self,
86 const EggBitset *other);
87 void egg_bitset_subtract (EggBitset *self,
88 const EggBitset *other);
89 void egg_bitset_difference (EggBitset *self,
90 const EggBitset *other);
91 void egg_bitset_shift_left (EggBitset *self,
92 guint amount);
93 void egg_bitset_shift_right (EggBitset *self,
94 guint amount);
95 void egg_bitset_splice (EggBitset *self,
96 guint position,
97 guint removed,
98 guint added);
99
100 /**
101 * EggBitsetIter:
102 *
103 * An opaque, stack-allocated struct for iterating
104 * over the elements of a `EggBitset`.
105 *
106 * Before a `EggBitsetIter` can be used, it needs to be initialized with
107 * [[email protected]_first], [[email protected]_last]
108 * or [[email protected]_at].
109 */
110 typedef struct _EggBitsetIter EggBitsetIter;
111
112 struct _EggBitsetIter
113 {
114 /*< private >*/
115 gpointer private_data[10];
116 };
117
118 GType egg_bitset_iter_get_type (void) G_GNUC_CONST;
119 gboolean egg_bitset_iter_init_first (EggBitsetIter *iter,
120 const EggBitset *set,
121 guint *value);
122 gboolean egg_bitset_iter_init_last (EggBitsetIter *iter,
123 const EggBitset *set,
124 guint *value);
125 gboolean egg_bitset_iter_init_at (EggBitsetIter *iter,
126 const EggBitset *set,
127 guint target,
128 guint *value);
129 gboolean egg_bitset_iter_next (EggBitsetIter *iter,
130 guint *value);
131 gboolean egg_bitset_iter_previous (EggBitsetIter *iter,
132 guint *value);
133 guint egg_bitset_iter_get_value (const EggBitsetIter *iter);
134 gboolean egg_bitset_iter_is_valid (const EggBitsetIter *iter);
135
136 G_END_DECLS
137