:right-sidebar: True Queue =================================================================== .. currentmodule:: gi.repository.GLib .. class:: Queue(*args, **kwargs) :no-contents-entry: Contains the public fields of a [Queue][glib-Double-ended-Queues]. Methods ------- .. rst-class:: interim-class .. class:: Queue :no-index: .. method:: clear() -> None Removes all the elements in ``queue``\. If queue elements contain dynamically-allocated memory, they should be freed first. .. versionadded:: 2.14 .. method:: clear_full(free_func: ~typing.Callable[[~typing.Any], None] | None = None) -> None Convenience method, which frees all the memory used by a :obj:`~gi.repository.GLib.Queue`\, and calls the provided ``free_func`` on each item in the :obj:`~gi.repository.GLib.Queue`\. .. versionadded:: 2.60 :param free_func: the function to be called to free memory allocated .. method:: foreach(func: ~typing.Callable[[~typing.Any, ~typing.Any], None], user_data: ~typing.Any = None) -> None Calls ``func`` for each element in the queue passing ``user_data`` to the function. It is safe for ``func`` to remove the element from ``queue``\, but it must not modify any part of the queue after that element. .. versionadded:: 2.4 :param func: the function to call for each element's data :param user_data: user data to pass to ``func`` .. method:: free() -> None Frees the memory allocated for the :obj:`~gi.repository.GLib.Queue`\. Only call this function if ``queue`` was created with :func:`~gi.repository.GLib.Queue.new`. If queue elements contain dynamically-allocated memory, they should be freed first. If queue elements contain dynamically-allocated memory, you should either use :func:`~gi.repository.GLib.Queue.free_full` or free them manually first. .. method:: free_full(free_func: ~typing.Callable[[~typing.Any], None]) -> None Convenience method, which frees all the memory used by a :obj:`~gi.repository.GLib.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). .. versionadded:: 2.32 :param free_func: the function to be called to free each element's data .. method:: get_length() -> int Returns the number of items in ``queue``\. .. versionadded:: 2.4 .. method:: index(data: ~typing.Any = None) -> int Returns the position of the first element in ``queue`` which contains ``data``\. .. versionadded:: 2.4 :param data: the data to find .. method:: init() -> None A statically-allocated :obj:`~gi.repository.GLib.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 with :func:`~gi.repository.GLib.Queue.new`. .. versionadded:: 2.14 .. method:: insert_sorted(data: ~typing.Any, func: ~typing.Callable[[~typing.Any, ~typing.Any, ~typing.Any], int], user_data: ~typing.Any = None) -> None Inserts ``data`` into ``queue`` using ``func`` to determine the new position. .. versionadded:: 2.4 :param data: the data to insert :param func: the :obj:`~gi.repository.GLib.CompareDataFunc` used to compare elements in the queue. It is called with two elements of the ``queue`` and ``user_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. :param user_data: user data passed to ``func`` .. method:: is_empty() -> bool Returns :const:`True` if the queue is empty. .. method:: peek_head() -> ~typing.Any | None Returns the first element of the queue. .. method:: peek_nth(n: int) -> ~typing.Any | None Returns the ``n``\'th element of ``queue``\. .. versionadded:: 2.4 :param n: the position of the element .. method:: peek_tail() -> ~typing.Any | None Returns the last element of the queue. .. method:: pop_head() -> ~typing.Any | None Removes the first element of the queue and returns its data. .. method:: pop_nth(n: int) -> ~typing.Any | None Removes the ``n``\'th element of ``queue`` and returns its data. .. versionadded:: 2.4 :param n: the position of the element .. method:: pop_tail() -> ~typing.Any | None Removes the last element of the queue and returns its data. .. method:: push_head(data: ~typing.Any = None) -> None Adds a new element at the head of the queue. :param data: the data for the new element. .. method:: push_nth(data: ~typing.Any, n: int) -> None Inserts a new element into ``queue`` at the given position. .. versionadded:: 2.4 :param data: the data for the new element :param n: the position to insert the new element. If ``n`` is negative or larger than the number of elements in the ``queue``\, the element is added to the end of the queue. .. method:: push_tail(data: ~typing.Any = None) -> None Adds a new element at the tail of the queue. :param data: the data for the new element .. method:: remove(data: ~typing.Any = None) -> bool Removes the first element in ``queue`` that contains ``data``\. .. versionadded:: 2.4 :param data: the data to remove :return: 0 if the file was successfully removed, -1 if an error occurred .. method:: remove_all(data: ~typing.Any = None) -> int Remove all elements whose data equals ``data`` from ``queue``\. .. versionadded:: 2.4 :param data: the data to remove .. method:: reverse() -> None Reverses the order of the items in ``queue``\. .. versionadded:: 2.4 .. method:: sort(compare_func: ~typing.Callable[[~typing.Any, ~typing.Any, ~typing.Any], int], user_data: ~typing.Any = None) -> None Sorts ``queue`` using ``compare_func``\. .. versionadded:: 2.4 :param compare_func: the :obj:`~gi.repository.GLib.CompareDataFunc` used to sort ``queue``\. 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. :param user_data: user data passed to ``compare_func`` Fields ------ .. rst-class:: interim-class .. class:: Queue :no-index: .. attribute:: head A pointer to the first element of the queue .. attribute:: length The number of elements in the queue .. attribute:: tail A pointer to the last element of the queue