GLib.Sequence

Fields

None

Methods

class

foreach_range (begin, end, func, *user_data)

class

get (iter)

class

insert_before (iter, data)

class

move (src, dest)

class

move_range (dest, begin, end)

class

range_get_midpoint (begin, end)

class

remove (iter)

class

remove_range (begin, end)

class

set (iter, data)

class

sort_changed (iter, cmp_func, *cmp_data)

class

sort_changed_iter (iter, iter_cmp, *cmp_data)

class

swap (a, b)

append (data)

foreach (func, *user_data)

free ()

get_begin_iter ()

get_end_iter ()

get_iter_at_pos (pos)

get_length ()

insert_sorted (data, cmp_func, *cmp_data)

insert_sorted_iter (data, iter_cmp, *cmp_data)

is_empty ()

lookup (data, cmp_func, *cmp_data)

lookup_iter (data, iter_cmp, *cmp_data)

prepend (data)

search (data, cmp_func, *cmp_data)

search_iter (data, iter_cmp, *cmp_data)

sort (cmp_func, *cmp_data)

sort_iter (cmp_func, *cmp_data)

Details

class GLib.Sequence

The GLib.Sequence struct is an opaque data type representing a sequence data type.

classmethod foreach_range(begin, end, func, *user_data)[source]
Parameters:

Calls func for each item in the range (begin, end) passing user_data to the function. func must not modify the sequence itself.

New in version 2.14.

classmethod get(iter)[source]
Parameters:

iter (GLib.SequenceIter) – a GLib.SequenceIter

Returns:

the data that iter points to

Return type:

object or None

Returns the data that iter points to.

New in version 2.14.

classmethod insert_before(iter, data)[source]
Parameters:
Returns:

an iterator pointing to the new item

Return type:

GLib.SequenceIter

Inserts a new item just before the item pointed to by iter.

New in version 2.14.

classmethod move(src, dest)[source]
Parameters:

Moves the item pointed to by src to the position indicated by dest. After calling this function dest will point to the position immediately after src. It is allowed for src and dest to point into different sequences.

New in version 2.14.

classmethod move_range(dest, begin, end)[source]
Parameters:

Inserts the (begin, end) range at the destination pointed to by dest. The begin and end iters must point into the same sequence. It is allowed for dest to point to a different sequence than the one pointed into by begin and end.

If dest is None, the range indicated by begin and end is removed from the sequence. If dest points to a place within the (begin, end) range, the range does not move.

New in version 2.14.

classmethod range_get_midpoint(begin, end)[source]
Parameters:
Returns:

a GLib.SequenceIter pointing somewhere in the (begin, end) range

Return type:

GLib.SequenceIter

Finds an iterator somewhere in the range (begin, end). This iterator will be close to the middle of the range, but is not guaranteed to be exactly in the middle.

The begin and end iterators must both point to the same sequence and begin must come before or be equal to end in the sequence.

New in version 2.14.

classmethod remove(iter)[source]
Parameters:

iter (GLib.SequenceIter) – a GLib.SequenceIter

Removes the item pointed to by iter. It is an error to pass the end iterator to this function.

If the sequence has a data destroy function associated with it, this function is called on the data for the removed item.

New in version 2.14.

classmethod remove_range(begin, end)[source]
Parameters:

Removes all items in the (begin, end) range.

If the sequence has a data destroy function associated with it, this function is called on the data for the removed items.

New in version 2.14.

classmethod set(iter, data)[source]
Parameters:

Changes the data for the item pointed to by iter to be data. If the sequence has a data destroy function associated with it, that function is called on the existing data that iter pointed to.

New in version 2.14.

classmethod sort_changed(iter, cmp_func, *cmp_data)[source]
Parameters:

Moves the data pointed to by iter to a new position as indicated by cmp_func. This function should be called for items in a sequence already sorted according to cmp_func whenever some aspect of an item changes so that cmp_func may return different values for that item.

cmp_func is called with two items of the seq, and cmp_data. It should return 0 if the items are equal, a negative value if the first item comes before the second, and a positive value if the second item comes before the first.

New in version 2.14.

classmethod sort_changed_iter(iter, iter_cmp, *cmp_data)[source]
Parameters:

Like GLib.Sequence.sort_changed(), but uses a GLib.SequenceIterCompareFunc instead of a GLib.CompareDataFunc as the compare function.

iter_cmp is called with two iterators pointing into the GLib.Sequence that iter points into. It should return 0 if the iterators are equal, a negative value if the first iterator comes before the second, and a positive value if the second iterator comes before the first.

New in version 2.14.

classmethod swap(a, b)[source]
Parameters:

Swaps the items pointed to by a and b. It is allowed for a and b to point into difference sequences.

New in version 2.14.

append(data)[source]
Parameters:

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

Returns:

an iterator pointing to the new item

Return type:

GLib.SequenceIter

Adds a new item to the end of self.

New in version 2.14.

foreach(func, *user_data)[source]
Parameters:
  • func (GLib.Func) – the function to call for each item in self

  • user_data (object or None) – user data passed to func

Calls func for each item in the sequence passing user_data to the function. func must not modify the sequence itself.

New in version 2.14.

free()[source]

Frees the memory allocated for self. If self has a data destroy function associated with it, that function is called on all items in self.

New in version 2.14.

get_begin_iter()[source]
Returns:

the begin iterator for self.

Return type:

GLib.SequenceIter

Returns the begin iterator for self.

New in version 2.14.

get_end_iter()[source]
Returns:

the end iterator for self

Return type:

GLib.SequenceIter

Returns the end iterator for seg

New in version 2.14.

get_iter_at_pos(pos)[source]
Parameters:

pos (int) – a position in self, or -1 for the end

