Class VecDeque
- All Implemented Interfaces:
Proxy
GstVecDeque is an object that provides standard double-ended queue (deque)
functionality based on an array instead of linked lists. This reduces the
overhead caused by memory management by a large factor.- Since:
- 1.26
-
Constructor Summary
ConstructorsConstructorDescriptionVecDeque(MemorySegment address) Create a VecDeque proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears queue this VecDeque and frees all memory associated to it.@Nullable MemorySegmentdropElement(long idx) Drops the queue element at positionidxfrom queuearray.booleandropStruct(long idx, @Nullable MemorySegment pStruct) Drops the queue element at positionidxfrom queue this VecDeque and copies the data of the element or structure that was removed intopStructifpStructis set (not NULL).longfind(@Nullable CompareFunc func) Finds an element in the queuearray,either by comparing every element withfuncor by looking updataif no compare functionfuncis provided, and returning the index of the found element.voidfree()Frees queue this VecDeque and all memory associated to it.longReturns the length of the queue this VecDequebooleanisEmpty()Checks if the queue this VecDeque is empty.static VecDequenew_(long initialSize) Allocates a newGstVecDequeobject with an initial queue size ofinitialSize.static VecDequenewForStruct(long structSize, long initialSize) Allocates a newGstVecDequeobject for elements (e.g.@Nullable MemorySegmentpeekHead()Returns the head of the queue this VecDeque and does not remove it from the queue.@Nullable MemorySegmentReturns the head of the queue this VecDeque without removing it from the queue.@Nullable MemorySegmentpeekNth(long idx) Returns the item atidxinarray,but does not remove it from the queue.@Nullable MemorySegmentpeekNthStruct(long idx) Returns the item atidxinarray,but does not remove it from the queue.@Nullable MemorySegmentpeekTail()Returns the tail of the queuearray,but does not remove it from the queue.@Nullable MemorySegmentReturns the tail of the queuearray,but does not remove it from the queue.@Nullable MemorySegmentpopHead()Returns and head of the queue this VecDeque and removes it from the queue.@Nullable MemorySegmentReturns the head of the queue this VecDeque and removes it from the queue.@Nullable MemorySegmentpopTail()Returns the tail of the queue this VecDeque and removes it from the queue.@Nullable MemorySegmentReturns the tail of the queue this VecDeque and removes it from the queue.voidpushSorted(@Nullable MemorySegment data, @Nullable CompareDataFunc func) Pushesdatato the queuearray,finding the correct position by comparingdatawith each array element usingfunc.voidpushSortedStruct(@Nullable MemorySegment pStruct, @Nullable CompareDataFunc func) Pushes the element at addresspStructinto the queue this VecDeque (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 atpStructwith each element in the array usingfunc.voidpushTail(@Nullable MemorySegment data) Pushesdatato the tail of the queuearray.voidpushTailStruct(@Nullable MemorySegment pStruct) Pushes the element at addresspStructto the tail of the queue this VecDeque (Copies the contents of a structure of the struct_size specified when creating the queue into the array).voidSets a function to clear an element ofarray.voidsort(@Nullable CompareDataFunc compareFunc) Sorts the queue this VecDeque by comparing elements against each other using the providedcompareFunc.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
VecDeque
Create a VecDeque proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
-
Method Details
-
new_
Allocates a newGstVecDequeobject with an initial queue size ofinitialSize.- Parameters:
initialSize- Initial size of the new queue- Returns:
- a new
GstVecDequeobject - Since:
- 1.26
-
newForStruct
Allocates a newGstVecDequeobject 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
GstVecDequeobject - Since:
- 1.26
-
clear
public void clear()Clears queue this VecDeque and frees all memory associated to it.- Since:
- 1.26
-
dropElement
Drops the queue element at positionidxfrom queuearray.- Parameters:
idx- index to drop- Returns:
- the dropped element
- Since:
- 1.26
-
dropStruct
Drops the queue element at positionidxfrom queue this VecDeque and copies the data of the element or structure that was removed intopStructifpStructis 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
- Since:
- 1.26
-
find
Finds an element in the queuearray,either by comparing every element withfuncor by looking updataif no compare functionfuncis provided, and returning the index of the found element.- Parameters:
func- comparison function, ornullto finddataby value- Returns:
- Index of the found element or -1 if nothing was found.
- Since:
- 1.26
-
free
public void free()Frees queue this VecDeque and all memory associated to it.- Since:
- 1.26
-
getLength
public long getLength()Returns the length of the queue this VecDeque- Returns:
- the length of the queue
array. - Since:
- 1.26
-
isEmpty
public boolean isEmpty()Checks if the queue this VecDeque is empty.- Returns:
trueif the queue this VecDeque is empty- Since:
- 1.26
-
peekHead
Returns the head of the queue this VecDeque and does not remove it from the queue.- Returns:
- The head of the queue
- Since:
- 1.26
-
peekHeadStruct
Returns the head of the queue this VecDeque without removing it from the queue.- Returns:
- pointer to element or struct, or NULL if this VecDeque was empty. The data pointed to by the returned pointer stays valid only as long as the queue array is not modified further!
- Since:
- 1.26
-
peekNth
Returns the item atidxinarray,but does not remove it from the queue.- Returns:
- The item, or
nullifidxwas out of bounds - Since:
- 1.26
-
peekNthStruct
Returns the item atidxinarray,but does not remove it from the queue.- Returns:
- The item, or
nullifidxwas out of bounds - Since:
- 1.26
-
peekTail
Returns the tail of the queuearray,but does not remove it from the queue.- Returns:
- The tail of the queue
- Since:
- 1.26
-
peekTailStruct
Returns the tail of the queuearray,but does not remove it from the queue.- Returns:
- The tail of the queue
- Since:
- 1.26
-
popHead
Returns and head of the queue this VecDeque and removes it from the queue.- Returns:
- The head of the queue
- Since:
- 1.26
-
popHeadStruct
Returns the head of the queue this VecDeque and removes it from the queue.- Returns:
- pointer to element or struct, or NULL if this VecDeque was empty. The data pointed to by the returned pointer stays valid only as long as the queue array is not modified further!
- Since:
- 1.26
-
popTail
Returns the tail of the queue this VecDeque and removes it from the queue.- Returns:
- The tail of the queue
- Since:
- 1.26
-
popTailStruct
Returns the tail of the queue this VecDeque and removes it from the queue.- Returns:
- The tail of the queue
- Since:
- 1.26
-
pushSorted
Pushesdatato the queuearray,finding the correct position by comparingdatawith 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_vec_deque_sort() first.
- Parameters:
data- object to pushfunc- comparison function- Since:
- 1.26
-
pushSortedStruct
Pushes the element at addresspStructinto the queue this VecDeque (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 atpStructwith 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_vec_deque_sort() first.
- Parameters:
pStruct- address of element or structure to push into the queuefunc- comparison function- Since:
- 1.26
-
pushTail
Pushesdatato the tail of the queuearray.- Parameters:
data- object to push- Since:
- 1.26
-
pushTailStruct
Pushes the element at addresspStructto the tail of the queue this VecDeque (Copies the contents of a structure of the struct_size specified when creating the queue into the array).- Parameters:
pStruct- address of element or structure to push to the tail of the queue- Since:
- 1.26
-
setClearFunc
public void setClearFunc()Sets a function to clear an element ofarray.The
clearFuncwill 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.clearFuncwill be passed a pointer to the element to clear, rather than the element itself.Note that in contrast with other uses of
GDestroyNotifyfunctions,clearFuncis expected to clear the contents of the array element it is given, but not free the element itself.- Since:
- 1.26
-
sort
Sorts the queue this VecDeque by comparing elements against each other using the providedcompareFunc.- Parameters:
compareFunc- comparison function- Since:
- 1.26
-