Package ch.bailu.gtk.gtk
Class Bitset
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.type.Record
ch.bailu.gtk.gtk.Bitset
- All Implemented Interfaces:
PointerInterface
A `GtkBitset` represents a set of unsigned integers.
Another name for this data structure is "bitmap".
The current implementation is based on [roaring bitmaps](https://roaringbitmap.org/).
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].
Another name for this data structure is "bitmap".
The current implementation is based on [roaring bitmaps](https://roaringbitmap.org/).
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].
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
add
(int value) Adds @value to @self if it wasn't part of it before.void
addRange
(int start, int n_items) Adds all values from @start (inclusive) to @start + @n_items
(exclusive) in @self.void
addRangeClosed
(int first, int last) Adds the closed range [@first, @last], so @first, @last and all
values in between.void
addRectangle
(int start, int width, int height, int 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.boolean
contains
(int value) Checks if the given @value has been added to @selfcopy()
Creates a copy of @self.void
difference
(Bitset other) Sets @self to be the symmetric difference of @self and @other.boolean
Returns %TRUE if @self and @other contain the same values.static ClassHandler
static int
int
Returns the largest value in @self.int
Returns the smallest value in @self.int
getNth
(int nth) Returns the value of the @nth item in self.static long
static TypeSystem.TypeSize
long
getSize()
Gets the number of values that were added to the set.long
getSizeInRange
(int first, int last) Gets the number of values that are part of the set from @first to @last
(inclusive).static long
static TypeSystem.TypeSize
void
Sets @self to be the intersection of @self and @other.boolean
isEmpty()
Check if no value is contained in bitset.static Bitset
Creates a new empty bitset.static Bitset
newRangeBitset
(int start, int n_items) Creates a bitset with the given range set.ref()
Acquires a reference on the given `GtkBitset`.boolean
remove
(int value) Removes @value from @self if it was part of it before.void
Removes all values from the bitset so that it is empty again.void
removeRange
(int start, int n_items) Removes all values from @start (inclusive) to @start + @n_items (exclusive)
in @self.void
removeRangeClosed
(int first, int last) Removes the closed range [@first, @last], so @first, @last and all
values in between.void
removeRectangle
(int start, int width, int height, int 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.void
shiftLeft
(int amount) Shifts all values in @self to the left by @amount.void
shiftRight
(int amount) Shifts all values in @self to the right by @amount.void
splice
(int position, int removed, int added) This is a support function for `GListModel` handling, by mirroring
the `GlistModel::items-changed` signal.void
Sets @self to be the subtraction of @other from @self.void
Sets @self to be the union of @self and @other.void
unref()
Releases a reference on the given `GtkBitset`.Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Constructor Details
-
Bitset
-
-
Method Details
-
getClassHandler
-
newEmptyBitset
Creates a new empty bitset.- Returns:
- A new empty bitset
-
newRangeBitset
Creates a bitset with the given range set.- Parameters:
start
- first value to addn_items
- number of consecutive values to add- Returns:
- A new bitset
-
add
public boolean add(int value) Adds @value to @self if it wasn't part of it before.- Parameters:
value
- value to add- Returns:
- %TRUE if @value was not part of @self and @self was changed
-
addRange
public void addRange(int start, int n_items) Adds all values from @start (inclusive) to @start + @n_items
(exclusive) in @self.- Parameters:
start
- first value to addn_items
- number of consecutive values to add
-
addRangeClosed
public void addRangeClosed(int first, int last) Adds the closed range [@first, @last], so @first, @last and all
values in between. @first must be smaller than @last.- Parameters:
first
- first value to addlast
- last value to add
-
addRectangle
public void addRectangle(int start, int width, int height, int 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.- Parameters:
start
- first value to addwidth
- width of the rectangleheight
- height of the rectanglestride
- row stride of the grid
-
contains
public boolean contains(int value) Checks if the given @value has been added to @self- Parameters:
value
- the value to check- Returns:
- %TRUE if @self contains @value
-
copy
Creates a copy of @self.- Returns:
- A new bitset that contains the same values as @self
-
difference
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.- Parameters:
other
- the `GtkBitset` to compute the difference from
-
equals
Returns %TRUE if @self and @other contain the same values.- Parameters:
other
- another `GtkBitset`- Returns:
- %TRUE if @self and @other contain the same values
-
getMaximum
public int getMaximum()Returns the largest value in @self.
If @self is empty, 0 is returned.- Returns:
- The largest value in @self
-
getMinimum
public int getMinimum()Returns the smallest value in @self.
If @self is empty, `G_MAXUINT` is returned.- Returns:
- The smallest value in @self
-
getNth
public int getNth(int nth) Returns the value of the @nth item in self.
If @nth is >= the size of @self, 0 is returned.- Parameters:
nth
- index of the item to get- Returns:
- the value of the @nth item in @self
-
getSize
public long getSize()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.
-
getSizeInRange
public long getSizeInRange(int first, int last) 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.- Parameters:
first
- the first element to includelast
- the last element to include- Returns:
- The number of values in the set from @first to @last.
-
intersect
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.- Parameters:
other
- the `GtkBitset` to intersect with
-
isEmpty
public boolean isEmpty()Check if no value is contained in bitset.- Returns:
- %TRUE if @self is empty
-
ref
Acquires a reference on the given `GtkBitset`.- Returns:
- the `GtkBitset` with an additional reference
-
remove
public boolean remove(int value) Removes @value from @self if it was part of it before.- Parameters:
value
- value to add- Returns:
- %TRUE if @value was part of @self and @self was changed
-
removeAll
public void removeAll()Removes all values from the bitset so that it is empty again. -
removeRange
public void removeRange(int start, int n_items) Removes all values from @start (inclusive) to @start + @n_items (exclusive)
in @self.- Parameters:
start
- first value to removen_items
- number of consecutive values to remove
-
removeRangeClosed
public void removeRangeClosed(int first, int last) Removes the closed range [@first, @last], so @first, @last and all
values in between. @first must be smaller than @last.- Parameters:
first
- first value to removelast
- last value to remove
-
removeRectangle
public void removeRectangle(int start, int width, int height, int 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.- Parameters:
start
- first value to removewidth
- width of the rectangleheight
- height of the rectanglestride
- row stride of the grid
-
shiftLeft
public void shiftLeft(int amount) Shifts all values in @self to the left by @amount.
Values smaller than @amount are discarded.- Parameters:
amount
- amount to shift all values to the left
-
shiftRight
public void shiftRight(int 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.- Parameters:
amount
- amount to shift all values to the right
-
splice
public void splice(int position, int removed, int 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.- Parameters:
position
- position at which to sliceremoved
- number of values to removeadded
- number of values to add
-
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.- Parameters:
other
- the `GtkBitset` to subtract
-
union
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.- Parameters:
other
- the `GtkBitset` to union with
-
unref
public void unref()Releases a reference on the given `GtkBitset`.
If the reference was the last, the resources associated to the @self are
freed. -
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-