:right-sidebar: True HashTableIter =================================================================== .. currentmodule:: gi.repository.GLib .. class:: HashTableIter(*args, **kwargs) :no-contents-entry: A GHashTableIter structure represents an iterator that can be used to iterate over the elements of a :obj:`~gi.repository.GLib.HashTable`\. GHashTableIter structures are typically allocated on the stack and then initialized with :func:`~gi.repository.GLib.HashTableIter.init`. The iteration order of a :obj:`~gi.repository.GLib.HashTableIter` over the keys/values in a hash table is not defined. Methods ------- .. rst-class:: interim-class .. class:: HashTableIter :no-index: .. method:: get_hash_table() -> dict[~typing.Any, ~typing.Any] Returns the :obj:`~gi.repository.GLib.HashTable` associated with ``iter``\. .. versionadded:: 2.16 .. method:: init(hash_table: dict[~typing.Any, ~typing.Any]) -> None Initializes a key/value pair iterator and associates it with ``hash_table``\. Modifying the hash table after calling this function invalidates the returned iterator. The iteration order of a :obj:`~gi.repository.GLib.HashTableIter` over the keys/values in a hash table is not defined. .. code-block:: C :dedent: GHashTableIter iter; gpointer key, value; g_hash_table_iter_init (&iter, hash_table); while (g_hash_table_iter_next (&iter, &key, &value)) { // do something with key and value } .. versionadded:: 2.16 :param hash_table: a :obj:`~gi.repository.GLib.HashTable` .. method:: next() -> ~typing.Tuple[bool, ~typing.Any | None, ~typing.Any | None] Advances ``iter`` and retrieves the key and/or value that are now pointed to as a result of this advancement. If :const:`False` is returned, ``key`` and ``value`` are not set, and the iterator becomes invalid. .. versionadded:: 2.16 .. method:: remove() -> None Removes the key/value pair currently pointed to by the iterator from its associated :obj:`~gi.repository.GLib.HashTable`\. Can only be called after :func:`~gi.repository.GLib.HashTableIter.next` returned :const:`True`, and cannot be called more than once for the same key/value pair. If the :obj:`~gi.repository.GLib.HashTable` was created using :func:`~gi.repository.GLib.HashTable.new_full`, the key and value are freed using the supplied destroy functions, otherwise you have to make sure that any dynamically allocated values are freed yourself. It is safe to continue iterating the :obj:`~gi.repository.GLib.HashTable` afterward: .. code-block:: C :dedent: while (g_hash_table_iter_next (&iter, &key, &value)) { if (condition) g_hash_table_iter_remove (&iter); } .. versionadded:: 2.16 :return: 0 if the file was successfully removed, -1 if an error occurred .. method:: replace(value: ~typing.Any = None) -> None Replaces the value currently pointed to by the iterator from its associated :obj:`~gi.repository.GLib.HashTable`\. Can only be called after :func:`~gi.repository.GLib.HashTableIter.next` returned :const:`True`. If you supplied a ``value_destroy_func`` when creating the :obj:`~gi.repository.GLib.HashTable`\, the old value is freed using that function. .. versionadded:: 2.30 :param value: the value to replace with Fields ------ .. rst-class:: interim-class .. class:: HashTableIter :no-index: .. attribute:: dummy1 .. attribute:: dummy2 .. attribute:: dummy3 .. attribute:: dummy4 .. attribute:: dummy5 .. attribute:: dummy6