Class QueueArray
- All Implemented Interfaces:
Proxy
GstQueueArray
is an object that provides standard queue functionality
based on an array instead of linked lists. This reduces the overhead
caused by memory management by a large factor.-
Constructor Summary
ConstructorDescriptionQueueArray
(MemorySegment address) Create a QueueArray proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears queue this QueueArray and frees all memory associated to it.dropElement
(int idx) Drops the queue element at positionidx
from queue this QueueArray.boolean
dropStruct
(int idx, @Nullable MemorySegment pStruct) Drops the queue element at positionidx
from queue this QueueArray and copies the data of the element or structure that was removed intopStruct
ifpStruct
is set (not NULL).int
find
(@Nullable CompareFunc func) Finds an element in the queue this QueueArray, either by comparing every element withfunc
or by looking updata
if no compare functionfunc
is provided, and returning the index of the found element.void
free()
Frees queue this QueueArray and all memory associated to it.int
Returns the length of the queue this QueueArrayboolean
isEmpty()
Checks if the queue this QueueArray is empty.static QueueArray
new_
(int initialSize) Allocates a newGstQueueArray
object with an initial queue size ofinitialSize
.static QueueArray
newForStruct
(long structSize, int initialSize) Allocates a newGstQueueArray
object for elements (e.g.peekHead()
Returns the head of the queue this QueueArray and does not remove it from the queue.Returns the head of the queue this QueueArray without removing it from the queue.peekNth
(int idx) Returns the item atidx
in this QueueArray, but does not remove it from the queue.peekNthStruct
(int idx) Returns the item atidx
in this QueueArray, but does not remove it from the queue.peekTail()
Returns the tail of the queue this QueueArray, but does not remove it from the queue.Returns the tail of the queue this QueueArray, but does not remove it from the queue.popHead()
Returns and head of the queue this QueueArray and removes it from the queue.Returns the head of the queue this QueueArray and removes it from the queue.popTail()
Returns the tail of the queue this QueueArray and removes it from the queue.Returns the tail of the queue this QueueArray and removes it from the queue.void
pushSorted
(@Nullable MemorySegment data, CompareDataFunc func) Pushesdata
to the queue this QueueArray, finding the correct position by comparingdata
with each array element usingfunc
.void
pushSortedStruct
(@Nullable MemorySegment pStruct, CompareDataFunc func) Pushes the element at addresspStruct
into the queue this QueueArray (copying the contents of a structure of the struct_size specified when creating the queue into the array), finding the correct position by comparing the element atpStruct
with each element in the array usingfunc
.void
pushTail
(@Nullable MemorySegment data) Pushesdata
to the tail of the queue this QueueArray.void
pushTailStruct
(@Nullable MemorySegment pStruct) void
Sets a function to clear an element of this QueueArray.void
sort
(CompareDataFunc compareFunc) Sorts the queue this QueueArray by comparing elements against each other using the providedcompareFunc
.Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
QueueArray
Create a QueueArray proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
Method Details
-
new_
Allocates a newGstQueueArray
object with an initial queue size ofinitialSize
.- Parameters:
initialSize
- Initial size of the new queue- Returns:
- a new
GstQueueArray
object
-
newForStruct
Allocates a newGstQueueArray
object for elements (e.g. structures) of sizestructSize
, with an initial queue size ofinitialSize
.- Parameters:
structSize
- Size of each element (e.g. structure) in the arrayinitialSize
- Initial size of the new queue- Returns:
- a new
GstQueueArray
object
-
clear
public void clear()Clears queue this QueueArray and frees all memory associated to it. -
dropElement
Drops the queue element at positionidx
from queue this QueueArray.- Parameters:
idx
- index to drop- Returns:
- the dropped element
-
dropStruct
Drops the queue element at positionidx
from queue this QueueArray and copies the data of the element or structure that was removed intopStruct
ifpStruct
is set (not NULL).- Parameters:
idx
- index to droppStruct
- address into which to store the data of the dropped structure, or NULL- Returns:
- TRUE on success, or FALSE on error
-
find
Finds an element in the queue this QueueArray, either by comparing every element withfunc
or by looking updata
if no compare functionfunc
is provided, and returning the index of the found element.- Parameters:
func
- comparison function, ornull
to finddata
by value- Returns:
- Index of the found element or -1 if nothing was found.
-
free
public void free()Frees queue this QueueArray and all memory associated to it. -
getLength
public int getLength()Returns the length of the queue this QueueArray- Returns:
- the length of the queue this QueueArray.
-
isEmpty
public boolean isEmpty()Checks if the queue this QueueArray is empty.- Returns:
true
if the queue this QueueArray is empty
-
peekHead
Returns the head of the queue this QueueArray and does not remove it from the queue.- Returns:
- The head of the queue
-
peekHeadStruct
Returns the head of the queue this QueueArray without removing it from the queue.- Returns:
- pointer to element or struct, or NULL if this QueueArray was empty. The data pointed to by the returned pointer stays valid only as long as the queue array is not modified further!
-
peekNth
Returns the item atidx
in this QueueArray, but does not remove it from the queue.- Returns:
- The item, or
null
ifidx
was out of bounds
-
peekNthStruct
Returns the item atidx
in this QueueArray, but does not remove it from the queue.- Returns:
- The item, or
null
ifidx
was out of bounds
-
peekTail
Returns the tail of the queue this QueueArray, but does not remove it from the queue.- Returns:
- The tail of the queue
-
peekTailStruct
Returns the tail of the queue this QueueArray, but does not remove it from the queue.- Returns:
- The tail of the queue
-
popHead
Returns and head of the queue this QueueArray and removes it from the queue.- Returns:
- The head of the queue
-
popHeadStruct
Returns the head of the queue this QueueArray and removes it from the queue.- Returns:
- pointer to element or struct, or NULL if this QueueArray was empty. The data pointed to by the returned pointer stays valid only as long as the queue array is not modified further!
-
popTail
Returns the tail of the queue this QueueArray and removes it from the queue.- Returns:
- The tail of the queue
-
popTailStruct
Returns the tail of the queue this QueueArray and removes it from the queue.- Returns:
- The tail of the queue
-
pushSorted
Pushesdata
to the queue this QueueArray, finding the correct position by comparingdata
with each array element usingfunc
.This has a time complexity of O(n), so depending on the size of the queue and expected access patterns, a different data structure might be better.
Assumes that the array is already sorted. If it is not, make sure to call gst_queue_array_sort() first.
- Parameters:
data
- object to pushfunc
- comparison function
-
pushSortedStruct
Pushes the element at addresspStruct
into the queue this QueueArray (copying the contents of a structure of the struct_size specified when creating the queue into the array), finding the correct position by comparing the element atpStruct
with each element in the array usingfunc
.This has a time complexity of O(n), so depending on the size of the queue and expected access patterns, a different data structure might be better.
Assumes that the array is already sorted. If it is not, make sure to call gst_queue_array_sort() first.
- Parameters:
pStruct
- address of element or structure to push into the queuefunc
- comparison function
-
pushTail
Pushesdata
to the tail of the queue this QueueArray.- Parameters:
data
- object to push
-
pushTailStruct
-
setClearFunc
public void setClearFunc()Sets a function to clear an element of this QueueArray.The
clearFunc
will be called when an element in the array data segment is removed and when the array is freed and data segment is deallocated as well.clearFunc
will be passed a pointer to the element to clear, rather than the element itself.Note that in contrast with other uses of
GDestroyNotify
functions,clearFunc
is expected to clear the contents of the array element it is given, but not free the element itself. -
sort
Sorts the queue this QueueArray by comparing elements against each other using the providedcompareFunc
.- Parameters:
compareFunc
- comparison function
-