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[[None], None] | None = None) None #
Convenience method, which frees all the memory used by a
Queue
, and calls the providedfree_func
on each item in theQueue
.Added in version 2.60.
- Parameters:
free_func – the function to be called to free memory allocated
- foreach(func: Callable[[...], None], *user_data: Any) None #
Calls
func
for each element in the queue passinguser_data
to the function.It is safe for
func
to 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 ifqueue
was 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[[None], 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_func
should 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: None) int #
Returns the position of the first element in
queue
which containsdata
.Added in version 2.4.
- Parameters:
data – the data to find
- init() None #
A statically-allocated
Queue
must 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: None, func: Callable[[...], int], *user_data: Any) None #
Inserts
data
intoqueue
usingfunc
to determine the new position.Added in version 2.4.
- Parameters:
data – the data to insert
func – the
CompareDataFunc
used to compare elements in the queue. It is called with two elements of thequeue
anduser_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) None #
Returns the
n
’th element ofqueue
.Added in version 2.4.
- Parameters:
n – the position of the element
- pop_nth(n: int) None #
Removes the
n
’th element ofqueue
and returns its data.Added in version 2.4.
- Parameters:
n – the position of the element
- push_head(data: None) None #
Adds a new element at the head of the queue.
- Parameters:
data – the data for the new element.
- push_nth(data: None, n: int) None #
Inserts a new element into
queue
at 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
n
is negative or larger than the number of elements in thequeue
, the element is added to the end of the queue.
- push_tail(data: None) None #
Adds a new element at the tail of the queue.
- Parameters:
data – the data for the new element
- remove(data: None) bool #
Removes the first element in
queue
that 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: None) int #
Remove all elements whose data equals
data
fromqueue
.Added in version 2.4.
- Parameters:
data – the data to remove
- sort(compare_func: Callable[[...], int], *user_data: Any) None #
Sorts
queue
usingcompare_func
.Added in version 2.4.
- Parameters:
compare_func – the
CompareDataFunc
used 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