Skip to content

GLib.Queue

record (struct)

Contains the public fields of a Queue.

Methods

clear

def clear(self) -> None

Removes all the elements in queue. If queue elements contain dynamically-allocated memory, they should be freed first.

clear_full

def clear_full(self, free_func: DestroyNotify | None = ...) -> None

Convenience method, which frees all the memory used by a Queue, and calls the provided free_func on each item in the Queue.

Parameters:

  • free_func — the function to be called to free memory allocated

foreach

def foreach(self, func: Func) -> 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.

Parameters:

  • func — the function to call for each element's data

free

def free(self) -> None

Frees the memory allocated for the Queue. Only call this function if queue was created with g_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 Queue.free_full or free them manually first.

free_full

def free_full(self, free_func: DestroyNotify) -> 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).

Parameters:

  • free_func — the function to be called to free each element's data

get_length

def get_length(self) -> int

Returns the number of items in queue.

index

def index(self, data: int | None = ...) -> int

Returns the position of the first element in queue which contains data.

Parameters:

  • data — the data to find

init

def init(self) -> 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 with g_queue_new().

insert_sorted

def insert_sorted(self, data: int | None, func: CompareDataFunc) -> None

Inserts data into queue using func to determine the new position.

Parameters:

  • data — the data to insert
  • func — the GCompareDataFunc 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.

is_empty

def is_empty(self) -> bool

Returns True if the queue is empty.

peek_head

def peek_head(self) -> int | None

Returns the first element of the queue.

peek_nth

def peek_nth(self, n: int) -> int | None

Returns the n'th element of queue.

Parameters:

  • n — the position of the element

peek_tail

def peek_tail(self) -> int | None

Returns the last element of the queue.

pop_head

def pop_head(self) -> int | None

Removes the first element of the queue and returns its data.

pop_nth

def pop_nth(self, n: int) -> int | None

Removes the n'th element of queue and returns its data.

Parameters:

  • n — the position of the element

pop_tail

def pop_tail(self) -> int | None

Removes the last element of the queue and returns its data.

push_head

def push_head(self, data: int | None = ...) -> None

Adds a new element at the head of the queue.

Parameters:

  • data — the data for the new element.

push_nth

def push_nth(self, data: int | None, n: int) -> None

Inserts a new element into queue at the given position.

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 the queue, the element is added to the end of the queue.

push_tail

def push_tail(self, data: int | None = ...) -> None

Adds a new element at the tail of the queue.

Parameters:

  • data — the data for the new element

remove

def remove(self, data: int | None = ...) -> bool

Removes the first element in queue that contains data.

Parameters:

  • data — the data to remove

remove_all

def remove_all(self, data: int | None = ...) -> int

Remove all elements whose data equals data from queue.

Parameters:

  • data — the data to remove

reverse

def reverse(self) -> None

Reverses the order of the items in queue.

sort

def sort(self, compare_func: CompareDataFunc) -> None

Sorts queue using compare_func.

Parameters:

  • compare_func — the GCompareDataFunc 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.

Properties

head

head: list[int]  # read/write

tail

tail: list[int]  # read/write

length

length: int  # read/write