GLib.Queue

Fields

Name

Type

Access

Description

head

[object]

r/w

a pointer to the first element of the queue

length

int

r/w

the number of elements in the queue

tail

[object]

r/w

a pointer to the last element of the queue

Methods

clear ()

clear_full (free_func)

free ()

free_full (free_func)

get_length ()

index (data)

init ()

is_empty ()

peek_head ()

peek_nth (n)

peek_tail ()

pop_head ()

pop_nth (n)

pop_tail ()

push_head (data)

push_nth (data, n)

push_tail (data)

remove (data)

remove_all (data)

reverse ()

Details

class GLib.Queue

Contains the public fields of a Queue.

clear()[source]

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

New in version 2.14.

clear_full(free_func)[source]
Parameters:

free_func (GLib.DestroyNotify or None) – the function to be called to free memory allocated

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

New in version 2.60.

free()[source]

Frees the memory allocated for the GLib.Queue. Only call this function if self 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 GLib.Queue.free_full() or free them manually first.

free_full(free_func)[source]
Parameters:

free_func (GLib.DestroyNotify) – the function to be called to free each element’s data

Convenience method, which frees all the memory used by a 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).

New in version 2.32.

get_length()[source]
Returns:

the number of items in self

Return type:

int

Returns the number of items in self.

New in version 2.4.

index(data)[source]
Parameters:

data (object or None) – the data to find

Returns:

the position of the first element in self which contains data, or -1 if no element in self contains data

Return type:

int

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

New in version 2.4.

init()[source]

A statically-allocated 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 g_queue_new().

New in version 2.14.

is_empty()[source]
Returns:

True if the queue is empty

Return type:

bool

Returns True if the queue is empty.

peek_head()[source]
Returns:

the data of the first element in the queue, or None if the queue is empty

Return type:

object or None

Returns the first element of the queue.

peek_nth(n)[source]
Parameters:

n (int) – the position of the element

Returns:

the data for the n'th element of self, or None if n is off the end of self

Return type:

object or None

Returns the n'th element of self.

New in version 2.4.

peek_tail()[source]
Returns:

the data of the last element in the queue, or None if the queue is empty

Return type:

object or None

Returns the last element of the queue.

pop_head()[source]
Returns:

the data of the first element in the queue, or None if the queue is empty

Return type:

object or None

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

pop_nth(n)[source]
Parameters:

n (int) – the position of the element

Returns:

the element’s data, or None if n is off the end of self

Return type:

object or None

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

New in version 2.4.

pop_tail()[source]
Returns:

the data of the last element in the queue, or None if the queue is empty

Return type:

object or None

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

push_head(data)[source]
Parameters:

data (object or None) – the data for the new element.

Adds a new element at the head of the queue.

push_nth(data, n)[source]
Parameters:
  • data (object or None) – the data for the new element

  • n (int) – the position to insert the new element. If n is negative or larger than the number of elements in the self, the element is added to the end of the queue.

Inserts a new element into self at the given position.

New in version 2.4.

push_tail(data)[source]
Parameters:

data (object or None) – the data for the new element

Adds a new element at the tail of the queue.

remove(data)[source]
Parameters:

data (object or None) – the data to remove

Returns:

True if data was found and removed from self

Return type:

bool

Removes the first element in self that contains data.

New in version 2.4.

remove_all(data)[source]
Parameters:

data (object or None) – the data to remove

Returns:

the number of elements removed from self

Return type:

int

Remove all elements whose data equals data from self.

New in version 2.4.

reverse()[source]

Reverses the order of the items in self.

New in version 2.4.