Top |
Functions
Description
GtkBitset is a data structure for representing a set of unsigned integers. Another name for this data structure is "bitmap".
The current implementation is based on roaring bitmaps.
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. GtkBitset 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 GtkBitsetIter.
The main use case for GtkBitset is implementing complex selections for GtkSelectionModel.
Functions
gtk_bitset_ref ()
GtkBitset *
gtk_bitset_ref (GtkBitset *self
);
Acquires a reference on the given GtkBitset.
gtk_bitset_unref ()
void
gtk_bitset_unref (GtkBitset *self
);
Releases a reference on the given GtkBitset.
If the reference was the last, the resources associated to the self
are
freed.
gtk_bitset_new_range ()
GtkBitset * gtk_bitset_new_range (guint start
,guint n_items
);
Creates a bitset with the given range set.
gtk_bitset_contains ()
gboolean gtk_bitset_contains (const GtkBitset *self
,guint value
);
Checks if the given value
has been added to self
gtk_bitset_is_empty ()
gboolean
gtk_bitset_is_empty (const GtkBitset *self
);
Check if no value is contained in bitset.
gtk_bitset_equals ()
gboolean gtk_bitset_equals (const GtkBitset *self
,const GtkBitset *other
);
Returns TRUE
if self
and other
contain the same values.
gtk_bitset_get_minimum ()
guint
gtk_bitset_get_minimum (const GtkBitset *self
);
Returns the smallest value in self
. If self
is empty,
G_MAXUINT is returned.
gtk_bitset_get_maximum ()
guint
gtk_bitset_get_maximum (const GtkBitset *self
);
Returns the largest value in self
. If self
is empty,
0 is returned.
gtk_bitset_get_size ()
guint64
gtk_bitset_get_size (const GtkBitset *self
);
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.
gtk_bitset_get_size_in_range ()
guint64 gtk_bitset_get_size_in_range (const GtkBitset *self
,guint first
,guint last
);
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.
gtk_bitset_get_nth ()
guint gtk_bitset_get_nth (const GtkBitset *self
,guint nth
);
Returns the value of the nth
item in self.
If nth
is >= the size of self
, 0 is returned.
gtk_bitset_remove_all ()
void
gtk_bitset_remove_all (GtkBitset *self
);
Removes all values from the bitset so that it is empty again.
gtk_bitset_add ()
gboolean gtk_bitset_add (GtkBitset *self
,guint value
);
Adds value
to self
if it wasn't part of it before.
gtk_bitset_remove ()
gboolean gtk_bitset_remove (GtkBitset *self
,guint value
);
Removes value
from self
if it was part of it before.
gtk_bitset_add_range ()
void gtk_bitset_add_range (GtkBitset *self
,guint start
,guint n_items
);
Adds all values from start
(inclusive) to start
+ n_items
(exclusive) in self
.
gtk_bitset_remove_range ()
void gtk_bitset_remove_range (GtkBitset *self
,guint start
,guint n_items
);
Removes all values from start
(inclusive) to start
+ n_items
(exclusive)
in self
.
gtk_bitset_add_range_closed ()
void gtk_bitset_add_range_closed (GtkBitset *self
,guint first
,guint last
);
Adds the closed range [first
, last
], so first
, last
and all
values in between. first
must be smaller than last
.
gtk_bitset_remove_range_closed ()
void gtk_bitset_remove_range_closed (GtkBitset *self
,guint first
,guint last
);
Removes the closed range [first
, last
], so first
, last
and all
values in between. first
must be smaller than last
.
gtk_bitset_add_rectangle ()
void gtk_bitset_add_rectangle (GtkBitset *self
,guint start
,guint width
,guint height
,guint stride
);
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
.
gtk_bitset_remove_rectangle ()
void gtk_bitset_remove_rectangle (GtkBitset *self
,guint start
,guint width
,guint height
,guint stride
);
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
.
gtk_bitset_union ()
void gtk_bitset_union (GtkBitset *self
,const GtkBitset *other
);
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.
gtk_bitset_intersect ()
void gtk_bitset_intersect (GtkBitset *self
,const GtkBitset *other
);
Sets self
to be the intersection of self
and other
, that is 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.
gtk_bitset_subtract ()
void gtk_bitset_subtract (GtkBitset *self
,const GtkBitset *other
);
Sets self
to be the subtraction of other
from self
, that is 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.
gtk_bitset_difference ()
void gtk_bitset_difference (GtkBitset *self
,const GtkBitset *other
);
Sets self
to be the symmetric difference of self
and other
, that
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.
gtk_bitset_shift_left ()
void gtk_bitset_shift_left (GtkBitset *self
,guint amount
);
Shifts all values in self
to the left by amount
. Values
smaller than amount
are discarded.
gtk_bitset_shift_right ()
void gtk_bitset_shift_right (GtkBitset *self
,guint 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.
gtk_bitset_splice ()
void gtk_bitset_splice (GtkBitset *self
,guint position
,guint removed
,guint added
);
This is a support function for GListModel handling, by mirroring the “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.
gtk_bitset_iter_init_first ()
gboolean gtk_bitset_iter_init_first (GtkBitsetIter *iter
,const GtkBitset *set
,guint *value
);
Initializes an iterator for set
and points it to the first
value in set
. If set
is empty, FALSE
is returned and value
is set to G_MAXUINT
.
Parameters
iter |
a pointer to an uninitialized GtkBitsetIter. |
[out] |
set |
||
value |
Set to the first value in |
[out][optional] |
gtk_bitset_iter_init_last ()
gboolean gtk_bitset_iter_init_last (GtkBitsetIter *iter
,const GtkBitset *set
,guint *value
);
Initializes an iterator for set
and points it to the last
value in set
. If set
is empty, FALSE
is returned.
Parameters
iter |
a pointer to an uninitialized GtkBitsetIter. |
[out] |
set |
||
value |
Set to the last value in |
[out][optional] |
gtk_bitset_iter_init_at ()
gboolean gtk_bitset_iter_init_at (GtkBitsetIter *iter
,const GtkBitset *set
,guint target
,guint *value
);
Initializes iter
to point to target
. If target
is not found, finds
the next value after it. If no value >= target
exists in set
, this
function returns FALSE
.
Parameters
iter |
a pointer to an uninitialized GtkBitsetIter. |
[out] |
set |
||
target |
target value to start iterating at |
|
value |
Set to the found value in |
[out][optional] |
gtk_bitset_iter_next ()
gboolean gtk_bitset_iter_next (GtkBitsetIter *iter
,guint *value
);
Moves iter
to the next value in the set. If it was already
pointing to the last value in the set, FALSE
is returned and
iter
is invalidated.
gtk_bitset_iter_previous ()
gboolean gtk_bitset_iter_previous (GtkBitsetIter *iter
,guint *value
);
Moves iter
to the previous value in the set. If it was already
pointing to the first value in the set, FALSE
is returned and
iter
is invalidated.
gtk_bitset_iter_get_value ()
guint
gtk_bitset_iter_get_value (const GtkBitsetIter *iter
);
Gets the current value that iter
points to.
If iter
is not valid and gtk_bitset_iter_is_valid()
returns
FALSE
, this function returns 0.
gtk_bitset_iter_is_valid ()
gboolean
gtk_bitset_iter_is_valid (const GtkBitsetIter *iter
);
Checks if iter
points to a valid value.
Types and Values
struct GtkBitsetIter
struct GtkBitsetIter { };
An opaque, stack-allocated struct for iterating
over the elements of a GtkBitset. Before a GtkBitsetIter
can be used, it needs to be initialized with
gtk_bitset_iter_init_first()
, gtk_bitset_iter_init_last()
or gtk_bitset_iter_init_at()
.