Returns:

The GLib.SequenceIter at position pos

Return type:

GLib.SequenceIter

Returns the iterator at position pos. If pos is negative or larger than the number of items in self, the end iterator is returned.

New in version 2.14.

get_length()[source]
Returns:

the length of self

Return type:

int

Returns the positive length (>= 0) of self. Note that this method is O(h) where `h’ is the height of the tree. It is thus more efficient to use GLib.Sequence.is_empty() when comparing the length to zero.

New in version 2.14.

insert_sorted(data, cmp_func, *cmp_data)[source]
Parameters:
Returns:

a GLib.SequenceIter pointing to the new item.

Return type:

GLib.SequenceIter

Inserts data into self using cmp_func to determine the new position. The sequence must already be sorted according to cmp_func; otherwise the new position of data is undefined.

cmp_func is called with two items of the self, and cmp_data. It should return 0 if the items are equal, a negative value if the first item comes before the second, and a positive value if the second item comes before the first.

Note that when adding a large amount of data to a GLib.Sequence, it is more efficient to do unsorted insertions and then call GLib.Sequence.sort() or GLib.Sequence.sort_iter().

New in version 2.14.

insert_sorted_iter(data, iter_cmp, *cmp_data)[source]
Parameters:
Returns:

a GLib.SequenceIter pointing to the new item

Return type:

GLib.SequenceIter

Like GLib.Sequence.insert_sorted(), but uses a GLib.SequenceIterCompareFunc instead of a GLib.CompareDataFunc as the compare function.

iter_cmp is called with two iterators pointing into self. It should return 0 if the iterators are equal, a negative value if the first iterator comes before the second, and a positive value if the second iterator comes before the first.

Note that when adding a large amount of data to a GLib.Sequence, it is more efficient to do unsorted insertions and then call GLib.Sequence.sort() or GLib.Sequence.sort_iter().

New in version 2.14.

is_empty()[source]
Returns:

True if the sequence is empty, otherwise False.

Return type:

bool

Returns True if the sequence contains zero items.

This function is functionally identical to checking the result of GLib.Sequence.get_length() being equal to zero. However this function is implemented in O(1) running time.

New in version 2.48.

lookup(data, cmp_func, *cmp_data)[source]
Parameters:
Returns:

an GLib.SequenceIter pointing to the position of the first item found equal to data according to cmp_func and cmp_data, or None if no such item exists

Return type:

GLib.SequenceIter or None

Returns an iterator pointing to the position of the first item found equal to data according to cmp_func and cmp_data. If more than one item is equal, it is not guaranteed that it is the first which is returned. In that case, you can use GLib.SequenceIter.next() and GLib.SequenceIter.prev() to get others.

cmp_func is called with two items of the self, and cmp_data. It should return 0 if the items are equal, a negative value if the first item comes before the second, and a positive value if the second item comes before the first.

This function will fail if the data contained in the sequence is unsorted.

New in version 2.28.

lookup_iter(data, iter_cmp, *cmp_data)[source]
Parameters:
Returns:

an GLib.SequenceIter pointing to the position of the first item found equal to data according to iter_cmp and cmp_data, or None if no such item exists

Return type:

GLib.SequenceIter or None

Like GLib.Sequence.lookup(), but uses a GLib.SequenceIterCompareFunc instead of a GLib.CompareDataFunc as the compare function.

iter_cmp is called with two iterators pointing into self. It should return 0 if the iterators are equal, a negative value if the first iterator comes before the second, and a positive value if the second iterator comes before the first.

This function will fail if the data contained in the sequence is unsorted.

New in version 2.28.

prepend(data)[source]
Parameters:

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

Returns:

an iterator pointing to the new item

Return type:

GLib.SequenceIter

Adds a new item to the front of self

New in version 2.14.

search(data, cmp_func, *cmp_data)[source]
Parameters:
Returns:

an GLib.SequenceIter pointing to the position where data would have been inserted according to cmp_func and cmp_data

Return type:

GLib.SequenceIter

Returns an iterator pointing to the position where data would be inserted according to cmp_func and cmp_data.

cmp_func is called with two items of the self, and cmp_data. It should return 0 if the items are equal, a negative value if the first item comes before the second, and a positive value if the second item comes before the first.

If you are simply searching for an existing element of the sequence, consider using GLib.Sequence.lookup().

This function will fail if the data contained in the sequence is unsorted.

New in version 2.14.

search_iter(data, iter_cmp, *cmp_data)[source]
Parameters:
Returns:

a GLib.SequenceIter pointing to the position in self where data would have been inserted according to iter_cmp and cmp_data

Return type:

GLib.SequenceIter

Like GLib.Sequence.search(), but uses a GLib.SequenceIterCompareFunc instead of a GLib.CompareDataFunc as the compare function.

iter_cmp is called with two iterators pointing into self. It should return 0 if the iterators are equal, a negative value if the first iterator comes before the second, and a positive value if the second iterator comes before the first.

If you are simply searching for an existing element of the sequence, consider using GLib.Sequence.lookup_iter().

This function will fail if the data contained in the sequence is unsorted.

New in version 2.14.

sort(cmp_func, *cmp_data)[source]
Parameters:

Sorts self using cmp_func.

cmp_func is passed two items of self 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.

New in version 2.14.

sort_iter(cmp_func, *cmp_data)[source]
Parameters:

Like GLib.Sequence.sort(), but uses a GLib.SequenceIterCompareFunc instead of a GLib.CompareDataFunc as the compare function

cmp_func is called with two iterators pointing into self. It should return 0 if the iterators are equal, a negative value if the first iterator comes before the second, and a positive value if the second iterator comes before the first.

New in version 2.14.