Struct gtk4::Bitset[][src]

pub struct Bitset(_);
Expand description

A Bitset 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. Bitset 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 BitsetIter.

The main use case for Bitset is implementing complex selections for SelectionModel.

Implementations

Creates a new empty bitset.

Returns

A new empty bitset

Creates a bitset with the given range set.

start

first value to add

n_items

number of consecutive values to add

Returns

A new bitset

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

value

value to add

Returns

true if value was not part of self and self was changed.

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

start

first value to add

n_items

number of consecutive values to add

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

first

first value to add

last

last value to add

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.

start

first value to add

width

width of the rectangle

height

height of the rectangle

stride

row stride of the grid

Checks if the given value has been added to self

value

the value to check

Returns

true if self contains value

Creates a copy of self.

Returns

A new bitset that contains the same values as self

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.

other

the Bitset to compute the difference from

Returns true if self and other contain the same values.

other

another Bitset

Returns

true if self and other contain the same values

Returns the largest value in self.

If self is empty, 0 is returned.

Returns

The largest value in self

Returns the smallest value in self.

If self is empty, G_MAXUINT is returned.

Returns

The smallest value in self

Returns the value of the nth item in self.

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

nth

index of the item to get

Returns

the value of the nth item in 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.

Returns

The number of values in the set.

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.

first

the first element to include

last

the last element to include

Returns

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

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.

other

the Bitset to intersect with

Check if no value is contained in bitset.

Returns

true if self is empty

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

value

value to add

Returns

true if value was part of self and self was changed.

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

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

start

first value to remove

n_items

number of consecutive values to remove

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

first

first value to remove

last

last value to remove

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.

start

first value to remove

width

width of the rectangle

height

height of the rectangle

stride

row stride of the grid

Shifts all values in self to the left by amount.

Values smaller than amount are discarded.

amount

amount to shift all values to the left

Shifts all values in self to the right by amount.

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

amount

amount to shift all values to the right

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.

position

position at which to slice

removed

number of values to remove

added

number of values to add

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.

other

the Bitset to subtract

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.

other

the Bitset to union with

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Returns the type identifier of Self.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.