Gjsify LogoGjsify Logo

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].

record

Hierarchy

  • Bitset

Index

Constructors

Properties

name: string

Methods

  • add(value: number): boolean
  • add_range(start: number, n_items: number): void
  • Adds all values from start (inclusive) to start + n_items (exclusive) in self.

    Parameters

    • start: number

      first value to add

    • n_items: number

      number of consecutive values to add

    Returns void

  • add_range_closed(first: number, last: number): void
  • Adds the closed range [first, last], so first, last and all values in between. first must be smaller than last.

    Parameters

    • first: number

      first value to add

    • last: number

      last value to add

    Returns void

  • add_rectangle(start: number, width: number, height: number, stride: number): void
  • 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: number

      first value to add

    • width: number

      width of the rectangle

    • height: number

      height of the rectangle

    • stride: number

      row stride of the grid

    Returns void

  • contains(value: number): boolean
  • Checks if the given value has been added to self

    Parameters

    • value: number

      the value to check

    Returns boolean

  • difference(other: Bitset): void
  • 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: Bitset

      the GtkBitset to compute the difference from

    Returns void

  • equals(other: Bitset): boolean
  • get_maximum(): number
  • get_minimum(): number
  • get_nth(nth: number): number
  • Returns the value of the nth item in self.

    If nth is >= the size of self, 0 is returned.

    Parameters

    • nth: number

      index of the item to get

    Returns number

  • get_size(): number
  • 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 number

  • get_size_in_range(first: number, last: number): number
  • 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: number

      the first element to include

    • last: number

      the last element to include

    Returns number

  • intersect(other: Bitset): void
  • 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: Bitset

      the GtkBitset to intersect with

    Returns void

  • is_empty(): boolean
  • remove(value: number): boolean
  • Removes value from self if it was part of it before.

    Parameters

    • value: number

      value to add

    Returns boolean

  • remove_all(): void
  • remove_range(start: number, n_items: number): void
  • Removes all values from start (inclusive) to start + n_items (exclusive) in self.

    Parameters

    • start: number

      first value to remove

    • n_items: number

      number of consecutive values to remove

    Returns void

  • remove_range_closed(first: number, last: number): void
  • Removes the closed range [first, last], so first, last and all values in between. first must be smaller than last.

    Parameters

    • first: number

      first value to remove

    • last: number

      last value to remove

    Returns void

  • remove_rectangle(start: number, width: number, height: number, stride: number): void
  • 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: number

      first value to remove

    • width: number

      width of the rectangle

    • height: number

      height of the rectangle

    • stride: number

      row stride of the grid

    Returns void

  • shift_left(amount: number): void
  • Shifts all values in self to the left by amount.

    Values smaller than amount are discarded.

    Parameters

    • amount: number

      amount to shift all values to the left

    Returns void

  • shift_right(amount: number): void
  • 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: number

      amount to shift all values to the right

    Returns void

  • splice(position: number, removed: number, added: number): void
  • 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: number

      position at which to slice

    • removed: number

      number of values to remove

    • added: number

      number of values to add

    Returns void

  • 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: Bitset

      the GtkBitset to subtract

    Returns void

  • 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: Bitset

      the GtkBitset to union with

    Returns void

  • unref(): void
  • Releases a reference on the given GtkBitset.

    If the reference was the last, the resources associated to the self are freed.

    Returns void

  • new_range(start: number, n_items: number): Bitset
  • Creates a bitset with the given range set.

    Parameters

    • start: number

      first value to add

    • n_items: number

      number of consecutive values to add

    Returns Bitset

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method