foreach_remove


Description:

public uint foreach_remove (HRFunc<K,V> predicate)

Calls the given function for each key/value pair in the GenericSet.

If the function returns true, then the key/value pair is removed from the GenericSet. If you supplied key or value destroy functions when creating the GenericSet, they are used to free the memory allocated for the removed keys and values.

See GenericSetIter for an alternative way to loop over the key/value pairs in the hash table.

Example: Filter all entries:

public static int main (string[] args) {
HashTable<int, string> table = new HashTable<int, string> (direct_hash, direct_equal);
table.insert (1, "first string");
table.insert (2, "second string");
table.insert (3, "third string");

// Output:
// ``1 => first string``
// ``2 => second string``
// ``3 => third string``
table.foreach_remove ((key, val) => {
print ("%d => %s\n", key, val);
return true; // remove current item!
});

// Output: ``Size: 0``
print ("Size: %u\n", table.size ());

return 0;
}

valac --pkg glib-2.0 GLib.HashTable.foreach_remove.vala

Parameters:

func

the function to call for each key/value pair

hash_table

a GenericSet

user_data

user data to pass to the function

Returns:

the number of key/value pairs removed