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.

  • ptr

    Untyped pointer to the underlying GtkBitset instance.

    Declaration

    Swift

    var ptr: UnsafeMutableRawPointer! { get }
  • bitset_ptr Default implementation

    Typed 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)

Bitset Record: BitsetProtocol extension (methods and fields)

  • add(value:) Extension method

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

    Declaration

    Swift

    @inlinable
    func add(value: Int) -> Bool
  • addRange(start:nItems:) Extension method

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

    Declaration

    Swift

    @inlinable
    func addRange(start: Int, nItems: Int)
  • addRangeClosed(first:last:) Extension method

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

    Declaration

    Swift

    @inlinable
    func addRangeClosed(first: Int, last: Int)
  • 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.

    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 to self

    Declaration

    Swift

    @inlinable
    func contains(value: Int) -> Bool
  • copy() Extension method

    Creates a copy of self.

    Declaration

    Swift

    @inlinable
    func copy() -> BitsetRef!
  • difference(other:) Extension method

    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.

    Declaration

    Swift

    @inlinable
    func difference<BitsetT>(other: BitsetT) where BitsetT : BitsetProtocol
  • equals(other:) Extension method

    Returns true if self and other contain the same values.

    Declaration

    Swift

    @inlinable
    func equals<BitsetT>(other: BitsetT) -> Bool where BitsetT : BitsetProtocol
  • getMaximum() Extension method

    Returns the largest value in self.

    If self is empty, 0 is returned.

    Declaration

    Swift

    @inlinable
    func getMaximum() -> Int
  • getMinimum() Extension method

    Returns 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 of self, 0 is returned.

    Declaration

    Swift

    @inlinable
    func get(nth: Int) -> Int
  • getSize() Extension method

    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.

    Declaration

    Swift

    @inlinable
    func getSize() -> guint64
  • getSizeInRange(first:last:) Extension method

    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.

    Declaration

    Swift

    @inlinable
    func getSizeInRange(first: Int, last: Int) -> guint64
  • intersect(other:) Extension method

    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.

    Declaration

    Swift

    @inlinable
    func intersect<BitsetT>(other: BitsetT) where BitsetT : BitsetProtocol
  • ref() Extension method

    Acquires a reference on the given GtkBitset.

    Declaration

    Swift

    @discardableResult
    @inlinable
    func ref() -> BitsetRef!
  • remove(value:) Extension method

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

    Declaration

    Swift

    @inlinable
    func remove(value: Int) -> Bool
  • removeAll() Extension method

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

    Declaration

    Swift

    @inlinable
    func removeAll()
  • removeRange(start:nItems:) Extension method

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

    Declaration

    Swift

    @inlinable
    func removeRange(start: Int, nItems: Int)
  • Removes the closed range [first, last], so first, last and all values in between. first must be smaller than last.

    Declaration

    Swift

    @inlinable
    func removeRangeClosed(first: Int, last: Int)
  • 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.

    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 by amount.

    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 by amount.

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

    Declaration

    Swift

    @inlinable
    func shiftRight(amount: Int)
  • This is a support function for GListModel handling, by mirroring the GlistModelitems-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.

    Declaration

    Swift

    @inlinable
    func splice(position: Int, removed: Int, added: Int)
  • subtract(other:) Extension method

    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.

    Declaration

    Swift

    @inlinable
    func subtract<BitsetT>(other: BitsetT) where BitsetT : BitsetProtocol
  • union(other:) Extension method

    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.

    Declaration

    Swift

    @inlinable
    func union<BitsetT>(other: BitsetT) where BitsetT : BitsetProtocol
  • unref() Extension method

    Releases 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()
  • Initializes iter to point to target.

    If target is not found, finds the next value after it. If no value >= target exists in set, this function returns false.

    Declaration

    Swift

    @inlinable
    func bitsetIterInitAt<BitsetIterT>(iter: BitsetIterT, target: Int, value: UnsafeMutablePointer<guint>! = nil) -> Bool where BitsetIterT : BitsetIterProtocol
  • Initializes an iterator for set and points it to the first value in set.

    If set is empty, false is returned and value is set to G_MAXUINT.

    Declaration

    Swift

    @inlinable
    func bitsetIterInitFirst<BitsetIterT>(iter: BitsetIterT, value: UnsafeMutablePointer<guint>! = nil) -> Bool where BitsetIterT : BitsetIterProtocol
  • Initializes an iterator for set and points it to the last value in set.

    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 method

    Check if no value is contained in bitset.

    Declaration

    Swift

    @inlinable
    var isEmpty: Bool { get }
  • maximum Extension method

    Returns the largest value in self.

    If self is empty, 0 is returned.

    Declaration

    Swift

    @inlinable
    var maximum: Int { get }
  • minimum Extension method

    Returns the smallest value in self.

    If self is empty, G_MAXUINT is returned.

    Declaration

    Swift

    @inlinable
    var minimum: Int { get }
  • size Extension method

    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.

    Declaration

    Swift

    @inlinable
    var size: guint64 { get }