3.2 <GtkBitset>

Structure: <GtkBitset>

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>.

Procedures

Method: bitset:add-range self start n-items
Method: add-range self start n-items

Adds all values from start (inclusive) to start + n-items (exclusive) in self.

self

Passed: a <GtkBitset>.

a <GtkBitset>

start

Passed: an unsigned 32-bit integer.

first value to add

n-items

Passed: an unsigned 32-bit integer.

number of consecutive values to add

Method: bitset:add-range-closed self first last
Method: add-range-closed self first last

Adds the closed range [first, last], so first, last and all values in between. first must be smaller than last.

self

Passed: a <GtkBitset>.

a <GtkBitset>

first

Passed: an unsigned 32-bit integer.

first value to add

last

Passed: an unsigned 32-bit integer.

last value to add

Method: bitset:add-rectangle self start width height stride
Method: add-rectangle self start width height 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.

self

Passed: a <GtkBitset>.

a <GtkBitset>

start

Passed: an unsigned 32-bit integer.

first value to add

width

Passed: an unsigned 32-bit integer.

width of the rectangle

height

Passed: an unsigned 32-bit integer.

height of the rectangle

stride

Passed: an unsigned 32-bit integer.

row stride of the grid

Method: bitset:add? self value ⇒ %return
Method: add? self value ⇒ %return

Adds value to self if it wasn’t part of it before.

self

Passed: a <GtkBitset>.

a <GtkBitset>

value

Passed: an unsigned 32-bit integer.

value to add

%return

Returned: a boolean.

#t if value was not part of self and self was changed

Method: bitset:contains? self value ⇒ %return
Method: contains? self value ⇒ %return

Checks if the given value has been added to self

self

Passed: a <GtkBitset>.

a <GtkBitset>

value

Passed: an unsigned 32-bit integer.

the value to check

%return

Returned: a boolean.

#t if self contains value

Method: bitset:copy self ⇒ %return
Method: copy self ⇒ %return

Creates a copy of self.

self

Passed: a <GtkBitset>.

a <GtkBitset>

%return

Returned: a <GtkBitset>.

A new bitset that contains the same values as self

Method: bitset:difference self other
Method: difference self other

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.

self

Passed: a <GtkBitset>.

a <GtkBitset>

other

Passed: a <GtkBitset>.

the <GtkBitset> to compute the difference from

Method: bitset:equals? self other ⇒ %return
Method: equals? self other ⇒ %return

Returns #t if self and other contain the same values.

self

Passed: a <GtkBitset>.

a <GtkBitset>

other

Passed: a <GtkBitset>.

another <GtkBitset>

%return

Returned: a boolean.

#t if self and other contain the same values

Method: bitset:get-maximum self ⇒ %return
Method: get-maximum self ⇒ %return

Returns the largest value in self.

If self is empty, 0 is returned.

self

Passed: a <GtkBitset>.

a <GtkBitset>

%return

Returned: an unsigned 32-bit integer.

The largest value in self

Method: bitset:get-minimum self ⇒ %return
Method: get-minimum self ⇒ %return

Returns the smallest value in self.

If self is empty, G_MAXUINT is returned.

self

Passed: a <GtkBitset>.

a <GtkBitset>

%return

Returned: an unsigned 32-bit integer.

The smallest value in self

Method: bitset:get-nth self nth ⇒ %return
Method: get-nth self nth ⇒ %return

Returns the value of the nth item in self.

If nth is >= the size of self, 0 is returned.

self

Passed: a <GtkBitset>.

a <GtkBitset>

nth

Passed: an unsigned 32-bit integer.

index of the item to get

%return

Returned: an unsigned 32-bit integer.

the value of the nth item in self

Method: bitset:get-size self ⇒ %return
Method: get-size self ⇒ %return

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.

self

Passed: a <GtkBitset>.

a <GtkBitset>

%return

Returned: an unsigned 64-bit integer.

The number of values in the set.

Method: bitset:get-size-in-range self first last ⇒ %return
Method: get-size-in-range self first last ⇒ %return

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.

self

Passed: a <GtkBitset>.

a <GtkBitset>

first

Passed: an unsigned 32-bit integer.

the first element to include

last

Passed: an unsigned 32-bit integer.

the last element to include

%return

Returned: an unsigned 64-bit integer.

The number of values in the set from first to last.

