Class Sequence
- All Implemented Interfaces:
Proxy
GSequence
struct is an opaque data type representing a
[sequence][glib-Sequences] data type.-
Constructor Summary
ConstructorDescriptionSequence
(MemorySegment address) Create a Sequence proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionappend
(@Nullable MemorySegment data) Adds a new item to the end of this Sequence.void
Callsfunc
for each item in the sequence passinguserData
to the function.static void
foreachRange
(SequenceIter begin, SequenceIter end, Func func) Callsfunc
for each item in the range (begin
,end
) passinguserData
to the function.void
free()
Frees the memory allocated for this Sequence.static MemorySegment
get
(SequenceIter iter) Returns the data thatiter
points to.Returns the begin iterator for this Sequence.Returns the end iterator forseg
getIterAtPos
(int pos) Returns the iterator at positionpos
.int
Returns the positive length (>= 0) of this Sequence.static SequenceIter
insertBefore
(SequenceIter iter, @Nullable MemorySegment data) Inserts a new item just before the item pointed to byiter
.insertSorted
(@Nullable MemorySegment data, CompareDataFunc cmpFunc) Insertsdata
into this Sequence usingcmpFunc
to determine the new position.insertSortedIter
(@Nullable MemorySegment data, SequenceIterCompareFunc iterCmp) Like g_sequence_insert_sorted(), but uses aGSequenceIterCompareFunc
instead of aGCompareDataFunc
as the compare function.boolean
isEmpty()
Returnstrue
if the sequence contains zero items.lookup
(@Nullable MemorySegment data, CompareDataFunc cmpFunc) Returns an iterator pointing to the position of the first item found equal todata
according tocmpFunc
andcmpData
.lookupIter
(@Nullable MemorySegment data, SequenceIterCompareFunc iterCmp) Like g_sequence_lookup(), but uses aGSequenceIterCompareFunc
instead of aGCompareDataFunc
as the compare function.static void
move
(SequenceIter src, SequenceIter dest) Moves the item pointed to bysrc
to the position indicated bydest
.static void
moveRange
(SequenceIter dest, SequenceIter begin, SequenceIter end) Inserts the (begin
,end
) range at the destination pointed to bydest
.static Sequence
new_()
Creates a new GSequence.prepend
(@Nullable MemorySegment data) Adds a new item to the front of this Sequencestatic SequenceIter
rangeGetMidpoint
(SequenceIter begin, SequenceIter end) Finds an iterator somewhere in the range (begin
,end
).static void
remove
(SequenceIter iter) Removes the item pointed to byiter
.static void
removeRange
(SequenceIter begin, SequenceIter end) Removes all items in the (begin
,end
) range.search
(@Nullable MemorySegment data, CompareDataFunc cmpFunc) Returns an iterator pointing to the position wheredata
would be inserted according tocmpFunc
andcmpData
.searchIter
(@Nullable MemorySegment data, SequenceIterCompareFunc iterCmp) Like g_sequence_search(), but uses aGSequenceIterCompareFunc
instead of aGCompareDataFunc
as the compare function.static void
set
(SequenceIter iter, @Nullable MemorySegment data) Changes the data for the item pointed to byiter
to bedata
.void
sort
(CompareDataFunc cmpFunc) Sorts this Sequence usingcmpFunc
.static void
sortChanged
(SequenceIter iter, CompareDataFunc cmpFunc) Moves the data pointed to byiter
to a new position as indicated bycmpFunc
.static void
sortChangedIter
(SequenceIter iter, SequenceIterCompareFunc iterCmp) Like g_sequence_sort_changed(), but uses aGSequenceIterCompareFunc
instead of aGCompareDataFunc
as the compare function.void
sortIter
(SequenceIterCompareFunc cmpFunc) Like g_sequence_sort(), but uses aGSequenceIterCompareFunc
instead of aGCompareDataFunc
as the compare functionstatic void
swap
(SequenceIter a, SequenceIter b) Swaps the items pointed to bya
andb
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Sequence
Create a Sequence proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
foreachRange
Callsfunc
for each item in the range (begin
,end
) passinguserData
to the function.func
must not modify the sequence itself.- Parameters:
begin
- aGSequenceIter
end
- aGSequenceIter
func
- aGFunc
-
get
Returns the data thatiter
points to.- Parameters:
iter
- aGSequenceIter
- Returns:
- the data that
iter
points to
-
insertBefore
Inserts a new item just before the item pointed to byiter
.- Parameters:
iter
- aGSequenceIter
data
- the data for the new item- Returns:
- an iterator pointing to the new item
-
move
Moves the item pointed to bysrc
to the position indicated bydest
. After calling this functiondest
will point to the position immediately aftersrc
. It is allowed forsrc
anddest
to point into different sequences.- Parameters:
src
- aGSequenceIter
pointing to the item to movedest
- aGSequenceIter
pointing to the position to which the item is moved
-
moveRange
Inserts the (begin
,end
) range at the destination pointed to bydest
. Thebegin
andend
iters must point into the same sequence. It is allowed fordest
to point to a different sequence than the one pointed into bybegin
andend
.If
dest
isnull
, the range indicated bybegin
andend
is removed from the sequence. Ifdest
points to a place within the (begin
,end
) range, the range does not move.- Parameters:
dest
- aGSequenceIter
begin
- aGSequenceIter
end
- aGSequenceIter
-
new_
Creates a new GSequence. ThedataDestroy
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
-
rangeGetMidpoint
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
andend
iterators must both point to the same sequence andbegin
must come before or be equal toend
in the sequence.- Parameters:
begin
- aGSequenceIter
end
- aGSequenceIter
- Returns:
- a
GSequenceIter
pointing somewhere in the (begin
,end
) range
-
remove
Removes the item pointed to byiter
. 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
- aGSequenceIter
-
removeRange
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
- aGSequenceIter
end
- aGSequenceIter
-
set
Changes the data for the item pointed to byiter
to bedata
. If the sequence has a data destroy function associated with it, that function is called on the existing data thatiter
pointed to.- Parameters:
iter
- aGSequenceIter
data
- new data for the item
-
sortChanged
Moves the data pointed to byiter
to a new position as indicated bycmpFunc
. This function should be called for items in a sequence already sorted according tocmpFunc
whenever some aspect of an item changes so thatcmpFunc
may return different values for that item.cmpFunc
is called with two items of theseq
, andcmpData
. 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
- AGSequenceIter
cmpFunc
- the function used to compare items in the sequence
-
sortChangedIter
Like g_sequence_sort_changed(), but uses aGSequenceIterCompareFunc
instead of aGCompareDataFunc
as the compare function.iterCmp
is called with two iterators pointing into theGSequence
thatiter
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
- aGSequenceIter
iterCmp
- the function used to compare iterators in the sequence
-
swap
Swaps the items pointed to bya
andb
. It is allowed fora
andb
to point into difference sequences.- Parameters:
a
- aGSequenceIter
b
- aGSequenceIter
-
append
Adds a new item to the end of this Sequence.- Parameters:
data
- the data for the new item- Returns:
- an iterator pointing to the new item
-
foreach
Callsfunc
for each item in the sequence passinguserData
to the function.func
must not modify the sequence itself.- Parameters:
func
- the function to call for each item in this Sequence
-
free
public void free()Frees the memory allocated for this Sequence. If this Sequence has a data destroy function associated with it, that function is called on all items in this Sequence. -
getBeginIter
Returns the begin iterator for this Sequence.- Returns:
- the begin iterator for this Sequence.
-
getEndIter
Returns the end iterator forseg
- Returns:
- the end iterator for this Sequence
-
getIterAtPos
Returns the iterator at positionpos
. Ifpos
is negative or larger than the number of items in this Sequence, the end iterator is returned.- Parameters:
pos
- a position in this Sequence, or -1 for the end- Returns:
- The
GSequenceIter
at positionpos
-
getLength
public int getLength()Returns the positive length (>= 0) of this Sequence. 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
-
insertSorted
Insertsdata
into this Sequence usingcmpFunc
to determine the new position. The sequence must already be sorted according tocmpFunc
; otherwise the new position ofdata
is undefined.cmpFunc
is called with two items of the this Sequence, andcmpData
. 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 insertcmpFunc
- the function used to compare items in the sequence- Returns:
- a
GSequenceIter
pointing to the new item.
-
insertSortedIter
public SequenceIter insertSortedIter(@Nullable @Nullable MemorySegment data, SequenceIterCompareFunc iterCmp) Like g_sequence_insert_sorted(), but uses aGSequenceIterCompareFunc
instead of aGCompareDataFunc
as the compare function.iterCmp
is called with two iterators pointing into this Sequence. 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 itemiterCmp
- the function used to compare iterators in the sequence- Returns:
- a
GSequenceIter
pointing to the new item
-
isEmpty
public boolean isEmpty()Returnstrue
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, otherwisefalse
.
-
lookup
Returns an iterator pointing to the position of the first item found equal todata
according tocmpFunc
andcmpData
. 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 this Sequence, andcmpData
. 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 upcmpFunc
- the function used to compare items in the sequence- Returns:
- an
GSequenceIter
pointing to the position of the first item found equal todata
according tocmpFunc
andcmpData
, ornull
if no such item exists
-
lookupIter
public SequenceIter lookupIter(@Nullable @Nullable MemorySegment data, SequenceIterCompareFunc iterCmp) Like g_sequence_lookup(), but uses aGSequenceIterCompareFunc
instead of aGCompareDataFunc
as the compare function.iterCmp
is called with two iterators pointing into this Sequence. 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 upiterCmp
- the function used to compare iterators in the sequence- Returns:
- an
GSequenceIter
pointing to the position of the first item found equal todata
according toiterCmp
andcmpData
, ornull
if no such item exists
-
prepend
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
-
search
Returns an iterator pointing to the position wheredata
would be inserted according tocmpFunc
andcmpData
.cmpFunc
is called with two items of the this Sequence, andcmpData
. 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 itemcmpFunc
- the function used to compare items in the sequence- Returns:
- an
GSequenceIter
pointing to the position wheredata
would have been inserted according tocmpFunc
andcmpData
-
searchIter
public SequenceIter searchIter(@Nullable @Nullable MemorySegment data, SequenceIterCompareFunc iterCmp) Like g_sequence_search(), but uses aGSequenceIterCompareFunc
instead of aGCompareDataFunc
as the compare function.iterCmp
is called with two iterators pointing into this Sequence. 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 itemiterCmp
- the function used to compare iterators in the sequence- Returns:
- a
GSequenceIter
pointing to the position in this Sequence wheredata
would have been inserted according toiterCmp
andcmpData
-
sort
Sorts this Sequence usingcmpFunc
.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
-
sortIter
Like g_sequence_sort(), but uses aGSequenceIterCompareFunc
instead of aGCompareDataFunc
as the compare functioncmpFunc
is called with two iterators pointing into this Sequence. 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
-