Class Sequence

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class Sequence extends ProxyInstance
The GSequence struct is an opaque data type representing a sequence data type.
  • Constructor Details

    • Sequence

      public Sequence(MemorySegment address)
      Create a Sequence proxy instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
  • Method Details

    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • foreachRange

      public static void foreachRange(SequenceIter begin, SequenceIter end, @Nullable Func func)
      Calls func for each item in the range (begin, end) passing userData to the function. func must not modify the sequence itself.
      Parameters:
      begin - a GSequenceIter
      end - a GSequenceIter
      func - a GFunc
      Since:
      2.14
    • get

      public static @Nullable MemorySegment get(SequenceIter iter)
      Returns the data that iter points to.
      Parameters:
      iter - a GSequenceIter
      Returns:
      the data that iter points to
      Since:
      2.14
    • insertBefore

      public static SequenceIter insertBefore(SequenceIter iter, @Nullable MemorySegment data)
      Inserts a new item just before the item pointed to by iter.
      Parameters:
      iter - a GSequenceIter
      data - the data for the new item
      Returns:
      an iterator pointing to the new item
      Since:
      2.14
    • move

      public static void move(SequenceIter src, SequenceIter dest)
      Moves the item pointed to by src to the position indicated by dest. After calling this function dest will point to the position immediately after src. It is allowed for src and dest to point into different sequences.
      Parameters:
      src - a GSequenceIter pointing to the item to move
      dest - a GSequenceIter pointing to the position to which the item is moved
      Since:
      2.14
    • moveRange

      public static void moveRange(SequenceIter dest, SequenceIter begin, SequenceIter end)

      Inserts the (begin, end) range at the destination pointed to by dest. The begin and end iters must point into the same sequence. It is allowed for dest to point to a different sequence than the one pointed into by begin and end.

      If dest is null, the range indicated by begin and end is removed from the sequence. If dest points to a place within the (begin, end) range, the range does not move.

      Parameters:
      dest - a GSequenceIter
      begin - a GSequenceIter
      end - a GSequenceIter
      Since:
      2.14
    • new_

      public static Sequence new_()
      Creates a new GSequence. The dataDestroy function, if non-null will be called on all items when the sequence is destroyed and on items that are removed from the sequence.
      Returns:
      a new GSequence
      Since:
      2.14
    • rangeGetMidpoint

      public static SequenceIter rangeGetMidpoint(SequenceIter begin, SequenceIter end)

      Finds an iterator somewhere in the range (begin, end). This iterator will be close to the middle of the range, but is not guaranteed to be exactly in the middle.

      The begin and end iterators must both point to the same sequence and begin must come before or be equal to end in the sequence.

      Parameters:
      begin - a GSequenceIter
      end - a GSequenceIter
      Returns:
      a GSequenceIter pointing somewhere in the (begin, end) range
      Since:
      2.14
    • remove

      public static void remove(SequenceIter iter)

      Removes the item pointed to by iter. It is an error to pass the end iterator to this function.

      If the sequence has a data destroy function associated with it, this function is called on the data for the removed item.

      Parameters:
      iter - a GSequenceIter
      Since:
      2.14
    • removeRange

      public static void removeRange(SequenceIter begin, SequenceIter end)

      Removes all items in the (begin, end) range.

      If the sequence has a data destroy function associated with it, this function is called on the data for the removed items.

      Parameters:
      begin - a GSequenceIter
      end - a GSequenceIter
      Since:
      2.14
    • set

      public static void set(SequenceIter iter, @Nullable MemorySegment data)
      Changes the data for the item pointed to by iter to be data. If the sequence has a data destroy function associated with it, that function is called on the existing data that iter pointed to.
      Parameters:
      iter - a GSequenceIter
      data - new data for the item
      Since:
      2.14
    • sortChanged

      public static void sortChanged(SequenceIter iter, @Nullable CompareDataFunc cmpFunc)

      Moves the data pointed to by iter to a new position as indicated by cmpFunc. This function should be called for items in a sequence already sorted according to cmpFunc whenever some aspect of an item changes so that cmpFunc may return different values for that item.

      cmpFunc is called with two items of the seq, and cmpData. It should return 0 if the items are equal, a negative value if the first item comes before the second, and a positive value if the second item comes before the first.

      Parameters:
      iter - A GSequenceIter
      cmpFunc - the function used to compare items in the sequence
      Since:
      2.14
    • sortChangedIter

      public static void sortChangedIter(SequenceIter iter, @Nullable SequenceIterCompareFunc iterCmp)

      Like g_sequence_sort_changed(), but uses a GSequenceIterCompareFunc instead of a GCompareDataFunc as the compare function.

      iterCmp is called with two iterators pointing into the GSequence that iter points into. It should return 0 if the iterators are equal, a negative value if the first iterator comes before the second, and a positive value if the second iterator comes before the first.

      Parameters:
      iter - a GSequenceIter
      iterCmp - the function used to compare iterators in the sequence
      Since:
      2.14
    • swap

      public static void swap(SequenceIter a, SequenceIter b)
      Swaps the items pointed to by a and b. It is allowed for a and b to point into difference sequences.
      Parameters:
      a - a GSequenceIter
      b - a GSequenceIter
      Since:
      2.14
    • append

      public SequenceIter append(@Nullable MemorySegment data)
      Adds a new item to the end of seq.
      Parameters:
      data - the data for the new item
      Returns:
      an iterator pointing to the new item
      Since:
      2.14
    • foreach

      public void foreach(@Nullable Func func)
      Calls func for each item in the sequence passing userData to the function. func must not modify the sequence itself.
      Parameters:
      func - the function to call for each item in this Sequence
      Since:
      2.14
    • free

      public void free()
      Frees the memory allocated for seq. If this Sequence has a data destroy function associated with it, that function is called on all items in seq.
      Since:
      2.14
    • getBeginIter

      public SequenceIter getBeginIter()
      Returns the begin iterator for seq.
      Returns:
      the begin iterator for seq.
      Since:
      2.14
    • getEndIter

      public SequenceIter getEndIter()
      Returns the end iterator for seg
      Returns:
      the end iterator for this Sequence
      Since:
      2.14
    • getIterAtPos

      public SequenceIter getIterAtPos(int pos)
      Returns the iterator at position pos. If pos is negative or larger than the number of items in seq, the end iterator is returned.
      Parameters:
      pos - a position in seq, or -1 for the end
      Returns:
      The GSequenceIter at position pos
      Since:
      2.14
    • getLength

      public int getLength()
      Returns the positive length (>= 0) of seq. Note that this method is O(h) where `h' is the height of the tree. It is thus more efficient to use g_sequence_is_empty() when comparing the length to zero.
      Returns:
      the length of this Sequence
      Since:
      2.14
    • insertSorted

      public SequenceIter insertSorted(@Nullable MemorySegment data, @Nullable CompareDataFunc cmpFunc)

      Inserts data into this Sequence using cmpFunc to determine the new position. The sequence must already be sorted according to cmpFunc; otherwise the new position of data is undefined.

      cmpFunc is called with two items of the seq, and cmpData. It should return 0 if the items are equal, a negative value if the first item comes before the second, and a positive value if the second item comes before the first.

      Note that when adding a large amount of data to a GSequence, it is more efficient to do unsorted insertions and then call g_sequence_sort() or g_sequence_sort_iter().

      Parameters:
      data - the data to insert
      cmpFunc - the function used to compare items in the sequence
      Returns:
      a GSequenceIter pointing to the new item.
      Since:
      2.14
    • insertSortedIter

      public SequenceIter insertSortedIter(@Nullable MemorySegment data, @Nullable SequenceIterCompareFunc iterCmp)

      Like g_sequence_insert_sorted(), but uses a GSequenceIterCompareFunc instead of a GCompareDataFunc as the compare function.

      iterCmp is called with two iterators pointing into seq. It should return 0 if the iterators are equal, a negative value if the first iterator comes before the second, and a positive value if the second iterator comes before the first.

      Note that when adding a large amount of data to a GSequence, it is more efficient to do unsorted insertions and then call g_sequence_sort() or g_sequence_sort_iter().

      Parameters:
      data - data for the new item
      iterCmp - the function used to compare iterators in the sequence
      Returns:
      a GSequenceIter pointing to the new item
      Since:
      2.14
    • isEmpty

      public boolean isEmpty()

      Returns true if the sequence contains zero items.

      This function is functionally identical to checking the result of g_sequence_get_length() being equal to zero. However this function is implemented in O(1) running time.

      Returns:
      true if the sequence is empty, otherwise false.
      Since:
      2.48
    • lookup

      public @Nullable SequenceIter lookup(@Nullable MemorySegment data, @Nullable CompareDataFunc cmpFunc)

      Returns an iterator pointing to the position of the first item found equal to data according to cmpFunc and cmpData. If more than one item is equal, it is not guaranteed that it is the first which is returned. In that case, you can use g_sequence_iter_next() and g_sequence_iter_prev() to get others.

      cmpFunc is called with two items of the seq, and cmpData. It should return 0 if the items are equal, a negative value if the first item comes before the second, and a positive value if the second item comes before the first.

      This function will fail if the data contained in the sequence is unsorted.

      Parameters:
      data - data to look up
      cmpFunc - the function used to compare items in the sequence
      Returns:
      an GSequenceIter pointing to the position of the first item found equal to data according to cmpFunc and cmpData, or null if no such item exists
      Since:
      2.28
    • lookupIter

      public @Nullable SequenceIter lookupIter(@Nullable MemorySegment data, @Nullable SequenceIterCompareFunc iterCmp)

      Like g_sequence_lookup(), but uses a GSequenceIterCompareFunc instead of a GCompareDataFunc as the compare function.

      iterCmp is called with two iterators pointing into seq. It should return 0 if the iterators are equal, a negative value if the first iterator comes before the second, and a positive value if the second iterator comes before the first.

      This function will fail if the data contained in the sequence is unsorted.

      Parameters:
      data - data to look up
      iterCmp - the function used to compare iterators in the sequence
      Returns:
      an GSequenceIter pointing to the position of the first item found equal to data according to iterCmp and cmpData, or null if no such item exists
      Since:
      2.28
    • prepend

      public SequenceIter prepend(@Nullable MemorySegment data)
      Adds a new item to the front of this Sequence
      Parameters:
      data - the data for the new item
      Returns:
      an iterator pointing to the new item
      Since:
      2.14
    • search

      public SequenceIter search(@Nullable MemorySegment data, @Nullable CompareDataFunc cmpFunc)

      Returns an iterator pointing to the position where data would be inserted according to cmpFunc and cmpData.

      cmpFunc is called with two items of the seq, and cmpData. It should return 0 if the items are equal, a negative value if the first item comes before the second, and a positive value if the second item comes before the first.

      If you are simply searching for an existing element of the sequence, consider using g_sequence_lookup().

      This function will fail if the data contained in the sequence is unsorted.

      Parameters:
      data - data for the new item
      cmpFunc - the function used to compare items in the sequence
      Returns:
      an GSequenceIter pointing to the position where data would have been inserted according to cmpFunc and cmpData
      Since:
      2.14
    • searchIter

      public SequenceIter searchIter(@Nullable MemorySegment data, @Nullable SequenceIterCompareFunc iterCmp)

      Like g_sequence_search(), but uses a GSequenceIterCompareFunc instead of a GCompareDataFunc as the compare function.

      iterCmp is called with two iterators pointing into seq. It should return 0 if the iterators are equal, a negative value if the first iterator comes before the second, and a positive value if the second iterator comes before the first.

      If you are simply searching for an existing element of the sequence, consider using g_sequence_lookup_iter().

      This function will fail if the data contained in the sequence is unsorted.

      Parameters:
      data - data for the new item
      iterCmp - the function used to compare iterators in the sequence
      Returns:
      a GSequenceIter pointing to the position in this Sequence where data would have been inserted according to iterCmp and cmpData
      Since:
      2.14
    • sort

      public void sort(@Nullable CompareDataFunc cmpFunc)

      Sorts this Sequence using cmpFunc.

      cmpFunc is passed two items of this Sequence and should return 0 if they are equal, a negative value if the first comes before the second, and a positive value if the second comes before the first.

      Parameters:
      cmpFunc - the function used to sort the sequence
      Since:
      2.14
    • sortIter

      public void sortIter(@Nullable SequenceIterCompareFunc cmpFunc)

      Like g_sequence_sort(), but uses a GSequenceIterCompareFunc instead of a GCompareDataFunc as the compare function

      cmpFunc is called with two iterators pointing into seq. It should return 0 if the iterators are equal, a negative value if the first iterator comes before the second, and a positive value if the second iterator comes before the first.

      Parameters:
      cmpFunc - the function used to compare iterators in the sequence
      Since:
      2.14