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