Struct gtk4::Bitset

source ·
#[repr(transparent)]
pub struct Bitset { /* private fields */ }
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§

source§

impl Bitset

source

pub fn new_empty() -> Bitset

Creates a new empty bitset.

Returns

A new empty bitset

source

pub fn new_range(start: u32, n_items: u32) -> 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

source

pub fn add(&self, value: u32) -> bool

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

source

pub fn add_range(&self, start: u32, n_items: u32)

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

source

pub fn add_range_closed(&self, first: u32, last: u32)

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

source

pub fn add_rectangle(&self, start: u32, width: u32, height: u32, stride: u32)

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

source

pub fn contains(&self, value: u32) -> bool

Checks if the given @value has been added to @self

value

the value to check

Returns

true if @self contains @value

source

pub fn copy(&self) -> Bitset

source

pub fn difference(&self, other: &Bitset)

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

source

pub fn equals(&self, other: &Bitset) -> bool

Returns true if @self and @other contain the same values.

other

another Bitset

Returns

true if @self and @other contain the same values

source

pub fn maximum(&self) -> u32

Returns the largest value in @self.

If @self is empty, 0 is returned.

Returns

The largest value in @self

source

pub fn minimum(&self) -> u32

Returns the smallest value in @self.

If @self is empty, G_MAXUINT is returned.

Returns

The smallest value in @self

source

pub fn nth(&self, nth: u32) -> u32

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

source

pub fn size(&self) -> u64

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.

source

pub fn size_in_range(&self, first: u32, last: u32) -> u64

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.

source

pub fn intersect(&self, other: &Bitset)

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

source

pub fn is_empty(&self) -> bool

Check if no value is contained in bitset.

Returns

true if @self is empty

source

pub fn remove(&self, value: u32) -> bool

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

source

pub fn remove_all(&self)

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

source

pub fn remove_range(&self, start: u32, n_items: u32)

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

source

pub fn remove_range_closed(&self, first: u32, last: u32)

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

source

pub fn remove_rectangle(&self, start: u32, width: u32, height: u32, stride: u32)

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

source

pub fn shift_left(&self, amount: u32)

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

source

pub fn shift_right(&self, amount: u32)

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

source

pub fn splice(&self, position: u32, removed: u32, added: u32)

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

source

pub fn subtract(&self, other: &Bitset)

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

source

pub fn union(&self, other: &Bitset)

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§

source§

impl Clone for Bitset

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Bitset

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Hash for Bitset

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

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

impl Ord for Bitset

source§

fn cmp(&self, other: &Bitset) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<Bitset> for Bitset

source§

fn eq(&self, other: &Bitset) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Bitset> for Bitset

source§

fn partial_cmp(&self, other: &Bitset) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

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

fn le(&self, other: &Rhs) -> bool

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

fn gt(&self, other: &Rhs) -> bool

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

fn ge(&self, other: &Rhs) -> bool

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

impl StaticType for Bitset

source§

fn static_type() -> Type

Returns the type identifier of Self.
source§

impl Eq for Bitset

source§

impl StructuralEq for Bitset

source§

impl StructuralPartialEq for Bitset

Auto Trait Implementations§

§

impl RefUnwindSafe for Bitset

§

impl !Send for Bitset

§

impl !Sync for Bitset

§

impl Unpin for Bitset

§

impl UnwindSafe for Bitset

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *const GPtrArray, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( _: *const GPtrArray, _: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( _: *const GPtrArray, _: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *const GSList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( _: *const GSList, _: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( _: *const GSList, _: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *mut GList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( ptr: *mut GList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( ptr: *mut GList, num: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *mut GPtrArray, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( ptr: *mut GPtrArray, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( ptr: *mut GPtrArray, num: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_num_as_vec( ptr: *mut GSList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_container_num_as_vec( ptr: *mut GSList, num: usize ) -> Vec<T, Global>

source§

unsafe fn from_glib_full_num_as_vec( ptr: *mut GSList, num: usize ) -> Vec<T, Global>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_as_vec(ptr: *const GPtrArray) -> Vec<T, Global>

source§

unsafe fn from_glib_container_as_vec(_: *const GPtrArray) -> Vec<T, Global>

source§

unsafe fn from_glib_full_as_vec(_: *const GPtrArray) -> Vec<T, Global>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_as_vec(ptr: *mut GList) -> Vec<T, Global>

source§

unsafe fn from_glib_container_as_vec(ptr: *mut GList) -> Vec<T, Global>

source§

unsafe fn from_glib_full_as_vec(ptr: *mut GList) -> Vec<T, Global>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_as_vec(ptr: *mut GPtrArray) -> Vec<T, Global>

source§

unsafe fn from_glib_container_as_vec(ptr: *mut GPtrArray) -> Vec<T, Global>

source§

unsafe fn from_glib_full_as_vec(ptr: *mut GPtrArray) -> Vec<T, Global>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

unsafe fn from_glib_none_as_vec(ptr: *mut GSList) -> Vec<T, Global>

source§

unsafe fn from_glib_container_as_vec(ptr: *mut GSList) -> Vec<T, Global>

source§

unsafe fn from_glib_full_as_vec(ptr: *mut GSList) -> Vec<T, Global>

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticTypeExt for Twhere T: StaticType,

source§

fn ensure_type()

Ensures that the type has been registered with the type system.
source§

impl<T> ToClosureReturnValue for Twhere T: ToValue,

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T> TryFromClosureReturnValue for Twhere T: for<'a> FromValue<'a> + StaticType + 'static,

source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<'a, T, C> FromValueOptional<'a> for Twhere T: FromValue<'a, Checker = C>, C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError>,