Gtk.Bitset

Fields

None

Methods

class

new_empty ()

class

new_range (start, n_items)

add (value)

add_range (start, n_items)

add_range_closed (first, last)

add_rectangle (start, width, height, stride)

contains (value)

copy ()

difference (other)

equals (other)

get_maximum ()

get_minimum ()

get_nth (nth)

get_size ()

get_size_in_range (first, last)

intersect (other)

is_empty ()

ref ()

remove (value)

remove_all ()

remove_range (start, n_items)

remove_range_closed (first, last)

remove_rectangle (start, width, height, stride)

shift_left (amount)

shift_right (amount)

splice (position, removed, added)

subtract (other)

union (other)

unref ()

Details

class Gtk.Bitset

A GtkBitset represents 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 [struct`Gtk`.BitsetIter].

The main use case for GtkBitset is implementing complex selections for [iface`Gtk`.SelectionModel].

classmethod new_empty()[source]
Returns:

A new empty bitset

Return type:

Gtk.Bitset

Creates a new empty bitset.

classmethod new_range(start, n_items)[source]
Parameters:
  • start (int) – first value to add

  • n_items (int) – number of consecutive values to add

Returns:

A new bitset

Return type:

Gtk.Bitset

Creates a bitset with the given range set.

add(value)[source]
Parameters:

value (int) – value to add

Returns:

True if value was not part of self and self was changed

Return type:

bool

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

add_range(start, n_items)[source]
Parameters:
  • start (int) – first value to add

  • n_items (int) – number of consecutive values to add

Adds all values from start (inclusive) to start + n_items (exclusive) in self.

add_range_closed(first, last)[source]
Parameters:
  • first (int) – first value to add

  • last (int) – last value to add

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

add_rectangle(start, width, height, stride)[source]
Parameters:
  • start (int) – first value to add

  • width (int) – width of the rectangle

  • height (int) – height of the rectangle

  • stride (int) – row stride of the grid

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.

contains(value)[source]
Parameters:

value (int) – the value to check

Returns:

True if self contains value

Return type:

bool

Checks if the given value has been added to self

copy()[source]
Returns:

A new bitset that contains the same values as self

Return type:

Gtk.Bitset

Creates a copy of self.

difference(other)[source]
Parameters:

other (Gtk.Bitset) – the GtkBitset to compute the difference from

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.

equals(other)[source]
Parameters:

other (Gtk.Bitset) – another GtkBitset

Returns:

True if self and other contain the same values

Return type:

bool

Returns True if self and other contain the same values.

get_maximum()[source]
Returns:

The largest value in self

Return type:

int

Returns the largest value in self.

If self is empty, 0 is returned.

get_minimum()[source]
Returns:

The smallest value in self

Return type:

int

Returns the smallest value in self.

If self is empty, G_MAXUINT is returned.

get_nth(nth)[source]
Parameters:

nth (int) – index of the item to get

Returns:

the value of the nth item in self

Return type:

int

Returns the value of the nth item in self.

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

get_size()[source]
Returns:

The number of values in the set.

Return type:

int

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.

get_size_in_range(first, last)[source]
Parameters:
  • first (int) – the first element to include

  • last (int) – the last element to include

Returns:

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

Return type:

int

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.

intersect(other)[source]
Parameters:

other (Gtk.Bitset) – the GtkBitset to intersect with

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.

is_empty()[source]
Returns:

True if self is empty

Return type:

bool

Check if no value is contained in bitset.

ref()[source]
Returns:

the GtkBitset with an additional reference

Return type:

Gtk.Bitset

Acquires a reference on the given GtkBitset.

remove(value)[source]
Parameters:

value (int) – value to remove

Returns:

True if value was part of self and self was changed

Return type:

bool

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

remove_all()[source]

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

remove_range(start, n_items)[source]
Parameters:
  • start (int) – first value to remove

  • n_items (int) – number of consecutive values to remove

Removes all values from start (inclusive) to start + n_items (exclusive) in self.

remove_range_closed(first, last)[source]
Parameters:
  • first (int) – first value to remove

  • last (int) – last value to remove

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

remove_rectangle(start, width, height, stride)[source]
Parameters:
  • start (int) – first value to remove

  • width (int) – width of the rectangle

  • height (int) – height of the rectangle

  • stride (int) – row stride of the grid

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.

shift_left(amount)[source]
Parameters:

amount (int) – amount to shift all values to the left

Shifts all values in self to the left by amount.

Values smaller than amount are discarded.

shift_right(amount)[source]
Parameters:

amount (int) – amount to shift all values to the right

Shifts all values in self to the right by amount.

Values that end up too large to be held in a int are discarded.

splice(position, removed, added)[source]
Parameters:
  • position (int) – position at which to slice

  • removed (int) – number of values to remove

  • added (int) – number of values to add

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.

subtract(other)[source]
Parameters:

other (Gtk.Bitset) – the GtkBitset to subtract

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.

union(other)[source]
Parameters:

other (Gtk.Bitset) – the GtkBitset to union with

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.

unref()[source]

Releases a reference on the given GtkBitset.

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