gtk4/auto/
bitset.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::ffi;
6use glib::translate::*;
7
8glib::wrapper! {
9    /// A [`Bitset`][crate::Bitset] represents a set of unsigned integers.
10    ///
11    /// Another name for this data structure is "bitmap".
12    ///
13    /// The current implementation is based on [roaring bitmaps](https://roaringbitmap.org/).
14    ///
15    /// A bitset allows adding a set of integers and provides support for set operations
16    /// like unions, intersections and checks for equality or if a value is contained
17    /// in the set. [`Bitset`][crate::Bitset] also contains various functions to query metadata about
18    /// the bitset, such as the minimum or maximum values or its size.
19    ///
20    /// The fastest way to iterate values in a bitset is [`BitsetIter`][crate::BitsetIter].
21    ///
22    /// The main use case for [`Bitset`][crate::Bitset] is implementing complex selections for
23    /// [`SelectionModel`][crate::SelectionModel].
24    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
25    pub struct Bitset(Shared<ffi::GtkBitset>);
26
27    match fn {
28        ref => |ptr| ffi::gtk_bitset_ref(ptr),
29        unref => |ptr| ffi::gtk_bitset_unref(ptr),
30        type_ => || ffi::gtk_bitset_get_type(),
31    }
32}
33
34impl Bitset {
35    /// Creates a new empty bitset.
36    ///
37    /// # Returns
38    ///
39    /// A new empty bitset
40    #[doc(alias = "gtk_bitset_new_empty")]
41    pub fn new_empty() -> Bitset {
42        assert_initialized_main_thread!();
43        unsafe { from_glib_full(ffi::gtk_bitset_new_empty()) }
44    }
45
46    /// Creates a bitset with the given range set.
47    /// ## `start`
48    /// first value to add
49    /// ## `n_items`
50    /// number of consecutive values to add
51    ///
52    /// # Returns
53    ///
54    /// A new bitset
55    #[doc(alias = "gtk_bitset_new_range")]
56    pub fn new_range(start: u32, n_items: u32) -> Bitset {
57        assert_initialized_main_thread!();
58        unsafe { from_glib_full(ffi::gtk_bitset_new_range(start, n_items)) }
59    }
60
61    /// Adds @value to @self if it wasn't part of it before.
62    /// ## `value`
63    /// value to add
64    ///
65    /// # Returns
66    ///
67    /// [`true`] if @value was not part of @self and @self
68    ///   was changed
69    #[doc(alias = "gtk_bitset_add")]
70    pub fn add(&self, value: u32) -> bool {
71        unsafe { from_glib(ffi::gtk_bitset_add(self.to_glib_none().0, value)) }
72    }
73
74    /// Adds all values from @start (inclusive) to @start + @n_items
75    /// (exclusive) in @self.
76    /// ## `start`
77    /// first value to add
78    /// ## `n_items`
79    /// number of consecutive values to add
80    #[doc(alias = "gtk_bitset_add_range")]
81    pub fn add_range(&self, start: u32, n_items: u32) {
82        unsafe {
83            ffi::gtk_bitset_add_range(self.to_glib_none().0, start, n_items);
84        }
85    }
86
87    /// Adds the closed range [@first, @last], so @first, @last and all
88    /// values in between. @first must be smaller than @last.
89    /// ## `first`
90    /// first value to add
91    /// ## `last`
92    /// last value to add
93    #[doc(alias = "gtk_bitset_add_range_closed")]
94    pub fn add_range_closed(&self, first: u32, last: u32) {
95        unsafe {
96            ffi::gtk_bitset_add_range_closed(self.to_glib_none().0, first, last);
97        }
98    }
99
100    /// Interprets the values as a 2-dimensional boolean grid with the given @stride
101    /// and inside that grid, adds a rectangle with the given @width and @height.
102    /// ## `start`
103    /// first value to add
104    /// ## `width`
105    /// width of the rectangle
106    /// ## `height`
107    /// height of the rectangle
108    /// ## `stride`
109    /// row stride of the grid
110    #[doc(alias = "gtk_bitset_add_rectangle")]
111    pub fn add_rectangle(&self, start: u32, width: u32, height: u32, stride: u32) {
112        unsafe {
113            ffi::gtk_bitset_add_rectangle(self.to_glib_none().0, start, width, height, stride);
114        }
115    }
116
117    /// Checks if the given @value has been added to @self
118    /// ## `value`
119    /// the value to check
120    ///
121    /// # Returns
122    ///
123    /// [`true`] if @self contains @value
124    #[doc(alias = "gtk_bitset_contains")]
125    pub fn contains(&self, value: u32) -> bool {
126        unsafe { from_glib(ffi::gtk_bitset_contains(self.to_glib_none().0, value)) }
127    }
128
129    #[doc(alias = "gtk_bitset_copy")]
130    #[must_use]
131    pub fn copy(&self) -> Bitset {
132        unsafe { from_glib_full(ffi::gtk_bitset_copy(self.to_glib_none().0)) }
133    }
134
135    /// Sets @self to be the symmetric difference of @self and @other.
136    ///
137    /// The symmetric difference is set @self to contain all values that
138    /// were either contained in @self or in @other, but not in both.
139    /// This operation is also called an XOR.
140    ///
141    /// It is allowed for @self and @other to be the same bitset. The bitset
142    /// will be emptied in that case.
143    /// ## `other`
144    /// the [`Bitset`][crate::Bitset] to compute the difference from
145    #[doc(alias = "gtk_bitset_difference")]
146    pub fn difference(&self, other: &Bitset) {
147        unsafe {
148            ffi::gtk_bitset_difference(self.to_glib_none().0, other.to_glib_none().0);
149        }
150    }
151
152    /// Returns [`true`] if @self and @other contain the same values.
153    /// ## `other`
154    /// another [`Bitset`][crate::Bitset]
155    ///
156    /// # Returns
157    ///
158    /// [`true`] if @self and @other contain the same values
159    #[doc(alias = "gtk_bitset_equals")]
160    pub fn equals(&self, other: &Bitset) -> bool {
161        unsafe {
162            from_glib(ffi::gtk_bitset_equals(
163                self.to_glib_none().0,
164                other.to_glib_none().0,
165            ))
166        }
167    }
168
169    /// Returns the largest value in @self.
170    ///
171    /// If @self is empty, 0 is returned.
172    ///
173    /// # Returns
174    ///
175    /// The largest value in @self
176    #[doc(alias = "gtk_bitset_get_maximum")]
177    #[doc(alias = "get_maximum")]
178    pub fn maximum(&self) -> u32 {
179        unsafe { ffi::gtk_bitset_get_maximum(self.to_glib_none().0) }
180    }
181
182    /// Returns the smallest value in @self.
183    ///
184    /// If @self is empty, `G_MAXUINT` is returned.
185    ///
186    /// # Returns
187    ///
188    /// The smallest value in @self
189    #[doc(alias = "gtk_bitset_get_minimum")]
190    #[doc(alias = "get_minimum")]
191    pub fn minimum(&self) -> u32 {
192        unsafe { ffi::gtk_bitset_get_minimum(self.to_glib_none().0) }
193    }
194
195    /// Returns the value of the @nth item in self.
196    ///
197    /// If @nth is >= the size of @self, 0 is returned.
198    /// ## `nth`
199    /// index of the item to get
200    ///
201    /// # Returns
202    ///
203    /// the value of the @nth item in @self
204    #[doc(alias = "gtk_bitset_get_nth")]
205    #[doc(alias = "get_nth")]
206    pub fn nth(&self, nth: u32) -> u32 {
207        unsafe { ffi::gtk_bitset_get_nth(self.to_glib_none().0, nth) }
208    }
209
210    /// Gets the number of values that were added to the set.
211    ///
212    /// For example, if the set is empty, 0 is returned.
213    ///
214    /// Note that this function returns a `guint64`, because when all
215    /// values are set, the return value is `G_MAXUINT + 1`. Unless you
216    /// are sure this cannot happen (it can't with `GListModel`), be sure
217    /// to use a 64bit type.
218    ///
219    /// # Returns
220    ///
221    /// The number of values in the set.
222    #[doc(alias = "gtk_bitset_get_size")]
223    #[doc(alias = "get_size")]
224    pub fn size(&self) -> u64 {
225        unsafe { ffi::gtk_bitset_get_size(self.to_glib_none().0) }
226    }
227
228    /// Gets the number of values that are part of the set from @first to @last
229    /// (inclusive).
230    ///
231    /// Note that this function returns a `guint64`, because when all values are
232    /// set, the return value is `G_MAXUINT + 1`. Unless you are sure this cannot
233    /// happen (it can't with `GListModel`), be sure to use a 64bit type.
234    /// ## `first`
235    /// the first element to include
236    /// ## `last`
237    /// the last element to include
238    ///
239    /// # Returns
240    ///
241    /// The number of values in the set from @first to @last.
242    #[doc(alias = "gtk_bitset_get_size_in_range")]
243    #[doc(alias = "get_size_in_range")]
244    pub fn size_in_range(&self, first: u32, last: u32) -> u64 {
245        unsafe { ffi::gtk_bitset_get_size_in_range(self.to_glib_none().0, first, last) }
246    }
247
248    /// Sets @self to be the intersection of @self and @other.
249    ///
250    /// In other words, remove all values from @self that are not part of @other.
251    ///
252    /// It is allowed for @self and @other to be the same bitset. Nothing will
253    /// happen in that case.
254    /// ## `other`
255    /// the [`Bitset`][crate::Bitset] to intersect with
256    #[doc(alias = "gtk_bitset_intersect")]
257    pub fn intersect(&self, other: &Bitset) {
258        unsafe {
259            ffi::gtk_bitset_intersect(self.to_glib_none().0, other.to_glib_none().0);
260        }
261    }
262
263    /// Check if no value is contained in bitset.
264    ///
265    /// # Returns
266    ///
267    /// [`true`] if @self is empty
268    #[doc(alias = "gtk_bitset_is_empty")]
269    pub fn is_empty(&self) -> bool {
270        unsafe { from_glib(ffi::gtk_bitset_is_empty(self.to_glib_none().0)) }
271    }
272
273    /// Removes @value from @self if it was part of it before.
274    /// ## `value`
275    /// value to remove
276    ///
277    /// # Returns
278    ///
279    /// [`true`] if @value was part of @self and @self
280    ///   was changed
281    #[doc(alias = "gtk_bitset_remove")]
282    pub fn remove(&self, value: u32) -> bool {
283        unsafe { from_glib(ffi::gtk_bitset_remove(self.to_glib_none().0, value)) }
284    }
285
286    /// Removes all values from the bitset so that it is empty again.
287    #[doc(alias = "gtk_bitset_remove_all")]
288    pub fn remove_all(&self) {
289        unsafe {
290            ffi::gtk_bitset_remove_all(self.to_glib_none().0);
291        }
292    }
293
294    /// Removes all values from @start (inclusive) to @start + @n_items (exclusive)
295    /// in @self.
296    /// ## `start`
297    /// first value to remove
298    /// ## `n_items`
299    /// number of consecutive values to remove
300    #[doc(alias = "gtk_bitset_remove_range")]
301    pub fn remove_range(&self, start: u32, n_items: u32) {
302        unsafe {
303            ffi::gtk_bitset_remove_range(self.to_glib_none().0, start, n_items);
304        }
305    }
306
307    /// Removes the closed range [@first, @last], so @first, @last and all
308    /// values in between. @first must be smaller than @last.
309    /// ## `first`
310    /// first value to remove
311    /// ## `last`
312    /// last value to remove
313    #[doc(alias = "gtk_bitset_remove_range_closed")]
314    pub fn remove_range_closed(&self, first: u32, last: u32) {
315        unsafe {
316            ffi::gtk_bitset_remove_range_closed(self.to_glib_none().0, first, last);
317        }
318    }
319
320    /// Interprets the values as a 2-dimensional boolean grid with the given @stride
321    /// and inside that grid, removes a rectangle with the given @width and @height.
322    /// ## `start`
323    /// first value to remove
324    /// ## `width`
325    /// width of the rectangle
326    /// ## `height`
327    /// height of the rectangle
328    /// ## `stride`
329    /// row stride of the grid
330    #[doc(alias = "gtk_bitset_remove_rectangle")]
331    pub fn remove_rectangle(&self, start: u32, width: u32, height: u32, stride: u32) {
332        unsafe {
333            ffi::gtk_bitset_remove_rectangle(self.to_glib_none().0, start, width, height, stride);
334        }
335    }
336
337    /// Shifts all values in @self to the left by @amount.
338    ///
339    /// Values smaller than @amount are discarded.
340    /// ## `amount`
341    /// amount to shift all values to the left
342    #[doc(alias = "gtk_bitset_shift_left")]
343    pub fn shift_left(&self, amount: u32) {
344        unsafe {
345            ffi::gtk_bitset_shift_left(self.to_glib_none().0, amount);
346        }
347    }
348
349    /// Shifts all values in @self to the right by @amount.
350    ///
351    /// Values that end up too large to be held in a #guint are discarded.
352    /// ## `amount`
353    /// amount to shift all values to the right
354    #[doc(alias = "gtk_bitset_shift_right")]
355    pub fn shift_right(&self, amount: u32) {
356        unsafe {
357            ffi::gtk_bitset_shift_right(self.to_glib_none().0, amount);
358        }
359    }
360
361    /// This is a support function for `GListModel` handling, by mirroring
362    /// the `GlistModel::items-changed` signal.
363    ///
364    /// First, it "cuts" the values from @position to @removed from
365    /// the bitset. That is, it removes all those values and shifts
366    /// all larger values to the left by @removed places.
367    ///
368    /// Then, it "pastes" new room into the bitset by shifting all values
369    /// larger than @position by @added spaces to the right. This frees
370    /// up space that can then be filled.
371    /// ## `position`
372    /// position at which to slice
373    /// ## `removed`
374    /// number of values to remove
375    /// ## `added`
376    /// number of values to add
377    #[doc(alias = "gtk_bitset_splice")]
378    pub fn splice(&self, position: u32, removed: u32, added: u32) {
379        unsafe {
380            ffi::gtk_bitset_splice(self.to_glib_none().0, position, removed, added);
381        }
382    }
383
384    /// Sets @self to be the subtraction of @other from @self.
385    ///
386    /// In other words, remove all values from @self that are part of @other.
387    ///
388    /// It is allowed for @self and @other to be the same bitset. The bitset
389    /// will be emptied in that case.
390    /// ## `other`
391    /// the [`Bitset`][crate::Bitset] to subtract
392    #[doc(alias = "gtk_bitset_subtract")]
393    pub fn subtract(&self, other: &Bitset) {
394        unsafe {
395            ffi::gtk_bitset_subtract(self.to_glib_none().0, other.to_glib_none().0);
396        }
397    }
398
399    /// Sets @self to be the union of @self and @other.
400    ///
401    /// That is, add all values from @other into @self that weren't part of it.
402    ///
403    /// It is allowed for @self and @other to be the same bitset. Nothing will
404    /// happen in that case.
405    /// ## `other`
406    /// the [`Bitset`][crate::Bitset] to union with
407    #[doc(alias = "gtk_bitset_union")]
408    pub fn union(&self, other: &Bitset) {
409        unsafe {
410            ffi::gtk_bitset_union(self.to_glib_none().0, other.to_glib_none().0);
411        }
412    }
413}