Sequence#
- class Sequence(*args, **kwargs)#
The Sequence
struct is an opaque data type representing a
[sequence][glib-Sequences] data type.
Methods#
- class Sequence
- append(data: None) SequenceIter #
Adds a new item to the end of
seq
.Added in version 2.14.
- Parameters:
data – the data for the new item
- foreach(func: Callable[[...], None], *user_data: Any) None #
Calls
func
for each item in the sequence passinguser_data
to the function.func
must not modify the sequence itself.Added in version 2.14.
- Parameters:
func – the function to call for each item in
seq
user_data – user data passed to
func
- foreach_range(begin: SequenceIter, end: SequenceIter, func: Callable[[...], None], *user_data: Any) None #
Calls
func
for each item in the range (begin
,end
) passinguser_data
to the function.func
must not modify the sequence itself.Added in version 2.14.
- Parameters:
begin – a
SequenceIter
end – a
SequenceIter
func – a
Func
user_data – user data passed to
func
- free() None #
Frees the memory allocated for
seq
. Ifseq
has a data destroy function associated with it, that function is called on all items inseq
.Added in version 2.14.
- get(iter: SequenceIter) None #
Returns the data that
iter
points to.Added in version 2.14.
- Parameters:
iter – a
SequenceIter
- get_begin_iter() SequenceIter #
Returns the begin iterator for
seq
.Added in version 2.14.
- get_end_iter() SequenceIter #
Returns the end iterator for
seg
Added in version 2.14.
- get_iter_at_pos(pos: int) SequenceIter #
Returns the iterator at position
pos
. Ifpos
is negative or larger than the number of items inseq
, the end iterator is returned.Added in version 2.14.
- Parameters:
pos – a position in
seq
, or -1 for the end
- get_length() int #
Returns the positive length (>= 0) of
seq
. Note that this method is O(h) whereh' is the height of the tree. It is thus more efficient to use :func:`~gi.repository.GLib.Sequence.is_empty
when comparing the length to zero.Added in version 2.14.
- insert_before(iter: SequenceIter, data: None) SequenceIter #
Inserts a new item just before the item pointed to by
iter
.Added in version 2.14.
- Parameters:
iter – a
SequenceIter
data – the data for the new item
- insert_sorted(data: None, cmp_func: Callable[[...], int], *cmp_data: Any) SequenceIter #
Inserts
data
intoseq
usingcmp_func
to determine the new position. The sequence must already be sorted according tocmp_func
; otherwise the new position ofdata
is undefined.cmp_func
is called with two items of theseq
, andcmp_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
Sequence
, it is more efficient to do unsorted insertions and then callsort()
orsort_iter()
.Added in version 2.14.
- Parameters:
data – the data to insert
cmp_func – the function used to compare items in the sequence
cmp_data – user data passed to
cmp_func
.
- insert_sorted_iter(data: None, iter_cmp: Callable[[...], int], *cmp_data: Any) SequenceIter #
Like
insert_sorted()
, but uses aSequenceIterCompareFunc
instead of aCompareDataFunc
as the compare function.iter_cmp
is called with two iterators pointing intoseq
. 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
Sequence
, it is more efficient to do unsorted insertions and then callsort()
orsort_iter()
.Added in version 2.14.
- Parameters:
data – data for the new item
iter_cmp – the function used to compare iterators in the sequence
cmp_data – user data passed to
iter_cmp
- is_empty() bool #
Returns
True
if the sequence contains zero items.This function is functionally identical to checking the result of
get_length()
being equal to zero. However this function is implemented in O(1) running time.Added in version 2.48.
- lookup(data: None, cmp_func: Callable[[...], int], *cmp_data: Any) SequenceIter | None #
Returns an iterator pointing to the position of the first item found equal to
data
according tocmp_func
andcmp_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 usenext()
andprev()
to get others.cmp_func
is called with two items of theseq
, andcmp_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.
Added in version 2.28.
- Parameters:
data – data to look up
cmp_func – the function used to compare items in the sequence
cmp_data – user data passed to
cmp_func
- lookup_iter(data: None, iter_cmp: Callable[[...], int], *cmp_data: Any) SequenceIter | None #
Like
lookup()
, but uses aSequenceIterCompareFunc
instead of aCompareDataFunc
as the compare function.iter_cmp
is called with two iterators pointing intoseq
. 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.
Added in version 2.28.
- Parameters:
data – data to look up
iter_cmp – the function used to compare iterators in the sequence
cmp_data – user data passed to
iter_cmp
- move(src: SequenceIter, dest: SequenceIter) None #
Moves the item pointed to by
src
to the position indicated bydest
. After calling this functiondest
will point to the position immediately aftersrc
. It is allowed forsrc
anddest
to point into different sequences.Added in version 2.14.
- Parameters:
src – a
SequenceIter
pointing to the item to movedest – a
SequenceIter
pointing to the position to which the item is moved
- move_range(dest: SequenceIter, begin: SequenceIter, end: SequenceIter) None #
Inserts the (
begin
,end
) range at the destination pointed to bydest
. Thebegin
andend
iters must point into the same sequence. It is allowed fordest
to point to a different sequence than the one pointed into bybegin
andend
.If
dest
isNone
, the range indicated bybegin
andend
is removed from the sequence. Ifdest
points to a place within the (begin
,end
) range, the range does not move.Added in version 2.14.
- Parameters:
dest – a
SequenceIter
begin – a
SequenceIter
end – a
SequenceIter
- prepend(data: None) SequenceIter #
Adds a new item to the front of
seq
Added in version 2.14.
- Parameters:
data – the data for the new item
- range_get_midpoint(begin: SequenceIter, end: SequenceIter) 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
andend
iterators must both point to the same sequence andbegin
must come before or be equal toend
in the sequence.Added in version 2.14.
- Parameters:
begin – a
SequenceIter
end – a
SequenceIter
- remove(iter: SequenceIter) None #
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.
Added in version 2.14.
- Parameters:
iter – a
SequenceIter
- Returns:
0 if the file was successfully removed, -1 if an error occurred
- remove_range(begin: SequenceIter, end: SequenceIter) None #
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.
Added in version 2.14.
- Parameters:
begin – a
SequenceIter
end – a
SequenceIter
- search(data: None, cmp_func: Callable[[...], int], *cmp_data: Any) SequenceIter #
Returns an iterator pointing to the position where
data
would be inserted according tocmp_func
andcmp_data
.cmp_func
is called with two items of theseq
, andcmp_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
lookup()
.This function will fail if the data contained in the sequence is unsorted.
Added in version 2.14.
- Parameters:
data – data for the new item
cmp_func – the function used to compare items in the sequence
cmp_data – user data passed to
cmp_func
- search_iter(data: None, iter_cmp: Callable[[...], int], *cmp_data: Any) SequenceIter #
Like
search()
, but uses aSequenceIterCompareFunc
instead of aCompareDataFunc
as the compare function.iter_cmp
is called with two iterators pointing intoseq
. 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
lookup_iter()
.This function will fail if the data contained in the sequence is unsorted.
Added in version 2.14.
- Parameters:
data – data for the new item
iter_cmp – the function used to compare iterators in the sequence
cmp_data – user data passed to
iter_cmp
- set(iter: SequenceIter, data: None) None #
Changes the data for the item pointed to by
iter
to bedata
. If the sequence has a data destroy function associated with it, that function is called on the existing data thatiter
pointed to.Added in version 2.14.
- Parameters:
iter – a
SequenceIter
data – new data for the item
- sort(cmp_func: Callable[[...], int], *cmp_data: Any) None #
Sorts
seq
usingcmp_func
.cmp_func
is passed two items ofseq
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.Added in version 2.14.
- Parameters:
cmp_func – the function used to sort the sequence
cmp_data – user data passed to
cmp_func
- sort_changed(iter: SequenceIter, cmp_func: Callable[[...], int], *cmp_data: Any) None #
Moves the data pointed to by
iter
to a new position as indicated bycmp_func
. This function should be called for items in a sequence already sorted according tocmp_func
whenever some aspect of an item changes so thatcmp_func
may return different values for that item.cmp_func
is called with two items of theseq
, andcmp_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.Added in version 2.14.
- Parameters:
iter – A
SequenceIter
cmp_func – the function used to compare items in the sequence
cmp_data – user data passed to
cmp_func
.
- sort_changed_iter(iter: SequenceIter, iter_cmp: Callable[[...], int], *cmp_data: Any) None #
Like
sort_changed()
, but uses aSequenceIterCompareFunc
instead of aCompareDataFunc
as the compare function.iter_cmp
is called with two iterators pointing into theSequence
thatiter
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.Added in version 2.14.
- Parameters:
iter – a
SequenceIter
iter_cmp – the function used to compare iterators in the sequence
cmp_data – user data passed to
cmp_func
- sort_iter(cmp_func: Callable[[...], int], *cmp_data: Any) None #
Like
sort()
, but uses aSequenceIterCompareFunc
instead of aCompareDataFunc
as the compare functioncmp_func
is called with two iterators pointing intoseq
. 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.Added in version 2.14.
- Parameters:
cmp_func – the function used to compare iterators in the sequence
cmp_data – user data passed to
cmp_func
- swap(a: SequenceIter, b: SequenceIter) None #
Swaps the items pointed to by
a
andb
. It is allowed fora
andb
to point into difference sequences.Added in version 2.14.
- Parameters:
a – a
SequenceIter
b – a
SequenceIter