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
.
GLib type: Shared boxed type with reference counted clone semantics.
Implementations§
Source§impl Bitset
impl Bitset
Sourcepub fn add_range_closed(&self, first: u32, last: u32)
pub fn add_range_closed(&self, first: u32, last: u32)
pub fn copy(&self) -> Bitset
Sourcepub fn difference(&self, other: &Bitset)
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
Sourcepub fn maximum(&self) -> u32
pub fn maximum(&self) -> u32
Returns the largest value in @self.
If @self is empty, 0 is returned.
§Returns
The largest value in @self
Sourcepub fn minimum(&self) -> u32
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
Sourcepub fn size(&self) -> u64
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.
Sourcepub fn size_in_range(&self, first: u32, last: u32) -> u64
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.
Sourcepub fn remove_all(&self)
pub fn remove_all(&self)
Removes all values from the bitset so that it is empty again.
Sourcepub fn remove_range(&self, start: u32, n_items: u32)
pub fn remove_range(&self, start: u32, n_items: u32)
Sourcepub fn remove_range_closed(&self, first: u32, last: u32)
pub fn remove_range_closed(&self, first: u32, last: u32)
Sourcepub fn shift_left(&self, amount: u32)
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
Sourcepub fn shift_right(&self, amount: u32)
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
Sourcepub fn splice(&self, position: u32, removed: u32, added: u32)
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
Trait Implementations§
Source§impl HasParamSpec for Bitset
impl HasParamSpec for Bitset
Source§impl Ord for Bitset
impl Ord for Bitset
Source§impl PartialOrd for Bitset
impl PartialOrd for Bitset
Source§impl StaticType for Bitset
impl StaticType for Bitset
Source§fn static_type() -> Type
fn static_type() -> Type
Self
.