Queue#
- class Queue(*args, **kwargs)#
Contains the public fields of a [Queue][glib-Double-ended-Queues].
Methods#
- class Queue
- clear() None#
Removes all the elements in
queue. If queue elements contain dynamically-allocated memory, they should be freed first.Added in version 2.14.
- clear_full(free_func: Callable[[Any], None] | None = None) None#
Convenience method, which frees all the memory used by a
Queue, and calls the providedfree_funcon each item in theQueue.Added in version 2.60.
- Parameters:
free_func – the function to be called to free memory allocated
- foreach(func: Callable[[Any, Any], None], user_data: Any = None) None#
Calls
funcfor each element in the queue passinguser_datato the function.It is safe for
functo remove the element fromqueue, but it must not modify any part of the queue after that element.Added in version 2.4.
- Parameters:
func – the function to call for each element’s data
user_data – user data to pass to
func
- free() None#
Frees the memory allocated for the
Queue. Only call this function ifqueuewas created withnew(). If queue elements contain dynamically-allocated memory, they should be freed first.If queue elements contain dynamically-allocated memory, you should either use
free_full()or free them manually first.
- free_full(free_func: Callable[[Any], None]) None#
Convenience method, which frees all the memory used by a
Queue, and calls the specified destroy function on every element’s data.free_funcshould not modify the queue (eg, by removing the freed element from it).Added in version 2.32.
- Parameters:
free_func – the function to be called to free each element’s data
- index(data: Any = None) int#
Returns the position of the first element in
queuewhich containsdata.Added in version 2.4.
- Parameters:
data – the data to find
- init() None#
A statically-allocated
Queuemust be initialized with this function before it can be used. Alternatively you can initialize it with %G_QUEUE_INIT. It is not necessary to initialize queues created withnew().Added in version 2.14.
- insert_sorted(data: Any, func: Callable[[Any, Any, Any], int], user_data: Any = None) None#
Inserts
dataintoqueueusingfuncto determine the new position.Added in version 2.4.
- Parameters:
data – the data to insert
func – the
CompareDataFuncused to compare elements in the queue. It is called with two elements of thequeueanduser_data. It should return 0 if the elements are equal, a negative value if the first element comes before the second, and a positive value if the second element comes before the first.user_data – user data passed to
func
- peek_nth(n: int) Any | None#
Returns the
n'th element ofqueue.Added in version 2.4.
- Parameters:
n – the position of the element
- pop_nth(n: int) Any | None#
Removes the
n'th element ofqueueand returns its data.Added in version 2.4.
- Parameters:
n – the position of the element
- push_head(data: Any = None) None#
Adds a new element at the head of the queue.
- Parameters:
data – the data for the new element.
- push_nth(data: Any, n: int) None#
Inserts a new element into
queueat the given position.Added in version 2.4.
- Parameters:
data – the data for the new element
n – the position to insert the new element. If
nis negative or larger than the number of elements in thequeue, the element is added to the end of the queue.
- push_tail(data: Any = None) None#
Adds a new element at the tail of the queue.
- Parameters:
data – the data for the new element
- remove(data: Any = None) bool#
Removes the first element in
queuethat containsdata.Added in version 2.4.
- Parameters:
data – the data to remove
- Returns:
0 if the file was successfully removed, -1 if an error occurred
- remove_all(data: Any = None) int#
Remove all elements whose data equals
datafromqueue.Added in version 2.4.
- Parameters:
data – the data to remove
- sort(compare_func: Callable[[Any, Any, Any], int], user_data: Any = None) None#
Sorts
queueusingcompare_func.Added in version 2.4.
- Parameters:
compare_func – the
CompareDataFuncused to sortqueue. This function is passed two elements of the queue 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.user_data – user data passed to
compare_func