BitsetProtocol
public protocol BitsetProtocol
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 [structGtk.BitsetIter
].
The main use case for GtkBitset
is implementing complex selections for
[ifaceGtk.SelectionModel
].
The BitsetProtocol
protocol exposes the methods and properties of an underlying GtkBitset
instance.
The default implementation of these can be found in the protocol extension below.
For a concrete class that implements these methods and properties, see Bitset
.
Alternatively, use BitsetRef
as a lighweight, unowned
reference if you already have an instance you just want to use.
-
Untyped pointer to the underlying
GtkBitset
instance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get }
-
bitset_ptr
Default implementationTyped pointer to the underlying
GtkBitset
instance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GtkBitset
instance.Declaration
Swift
var bitset_ptr: UnsafeMutablePointer<GtkBitset>! { get }
-
Required Initialiser for types conforming to
BitsetProtocol
Declaration
Swift
init(raw: UnsafeMutableRawPointer)
-
add(value:
Extension method) Adds
value
toself
if it wasn’t part of it before.Declaration
Swift
@inlinable func add(value: Int) -> Bool
-
addRange(start:
Extension methodnItems: ) Adds all values from
start
(inclusive) tostart
+n_items
(exclusive) inself
.Declaration
Swift
@inlinable func addRange(start: Int, nItems: Int)
-
addRangeClosed(first:
Extension methodlast: ) Adds the closed range [
first
,last
], sofirst
,last
and all values in between.first
must be smaller thanlast
.Declaration
Swift
@inlinable func addRangeClosed(first: Int, last: Int)
-
addRectangle(start:
Extension methodwidth: height: stride: ) Interprets the values as a 2-dimensional boolean grid with the given
stride
and inside that grid, adds a rectangle with the givenwidth
andheight
.Declaration
Swift
@inlinable func addRectangle(start: Int, width: Int, height: Int, stride: Int)
-
contains(value:
Extension method) Checks if the given
value
has been added toself
Declaration
Swift
@inlinable func contains(value: Int) -> Bool
-
copy()
Extension methodCreates a copy of
self
.Declaration
Swift
@inlinable func copy() -> BitsetRef!
-
difference(other:
Extension method) Sets
self
to be the symmetric difference ofself
andother
.The symmetric difference is set
self
to contain all values that were either contained inself
or inother
, but not in both. This operation is also called an XOR.It is allowed for
self
andother
to be the same bitset. The bitset will be emptied in that case.Declaration
Swift
@inlinable func difference<BitsetT>(other: BitsetT) where BitsetT : BitsetProtocol
-
equals(other:
Extension method) Returns
true
ifself
andother
contain the same values.Declaration
Swift
@inlinable func equals<BitsetT>(other: BitsetT) -> Bool where BitsetT : BitsetProtocol
-
getMaximum()
Extension methodReturns the largest value in
self
.If
self
is empty, 0 is returned.Declaration
Swift
@inlinable func getMaximum() -> Int
-
getMinimum()
Extension methodReturns the smallest value in
self
.If
self
is empty,G_MAXUINT
is returned.Declaration
Swift
@inlinable func getMinimum() -> Int
-
get(nth:
Extension method) Returns the value of the
nth
item in self.If
nth
is >= the size ofself
, 0 is returned.Declaration
Swift
@inlinable func get(nth: Int) -> Int
-
getSize()
Extension methodGets 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 isG_MAXUINT + 1
. Unless you are sure this cannot happen (it can’t withGListModel
), be sure to use a 64bit type.Declaration
Swift
@inlinable func getSize() -> guint64
-
getSizeInRange(first:
Extension methodlast: ) Gets the number of values that are part of the set from
first
tolast
(inclusive).Note that this function returns a
guint64
, because when all values are set, the return value isG_MAXUINT + 1
. Unless you are sure this cannot happen (it can’t withGListModel
), be sure to use a 64bit type.Declaration
Swift
@inlinable func getSizeInRange(first: Int, last: Int) -> guint64
-
intersect(other:
Extension method) Sets
self
to be the intersection ofself
andother
.In other words, remove all values from
self
that are not part ofother
.It is allowed for
self
andother
to be the same bitset. Nothing will happen in that case.Declaration
Swift
@inlinable func intersect<BitsetT>(other: BitsetT) where BitsetT : BitsetProtocol
-
ref()
Extension methodAcquires a reference on the given
GtkBitset
.Declaration
Swift
@discardableResult @inlinable func ref() -> BitsetRef!
-
remove(value:
Extension method) Removes
value
fromself
if it was part of it before.Declaration
Swift
@inlinable func remove(value: Int) -> Bool
-
removeAll()
Extension methodRemoves all values from the bitset so that it is empty again.
Declaration
Swift
@inlinable func removeAll()
-
removeRange(start:
Extension methodnItems: ) Removes all values from
start
(inclusive) tostart
+n_items
(exclusive) inself
.Declaration
Swift
@inlinable func removeRange(start: Int, nItems: Int)
-
removeRangeClosed(first:
Extension methodlast: ) Removes the closed range [
first
,last
], sofirst
,last
and all values in between.first
must be smaller thanlast
.Declaration
Swift
@inlinable func removeRangeClosed(first: Int, last: Int)
-
removeRectangle(start:
Extension methodwidth: height: stride: ) Interprets the values as a 2-dimensional boolean grid with the given
stride
and inside that grid, removes a rectangle with the givenwidth
andheight
.Declaration
Swift
@inlinable func removeRectangle(start: Int, width: Int, height: Int, stride: Int)
-
shiftLeft(amount:
Extension method) Shifts all values in
self
to the left byamount
.Values smaller than
amount
are discarded.Declaration
Swift
@inlinable func shiftLeft(amount: Int)
-
shiftRight(amount:
Extension method) Shifts all values in
self
to the right byamount
.Values that end up too large to be held in a
guint
are discarded.Declaration
Swift
@inlinable func shiftRight(amount: Int)
-
splice(position:
Extension methodremoved: added: ) This is a support function for
GListModel
handling, by mirroring theGlistModel
items-changed`` signal.First, it “cuts” the values from
position
toremoved
from the bitset. That is, it removes all those values and shifts all larger values to the left byremoved
places.Then, it “pastes” new room into the bitset by shifting all values larger than
position
byadded
spaces to the right. This frees up space that can then be filled.Declaration
Swift
@inlinable func splice(position: Int, removed: Int, added: Int)
-
subtract(other:
Extension method) Sets
self
to be the subtraction ofother
fromself
.In other words, remove all values from
self
that are part ofother
.It is allowed for
self
andother
to be the same bitset. The bitset will be emptied in that case.Declaration
Swift
@inlinable func subtract<BitsetT>(other: BitsetT) where BitsetT : BitsetProtocol
-
union(other:
Extension method) Sets
self
to be the union ofself
andother
.That is, add all values from
other
intoself
that weren’t part of it.It is allowed for
self
andother
to be the same bitset. Nothing will happen in that case.Declaration
Swift
@inlinable func union<BitsetT>(other: BitsetT) where BitsetT : BitsetProtocol
-
unref()
Extension methodReleases a reference on the given
GtkBitset
.If the reference was the last, the resources associated to the
self
are freed.Declaration
Swift
@inlinable func unref()
-
bitsetIterInitAt(iter:
Extension methodtarget: value: ) Initializes
iter
to point totarget
.If
target
is not found, finds the next value after it. If no value >=target
exists inset
, this function returnsfalse
.Declaration
Swift
@inlinable func bitsetIterInitAt<BitsetIterT>(iter: BitsetIterT, target: Int, value: UnsafeMutablePointer<guint>! = nil) -> Bool where BitsetIterT : BitsetIterProtocol
-
bitsetIterInitFirst(iter:
Extension methodvalue: ) Initializes an iterator for
set
and points it to the first value inset
.If
set
is empty,false
is returned andvalue
is set toG_MAXUINT
.Declaration
Swift
@inlinable func bitsetIterInitFirst<BitsetIterT>(iter: BitsetIterT, value: UnsafeMutablePointer<guint>! = nil) -> Bool where BitsetIterT : BitsetIterProtocol
-
bitsetIterInitLast(iter:
Extension methodvalue: ) Initializes an iterator for
set
and points it to the last value inset
.If
set
is empty,false
is returned.Declaration
Swift
@inlinable func bitsetIterInitLast<BitsetIterT>(iter: BitsetIterT, value: UnsafeMutablePointer<guint>! = nil) -> Bool where BitsetIterT : BitsetIterProtocol
-
isEmpty
Extension methodCheck if no value is contained in bitset.
Declaration
Swift
@inlinable var isEmpty: Bool { get }
-
maximum
Extension methodReturns the largest value in
self
.If
self
is empty, 0 is returned.Declaration
Swift
@inlinable var maximum: Int { get }
-
minimum
Extension methodReturns the smallest value in
self
.If
self
is empty,G_MAXUINT
is returned.Declaration
Swift
@inlinable var minimum: Int { get }
-
size
Extension methodGets 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 isG_MAXUINT + 1
. Unless you are sure this cannot happen (it can’t withGListModel
), be sure to use a 64bit type.Declaration
Swift
@inlinable var size: guint64 { get }