1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use glib::translate::*;

glib::wrapper! {
    /// A [`Bitset`][crate::Bitset] represents a set of unsigned integers.
    ///
    /// Another name for this data structure is "bitmap".
    ///
    /// The current implementation is based on [roaring bitmaps](https://roaringbitmap.org/).
    ///
    /// A bitset allows adding a set of integers and provides support for set operations
    /// like unions, intersections and checks for equality or if a value is contained
    /// in the set. [`Bitset`][crate::Bitset] also contains various functions to query metadata about
    /// the bitset, such as the minimum or maximum values or its size.
    ///
    /// The fastest way to iterate values in a bitset is [`BitsetIter`][crate::BitsetIter].
    ///
    /// The main use case for [`Bitset`][crate::Bitset] is implementing complex selections for
    /// [`SelectionModel`][crate::SelectionModel].
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct Bitset(Shared<ffi::GtkBitset>);

    match fn {
        ref => |ptr| ffi::gtk_bitset_ref(ptr),
        unref => |ptr| ffi::gtk_bitset_unref(ptr),
        type_ => || ffi::gtk_bitset_get_type(),
    }
}

impl Bitset {
    /// Creates a new empty bitset.
    ///
    /// # Returns
    ///
    /// A new empty bitset
    #[doc(alias = "gtk_bitset_new_empty")]
    pub fn new_empty() -> Bitset {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gtk_bitset_new_empty()) }
    }

    /// Creates a bitset with the given range set.
    /// ## `start`
    /// first value to add
    /// ## `n_items`
    /// number of consecutive values to add
    ///
    /// # Returns
    ///
    /// A new bitset
    #[doc(alias = "gtk_bitset_new_range")]
    pub fn new_range(start: u32, n_items: u32) -> Bitset {
        assert_initialized_main_thread!();
        unsafe { from_glib_full(ffi::gtk_bitset_new_range(start, n_items)) }
    }

    /// Adds @value to @self if it wasn't part of it before.
    /// ## `value`
    /// value to add
    ///
    /// # Returns
    ///
    /// [`true`] if @value was not part of @self and @self
    ///   was changed
    #[doc(alias = "gtk_bitset_add")]
    pub fn add(&self, value: u32) -> bool {
        unsafe { from_glib(ffi::gtk_bitset_add(self.to_glib_none().0, value)) }
    }

    /// Adds all values from @start (inclusive) to @start + @n_items
    /// (exclusive) in @self.
    /// ## `start`
    /// first value to add
    /// ## `n_items`
    /// number of consecutive values to add
    #[doc(alias = "gtk_bitset_add_range")]
    pub fn add_range(&self, start: u32, n_items: u32) {
        unsafe {
            ffi::gtk_bitset_add_range(self.to_glib_none().0, start, n_items);
        }
    }

    /// Adds the closed range [@first, @last], so @first, @last and all
    /// values in between. @first must be smaller than @last.
    /// ## `first`
    /// first value to add
    /// ## `last`
    /// last value to add
    #[doc(alias = "gtk_bitset_add_range_closed")]
    pub fn add_range_closed(&self, first: u32, last: u32) {
        unsafe {
            ffi::gtk_bitset_add_range_closed(self.to_glib_none().0, first, last);
        }
    }

    /// Interprets the values as a 2-dimensional boolean grid with the given @stride
    /// and inside that grid, adds a rectangle with the given @width and @height.
    /// ## `start`
    /// first value to add
    /// ## `width`
    /// width of the rectangle
    /// ## `height`
    /// height of the rectangle
    /// ## `stride`
    /// row stride of the grid
    #[doc(alias = "gtk_bitset_add_rectangle")]
    pub fn add_rectangle(&self, start: u32, width: u32, height: u32, stride: u32) {
        unsafe {
            ffi::gtk_bitset_add_rectangle(self.to_glib_none().0, start, width, height, stride);
        }
    }

    /// Checks if the given @value has been added to @self
    /// ## `value`
    /// the value to check
    ///
    /// # Returns
    ///
    /// [`true`] if @self contains @value
    #[doc(alias = "gtk_bitset_contains")]
    pub fn contains(&self, value: u32) -> bool {
        unsafe { from_glib(ffi::gtk_bitset_contains(self.to_glib_none().0, value)) }
    }

    #[doc(alias = "gtk_bitset_copy")]
    #[must_use]
    pub fn copy(&self) -> Bitset {
        unsafe { from_glib_full(ffi::gtk_bitset_copy(self.to_glib_none().0)) }
    }

    /// Sets @self to be the symmetric difference of @self and @other.
    ///
    /// The symmetric difference is set @self to contain all values that
    /// were either contained in @self or in @other, but not in both.
    /// This operation is also called an XOR.
    ///
    /// It is allowed for @self and @other to be the same bitset. The bitset
    /// will be emptied in that case.
    /// ## `other`
    /// the [`Bitset`][crate::Bitset] to compute the difference from
    #[doc(alias = "gtk_bitset_difference")]
    pub fn difference(&self, other: &Bitset) {
        unsafe {
            ffi::gtk_bitset_difference(self.to_glib_none().0, other.to_glib_none().0);
        }
    }

    /// Returns [`true`] if @self and @other contain the same values.
    /// ## `other`
    /// another [`Bitset`][crate::Bitset]
    ///
    /// # Returns
    ///
    /// [`true`] if @self and @other contain the same values
    #[doc(alias = "gtk_bitset_equals")]
    pub fn equals(&self, other: &Bitset) -> bool {
        unsafe {
            from_glib(ffi::gtk_bitset_equals(
                self.to_glib_none().0,
                other.to_glib_none().0,
            ))
        }
    }

    /// Returns the largest value in @self.
    ///
    /// If @self is empty, 0 is returned.
    ///
    /// # Returns
    ///
    /// The largest value in @self
    #[doc(alias = "gtk_bitset_get_maximum")]
    #[doc(alias = "get_maximum")]
    pub fn maximum(&self) -> u32 {
        unsafe { ffi::gtk_bitset_get_maximum(self.to_glib_none().0) }
    }

    /// Returns the smallest value in @self.
    ///
    /// If @self is empty, `G_MAXUINT` is returned.
    ///
    /// # Returns
    ///
    /// The smallest value in @self
    #[doc(alias = "gtk_bitset_get_minimum")]
    #[doc(alias = "get_minimum")]
    pub fn minimum(&self) -> u32 {
        unsafe { ffi::gtk_bitset_get_minimum(self.to_glib_none().0) }
    }

    /// Returns the value of the @nth item in self.
    ///
    /// If @nth is >= the size of @self, 0 is returned.
    /// ## `nth`
    /// index of the item to get
    ///
    /// # Returns
    ///
    /// the value of the @nth item in @self
    #[doc(alias = "gtk_bitset_get_nth")]
    #[doc(alias = "get_nth")]
    pub fn nth(&self, nth: u32) -> u32 {
        unsafe { ffi::gtk_bitset_get_nth(self.to_glib_none().0, nth) }
    }

    /// Gets the number of values that were added to the set.
    ///
    /// For example, if the set is empty, 0 is returned.
    ///
    /// Note that this function returns a `guint64`, because when all
    /// values are set, the return value is `G_MAXUINT + 1`. Unless you
    /// are sure this cannot happen (it can't with `GListModel`), be sure
    /// to use a 64bit type.
    ///
    /// # Returns
    ///
    /// The number of values in the set.
    #[doc(alias = "gtk_bitset_get_size")]
    #[doc(alias = "get_size")]
    pub fn size(&self) -> u64 {
        unsafe { ffi::gtk_bitset_get_size(self.to_glib_none().0) }
    }

    /// Gets the number of values that are part of the set from @first to @last
    /// (inclusive).
    ///
    /// Note that this function returns a `guint64`, because when all values are
    /// set, the return value is `G_MAXUINT + 1`. Unless you are sure this cannot
    /// happen (it can't with `GListModel`), be sure to use a 64bit type.
    /// ## `first`
    /// the first element to include
    /// ## `last`
    /// the last element to include
    ///
    /// # Returns
    ///
    /// The number of values in the set from @first to @last.
    #[doc(alias = "gtk_bitset_get_size_in_range")]
    #[doc(alias = "get_size_in_range")]
    pub fn size_in_range(&self, first: u32, last: u32) -> u64 {
        unsafe { ffi::gtk_bitset_get_size_in_range(self.to_glib_none().0, first, last) }
    }

    /// Sets @self to be the intersection of @self and @other.
    ///
    /// In other words, remove all values from @self that are not part of @other.
    ///
    /// It is allowed for @self and @other to be the same bitset. Nothing will
    /// happen in that case.
    /// ## `other`
    /// the [`Bitset`][crate::Bitset] to intersect with
    #[doc(alias = "gtk_bitset_intersect")]
    pub fn intersect(&self, other: &Bitset) {
        unsafe {
            ffi::gtk_bitset_intersect(self.to_glib_none().0, other.to_glib_none().0);
        }
    }

    /// Check if no value is contained in bitset.
    ///
    /// # Returns
    ///
    /// [`true`] if @self is empty
    #[doc(alias = "gtk_bitset_is_empty")]
    pub fn is_empty(&self) -> bool {
        unsafe { from_glib(ffi::gtk_bitset_is_empty(self.to_glib_none().0)) }
    }

    /// Removes @value from @self if it was part of it before.
    /// ## `value`
    /// value to add
    ///
    /// # Returns
    ///
    /// [`true`] if @value was part of @self and @self
    ///   was changed
    #[doc(alias = "gtk_bitset_remove")]
    pub fn remove(&self, value: u32) -> bool {
        unsafe { from_glib(ffi::gtk_bitset_remove(self.to_glib_none().0, value)) }
    }

    /// Removes all values from the bitset so that it is empty again.
    #[doc(alias = "gtk_bitset_remove_all")]
    pub fn remove_all(&self) {
        unsafe {
            ffi::gtk_bitset_remove_all(self.to_glib_none().0);
        }
    }

    /// Removes all values from @start (inclusive) to @start + @n_items (exclusive)
    /// in @self.
    /// ## `start`
    /// first value to remove
    /// ## `n_items`
    /// number of consecutive values to remove
    #[doc(alias = "gtk_bitset_remove_range")]
    pub fn remove_range(&self, start: u32, n_items: u32) {
        unsafe {
            ffi::gtk_bitset_remove_range(self.to_glib_none().0, start, n_items);
        }
    }

    /// Removes the closed range [@first, @last], so @first, @last and all
    /// values in between. @first must be smaller than @last.
    /// ## `first`
    /// first value to remove
    /// ## `last`
    /// last value to remove
    #[doc(alias = "gtk_bitset_remove_range_closed")]
    pub fn remove_range_closed(&self, first: u32, last: u32) {
        unsafe {
            ffi::gtk_bitset_remove_range_closed(self.to_glib_none().0, first, last);
        }
    }

    /// Interprets the values as a 2-dimensional boolean grid with the given @stride
    /// and inside that grid, removes a rectangle with the given @width and @height.
    /// ## `start`
    /// first value to remove
    /// ## `width`
    /// width of the rectangle
    /// ## `height`
    /// height of the rectangle
    /// ## `stride`
    /// row stride of the grid
    #[doc(alias = "gtk_bitset_remove_rectangle")]
    pub fn remove_rectangle(&self, start: u32, width: u32, height: u32, stride: u32) {
        unsafe {
            ffi::gtk_bitset_remove_rectangle(self.to_glib_none().0, start, width, height, stride);
        }
    }

    /// Shifts all values in @self to the left by @amount.
    ///
    /// Values smaller than @amount are discarded.
    /// ## `amount`
    /// amount to shift all values to the left
    #[doc(alias = "gtk_bitset_shift_left")]
    pub fn shift_left(&self, amount: u32) {
        unsafe {
            ffi::gtk_bitset_shift_left(self.to_glib_none().0, amount);
        }
    }

    /// Shifts all values in @self to the right by @amount.
    ///
    /// Values that end up too large to be held in a #guint are discarded.
    /// ## `amount`
    /// amount to shift all values to the right
    #[doc(alias = "gtk_bitset_shift_right")]
    pub fn shift_right(&self, amount: u32) {
        unsafe {
            ffi::gtk_bitset_shift_right(self.to_glib_none().0, amount);
        }
    }

    /// This is a support function for `GListModel` handling, by mirroring
    /// the `GlistModel::items-changed` signal.
    ///
    /// First, it "cuts" the values from @position to @removed from
    /// the bitset. That is, it removes all those values and shifts
    /// all larger values to the left by @removed places.
    ///
    /// Then, it "pastes" new room into the bitset by shifting all values
    /// larger than @position by @added spaces to the right. This frees
    /// up space that can then be filled.
    /// ## `position`
    /// position at which to slice
    /// ## `removed`
    /// number of values to remove
    /// ## `added`
    /// number of values to add
    #[doc(alias = "gtk_bitset_splice")]
    pub fn splice(&self, position: u32, removed: u32, added: u32) {
        unsafe {
            ffi::gtk_bitset_splice(self.to_glib_none().0, position, removed, added);
        }
    }

    /// Sets @self to be the subtraction of @other from @self.
    ///
    /// In other words, remove all values from @self that are part of @other.
    ///
    /// It is allowed for @self and @other to be the same bitset. The bitset
    /// will be emptied in that case.
    /// ## `other`
    /// the [`Bitset`][crate::Bitset] to subtract
    #[doc(alias = "gtk_bitset_subtract")]
    pub fn subtract(&self, other: &Bitset) {
        unsafe {
            ffi::gtk_bitset_subtract(self.to_glib_none().0, other.to_glib_none().0);
        }
    }

    /// Sets @self to be the union of @self and @other.
    ///
    /// That is, add all values from @other into @self that weren't part of it.
    ///
    /// It is allowed for @self and @other to be the same bitset. Nothing will
    /// happen in that case.
    /// ## `other`
    /// the [`Bitset`][crate::Bitset] to union with
    #[doc(alias = "gtk_bitset_union")]
    pub fn union(&self, other: &Bitset) {
        unsafe {
            ffi::gtk_bitset_union(self.to_glib_none().0, other.to_glib_none().0);
        }
    }
}