Description:
[
Compact ]
[
CCode ( ref_function =
"g_hash_table_ref" , type_id =
"G_TYPE_HASH_TABLE" , type_signature =
"a{%s}" , unref_function =
"g_hash_table_unref" ) ]
public class HashTable<
K,
V>
Example: Get the value for a key:
public static int main (string[] args) {
HashTable<string, string> table = new HashTable<string, string> (str_hash, str_equal);
table.insert ("1", "first string");
table.insert ("2", "second string");
table.insert ("3", "third string");
// Output: ``first string``
unowned string val = table.get ("1");
print ("%s\n", val);
// Output: ``second string``
val = table.get ("2");
print ("%s\n", val);
// Output: ``third string``
val = table.get ("3");
print ("%s\n", val);
// Output: ``(null)``
val = table.get ("4");
print ("%s\n", val);
HashTable<string, int> table2 = new HashTable<string, int> (str_hash, str_equal);
table2.insert ("1", 1);
// Output: ``1``
int val2 = table2.get ("1");
print ("%d\n", val2);
// Output: ``0``
val2 = table2.get ("2");
print ("%d\n", val2);
HashTable<string, int?> table3 = new HashTable<string, int?> (str_hash, str_equal);
table3.insert ("1", 1);
// Output: ``1``
int? val3 = table3.get ("1");
print ("%d\n", val3);
// Output: ``(null)``
val3 = table3.get ("2");
if (val3 == null) {
print ("(null)\n");
} else {
print ("%d\n", val3);
}
return 0;
}
valac --pkg glib-2.0 GLib.HashTable.get.vala
Content:
Properties:
Creation methods:
Methods:
- public void @foreach (HFunc<K,V> func)
- public unowned V @get (K key)
- public bool @set (owned K key, owned V value)
- public bool add (owned K key)
- public bool contains (K key)
- public unowned V find (HRFunc<K,V> predicate)
Calls the given function for key/value pairs in the
GenericSet until predicate returns true
.
- public void for_each (HFunc<K,V> func)
Calls the given function for each of the key/value pairs in the
GenericSet.
- public uint foreach_remove (HRFunc<K,V> predicate)
Calls the given function for each key/value pair in the
GenericSet.
- public uint foreach_steal (HRFunc<K,V> predicate)
Calls the given function for each key/value pair in the
GenericSet.
- public List<unowned K> get_keys ()
- public (unowned K)[] get_keys_as_array ()
- public GenericArray<unowned K> get_keys_as_ptr_array ()
- public List<unowned V> get_values ()
- public GenericArray<unowned V> get_values_as_ptr_array ()
- public bool insert (owned K key, owned V value)
- public unowned V lookup (K key)
- public bool lookup_extended (K lookup_key, out unowned K orig_key, out unowned V value)
Looks up a key in the
GenericSet, returning the original key and the associated value and a
bool which is true if the key was found.
- public bool remove (K key)
- public void remove_all ()
- public bool replace (owned K key, owned V value)
- public uint size ()
Returns the number of elements contained in the
GenericSet.
- public bool steal (K key)
Removes a key and its associated value from a
GenericSet without calling the key and value destroy functions.
- public void steal_all ()
Removes all keys and their associated values from a
GenericSet without calling the key and value destroy functions.
- public GenericArray<K> steal_all_keys ()
Removes all keys and their associated values from a
GenericSet without calling the key destroy functions, returning the keys as a
GenericArray with the free func set to the hash_table key
destroy function.
- public GenericArray<V> steal_all_values ()
Removes all keys and their associated values from a
GenericSet without calling the value destroy functions, returning the values as
a GenericArray with the free func set to the hash_table value
destroy function.
- public bool steal_extended (K lookup_key, out K stolen_key, out V stolen_value)
Looks up a key in the
GenericSet, stealing the original key and the associated value and returning
true if the key was found.
- public V take (K key, out bool exists = null)