Skip to main content

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 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    /// = the size of @self, 0 is returned.
196    /// ## `nth`
197    /// index of the item to get
198    ///
199    /// # Returns
200    ///
201    /// the value of the @nth item in @self
202    #[doc(alias = "gtk_bitset_get_nth")]
203    #[doc(alias = "get_nth")]
204    pub fn nth(&self, nth: u32) -> u32 {
205        unsafe { ffi::gtk_bitset_get_nth(self.to_glib_none().0, nth) }
206    }
207
208    /// Gets the number of values that were added to the set.
209    ///
210    /// For example, if the set is empty, 0 is returned.
211    ///
212    /// Note that this function returns a `guint64`, because when all
213    /// values are set, the return value is `G_MAXUINT + 1`. Unless you
214    /// are sure this cannot happen (it can't with `GListModel`), be sure
215    /// to use a 64bit type.
216    ///
217    /// # Returns
218    ///
219    /// The number of values in the set.
220    #[doc(alias = "gtk_bitset_get_size")]
221    #[doc(alias = "get_size")]
222    pub fn size(&self) -> u64 {
223        unsafe { ffi::gtk_bitset_get_size(self.to_glib_none().0) }
224    }
225
226    /// Gets the number of values that are part of the set from @first to @last
227    /// (inclusive).
228    ///
229    /// Note that this function returns a `guint64`, because when all values are
230    /// set, the return value is `G_MAXUINT + 1`. Unless you are sure this cannot
231    /// happen (it can't with `GListModel`), be sure to use a 64bit type.
232    /// ## `first`
233    /// the first element to include
234    /// ## `last`
235    /// the last element to include
236    ///
237    /// # Returns
238    ///
239    /// The number of values in the set from @first to @last.
240    #[doc(alias = "gtk_bitset_get_size_in_range")]
241    #[doc(alias = "get_size_in_range")]
242    pub fn size_in_range(&self, first: u32, last: u32) -> u64 {
243        unsafe { ffi::gtk_bitset_get_size_in_range(self.to_glib_none().0, first, last) }
244    }
245
246    /// Sets @self to be the intersection of @self and @other.
247    ///
248    /// In other words, remove all values from @self that are not part of @other.
249    ///
250    /// It is allowed for @self and @other to be the same bitset. Nothing will
251    /// happen in that case.
252    /// ## `other`
253    /// the [`Bitset`][crate::Bitset] to intersect with
254    #[doc(alias = "gtk_bitset_intersect")]
255    pub fn intersect(&self, other: &Bitset) {
256        unsafe {
257            ffi::gtk_bitset_intersect(self.to_glib_none().0, other.to_glib_none().0);
258        }
259    }
260
261    /// Check if no value is contained in bitset.
262    ///
263    /// # Returns
264    ///
265    /// [`true`] if @self is empty
266    #[doc(alias = "gtk_bitset_is_empty")]
267    pub fn is_empty(&self) -> bool {
268        unsafe { from_glib(ffi::gtk_bitset_is_empty(self.to_glib_none().0)) }
269    }
270
271    /// Removes @value from @self if it was part of it before.
272    /// ## `value`
273    /// value to remove
274    ///
275    /// # Returns
276    ///
277    /// [`true`] if @value was part of @self and @self
278    ///   was changed
279    #[doc(alias = "gtk_bitset_remove")]
280    pub fn remove(&self, value: u32) -> bool {
281        unsafe { from_glib(ffi::gtk_bitset_remove(self.to_glib_none().0, value)) }
282    }
283
284    /// Removes all values from the bitset so that it is empty again.
285    #[doc(alias = "gtk_bitset_remove_all")]
286    pub fn remove_all(&self) {
287        unsafe {
288            ffi::gtk_bitset_remove_all(self.to_glib_none().0);
289        }
290    }
291
292    /// Removes all values from @start (inclusive) to @start + @n_items (exclusive)
293    /// in @self.
294    /// ## `start`
295    /// first value to remove
296    /// ## `n_items`
297    /// number of consecutive values to remove
298    #[doc(alias = "gtk_bitset_remove_range")]
299    pub fn remove_range(&self, start: u32, n_items: u32) {
300        unsafe {
301            ffi::gtk_bitset_remove_range(self.to_glib_none().0, start, n_items);
302        }
303    }
304
305    /// Removes the closed range [@first, @last], so @first, @last and all
306    /// values in between. @first must be smaller than @last.
307    /// ## `first`
308    /// first value to remove
309    /// ## `last`
310    /// last value to remove
311    #[doc(alias = "gtk_bitset_remove_range_closed")]
312    pub fn remove_range_closed(&self, first: u32, last: u32) {
313        unsafe {
314            ffi::gtk_bitset_remove_range_closed(self.to_glib_none().0, first, last);
315        }
316    }
317
318    /// Interprets the values as a 2-dimensional boolean grid with the given @stride
319    /// and inside that grid, removes a rectangle with the given @width and @height.
320    /// ## `start`
321    /// first value to remove
322    /// ## `width`
323    /// width of the rectangle
324    /// ## `height`
325    /// height of the rectangle
326    /// ## `stride`
327    /// row stride of the grid
328    #[doc(alias = "gtk_bitset_remove_rectangle")]
329    pub fn remove_rectangle(&self, start: u32, width: u32, height: u32, stride: u32) {
330        unsafe {
331            ffi::gtk_bitset_remove_rectangle(self.to_glib_none().0, start, width, height, stride);
332        }
333    }
334
335    /// Shifts all values in @self to the left by @amount.
336    ///
337    /// Values smaller than @amount are discarded.
338    /// ## `amount`
339    /// amount to shift all values to the left
340    #[doc(alias = "gtk_bitset_shift_left")]
341    pub fn shift_left(&self, amount: u32) {
342        unsafe {
343            ffi::gtk_bitset_shift_left(self.to_glib_none().0, amount);
344        }
345    }
346
347    /// Shifts all values in @self to the right by @amount.
348    ///
349    /// Values that end up too large to be held in a #guint are discarded.
350    /// ## `amount`
351    /// amount to shift all values to the right
352    #[doc(alias = "gtk_bitset_shift_right")]
353    pub fn shift_right(&self, amount: u32) {
354        unsafe {
355            ffi::gtk_bitset_shift_right(self.to_glib_none().0, amount);
356        }
357    }
358
359    /// This is a support function for `GListModel` handling, by mirroring
360    /// the `GlistModel::items-changed` signal.
361    ///
362    /// First, it "cuts" the values from @position to @removed from
363    /// the bitset. That is, it removes all those values and shifts
364    /// all larger values to the left by @removed places.
365    ///
366    /// Then, it "pastes" new room into the bitset by shifting all values
367    /// larger than @position by @added spaces to the right. This frees
368    /// up space that can then be filled.
369    /// ## `position`
370    /// position at which to slice
371    /// ## `removed`
372    /// number of values to remove
373    /// ## `added`
374    /// number of values to add
375    #[doc(alias = "gtk_bitset_splice")]
376    pub fn splice(&self, position: u32, removed: u32, added: u32) {
377        unsafe {
378            ffi::gtk_bitset_splice(self.to_glib_none().0, position, removed, added);
379        }
380    }
381
382    /// Sets @self to be the subtraction of @other from @self.
383    ///
384    /// In other words, remove all values from @self that are part of @other.
385    ///
386    /// It is allowed for @self and @other to be the same bitset. The bitset
387    /// will be emptied in that case.
388    /// ## `other`
389    /// the [`Bitset`][crate::Bitset] to subtract
390    #[doc(alias = "gtk_bitset_subtract")]
391    pub fn subtract(&self, other: &Bitset) {
392        unsafe {
393            ffi::gtk_bitset_subtract(self.to_glib_none().0, other.to_glib_none().0);
394        }
395    }
396
397    /// Sets @self to be the union of @self and @other.
398    ///
399    /// That is, add all values from @other into @self that weren't part of it.
400    ///
401    /// It is allowed for @self and @other to be the same bitset. Nothing will
402    /// happen in that case.
403    /// ## `other`
404    /// the [`Bitset`][crate::Bitset] to union with
405    #[doc(alias = "gtk_bitset_union")]
406    pub fn union(&self, other: &Bitset) {
407        unsafe {
408            ffi::gtk_bitset_union(self.to_glib_none().0, other.to_glib_none().0);
409        }
410    }
411}