gi-glib-2.0.24: GLib bindings

Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte
License | LGPL-2.1
Maintainer | Iñaki García Etxebarria
Safe Haskell | None
Language | Haskell2010

GI.GLib.Structs.HashTableIter

Contents

- Exported types
- Methods
  - Overloaded methods
  - init
  - next
  - remove
  - replace
  - steal

Description

A GHashTableIter structure represents an iterator that can be used to iterate over the elements of a `HashTable`. GHashTableIter structures are typically allocated on the stack and then initialized with `hashTableIterInit`.

The iteration order of a `HashTableIter` over the keys/values in a hash table is not defined.

Synopsis

- newtype HashTableIter = HashTableIter (ManagedPtr HashTableIter)
- newZeroHashTableIter :: MonadIO m => m HashTableIter
- hashTableIterInit :: (HasCallStack, MonadIO m) => HashTableIter -> Map (Ptr ()) (Ptr ()) -> m ()
- hashTableIterNext :: (HasCallStack, MonadIO m) => HashTableIter -> m (Bool, Ptr (), Ptr ())
- hashTableIterRemove :: (HasCallStack, MonadIO m) => HashTableIter -> m ()
- hashTableIterReplace :: (HasCallStack, MonadIO m) => HashTableIter -> Ptr () -> m ()
- hashTableIterSteal :: (HasCallStack, MonadIO m) => HashTableIter -> m ()

# Exported types

newtype HashTableIter Source #

Memory-managed wrapper type.

Constructors

HashTableIter (ManagedPtr HashTableIter) |

#### Instances

Instances details

Eq HashTableIter Source # |
Instance details Defined in GI.GLib.Structs.HashTableIter Methods (==) :: HashTableIter -> HashTableIter -> Bool # (/=) :: HashTableIter -> HashTableIter -> Bool #
ManagedPtrNewtype HashTableIter Source # |
Instance details Defined in GI.GLib.Structs.HashTableIter Methods toManagedPtr :: HashTableIter -> ManagedPtr HashTableIter Source #
BoxedPtr HashTableIter Source # |
Instance details Defined in GI.GLib.Structs.HashTableIter Methods boxedPtrCopy :: HashTableIter -> IO HashTableIter Source # boxedPtrFree :: HashTableIter -> IO () Source #
CallocPtr HashTableIter Source # |
Instance details Defined in GI.GLib.Structs.HashTableIter Methods boxedPtrCalloc :: IO (Ptr HashTableIter) Source #
tag ~ 'AttrSet => Constructible HashTableIter tag Source # |
Instance details Defined in GI.GLib.Structs.HashTableIter Methods new :: MonadIO m => (ManagedPtr HashTableIter -> HashTableIter) -> [AttrOp HashTableIter tag] -> m HashTableIter Source #

newZeroHashTableIter :: MonadIO m => m HashTableIter Source #

Construct a `HashTableIter` struct initialized to zero.

# Methods

## Overloaded methods

## init

hashTableIterInit Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> HashTableIter | `iter`: an uninitialized `HashTableIter`
-> Map (Ptr ()) (Ptr ()) | `hashTable`: a `HashTable`
-> m () |

Initializes a key/value pair iterator and associates it with `hashTable`. Modifying the hash table after calling this function invalidates the returned iterator.

The iteration order of a `HashTableIter` over the keys/values in a hash table is not defined.

### C code

    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
      }

Since: 2.16

## next

hashTableIterNext Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> HashTableIter | `iter`: an initialized `HashTableIter`
-> m (Bool, Ptr (), Ptr ()) | Returns: `False` if the end of the `HashTable` has been reached.

Advances `iter` and retrieves the key and/or value that are now pointed to as a result of this advancement. If `False` is returned, `key` and `value` are not set, and the iterator becomes invalid.

Since: 2.16

## remove

hashTableIterRemove Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> HashTableIter | `iter`: an initialized `HashTableIter`
-> m () |

Removes the key/value pair currently pointed to by the iterator from its associated `HashTable`. Can only be called after `hashTableIterNext` returned `True`, and cannot be called more than once for the same key/value pair.

If the `HashTable` was created using `g_hash_table_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 `HashTable` afterward:

### C code

    while (g_hash_table_iter_next (&iter, &key, &value))
      {
        if (condition)
          g_hash_table_iter_remove (&iter);
      }

Since: 2.16

## replace

hashTableIterReplace Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> HashTableIter | `iter`: an initialized `HashTableIter`
-> Ptr () | `value`: the value to replace with
-> m () |

Replaces the value currently pointed to by the iterator from its associated `HashTable`. Can only be called after `hashTableIterNext` returned `True`.

If you supplied a `valueDestroyFunc` when creating the `HashTable`, the old value is freed using that function.

Since: 2.30

## steal

hashTableIterSteal Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> HashTableIter | `iter`: an initialized `HashTableIter`
-> m () |

Removes the key/value pair currently pointed to by the iterator from its associated `HashTable`, without calling the key and value destroy functions. Can only be called after `hashTableIterNext` returned `True`, and cannot be called more than once for the same key/value pair.

Since: 2.16