Method: bitset:intersect self other
Method: intersect self other

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.

self

Passed: a <GtkBitset>.

a <GtkBitset>

other

Passed: a <GtkBitset>.

the <GtkBitset> to intersect with

Method: bitset:is-empty? self ⇒ %return
Method: is-empty? self ⇒ %return

Check if no value is contained in bitset.

self

Passed: a <GtkBitset>.

a <GtkBitset>

%return

Returned: a boolean.

#t if self is empty

Procedure: bitset:new-empty ⇒ %return

Creates a new empty bitset.

%return

Returned: a <GtkBitset>.

A new empty bitset

Procedure: bitset:new-range start n-items ⇒ %return

Creates a bitset with the given range set.

start

Passed: an unsigned 32-bit integer.

first value to add

n-items

Passed: an unsigned 32-bit integer.

number of consecutive values to add

%return

Returned: a <GtkBitset>.

A new bitset

Method: bitset:ref self ⇒ %return
Method: ref self ⇒ %return

Acquires a reference on the given <GtkBitset>.

self

Passed: a <GtkBitset>.

a <GtkBitset>

%return

Returned: a <GtkBitset>.

the <GtkBitset> with an additional reference

Method: bitset:remove-all self
Method: remove-all self

Removes all values from the bitset so that it is empty again.

self

Passed: a <GtkBitset>.

a <GtkBitset>

Method: bitset:remove-range self start n-items
Method: remove-range self start n-items

Removes all values from start (inclusive) to start + n-items (exclusive) in self.

self

Passed: a <GtkBitset>.

a <GtkBitset>

start

Passed: an unsigned 32-bit integer.

first value to remove

n-items

Passed: an unsigned 32-bit integer.

number of consecutive values to remove

Method: bitset:remove-range-closed self first last
Method: remove-range-closed self first last

Removes the closed range [first, last], so first, last and all values in between. first must be smaller than last.

self

Passed: a <GtkBitset>.

a <GtkBitset>

first

Passed: an unsigned 32-bit integer.

first value to remove

last

Passed: an unsigned 32-bit integer.

last value to remove

Method: bitset:remove-rectangle self start width height stride
Method: remove-rectangle self start width height 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.

self

Passed: a <GtkBitset>.

a <GtkBitset>

start

Passed: an unsigned 32-bit integer.

first value to remove

width

Passed: an unsigned 32-bit integer.

width of the rectangle

height

Passed: an unsigned 32-bit integer.

height of the rectangle

stride

Passed: an unsigned 32-bit integer.

row stride of the grid

Method: bitset:remove? self value ⇒ %return
Method: remove? self value ⇒ %return

Removes value from self if it was part of it before.

self

Passed: a <GtkBitset>.

a <GtkBitset>

value

Passed: an unsigned 32-bit integer.

value to remove

%return

Returned: a boolean.

#t if value was part of self and self was changed

Method: bitset:shift-left self amount
Method: shift-left self amount

Shifts all values in self to the left by amount.

Values smaller than amount are discarded.

self

Passed: a <GtkBitset>.

a <GtkBitset>

amount

Passed: an unsigned 32-bit integer.

amount to shift all values to the left

Method: bitset:shift-right self amount
Method: shift-right self 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.

self

Passed: a <GtkBitset>.

a <GtkBitset>

amount

Passed: an unsigned 32-bit integer.

amount to shift all values to the right

Method: bitset:splice self position removed added
Method: splice self position removed added

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.

self

Passed: a <GtkBitset>.

a <GtkBitset>

position

Passed: an unsigned 32-bit integer.

position at which to slice

removed

Passed: an unsigned 32-bit integer.

number of values to remove

added

Passed: an unsigned 32-bit integer.

number of values to add

Method: bitset:subtract self other
Method: subtract self other

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.

self

Passed: a <GtkBitset>.

a <GtkBitset>

other

Passed: a <GtkBitset>.

the <GtkBitset> to subtract

Method: bitset:union self other
Method: union self 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.

self

Passed: a <GtkBitset>.

a <GtkBitset>

other

Passed: a <GtkBitset>.

the <GtkBitset> to union with

Method: bitset:unref self
Method: unref self

Releases a reference on the given <GtkBitset>.

If the reference was the last, the resources associated to the self are freed.

self

Passed: a <GtkBitset>.

a <GtkBitset>