W Wrapl, The Programming Language

Libraries:Gtk:Glib:GHashTable

Types

T

Constants

Nil : T

Functions

New(hash_func @ Std.Function.T, key_equal_func @ Std.Function.T) : Gtk.Glib.GHashTable.T

Creates a new T with a reference count of 1.

hash_func a function to create a hash value from a key. Hash values are used to determine where keys are stored within the T data structure. The g_direct_hash(), g_int_hash(), g_int64_hash(), g_double_hash() and g_str_hash() functions are provided for some common types of keys. If hash_func is NULL, g_direct_hash() is used.
key_equal_func a function to check two keys for equality. This is used when looking up keys in the T. The g_direct_equal(), g_int_equal(), g_int64_equal(), g_double_equal() and g_str_equal() functions are provided for the most common types of keys. If key_equal_func is NULL, keys are compared directly in a similar fashion to g_direct_equal(), but without the overhead of a function call.
Returns a new T.


NewFull(hash_func @ Std.Function.T, key_equal_func @ Std.Function.T, key_destroy_func @ Std.Function.T, value_destroy_func @ Std.Function.T) : Gtk.Glib.GHashTable.T

Creates a new T like g_hash_table_new() with a reference count of 1 and allows to specify functions to free the memory allocated for the key and value that get called when removing the entry from the T.

hash_func a function to create a hash value from a key.
key_equal_func a function to check two keys for equality.
key_destroy_func a function to free the memory allocated for the key used when removing the entry from the T or NULL if you don't want to supply such a function.
value_destroy_func a function to free the memory allocated for the value used when removing the entry from the T or NULL if you don't want to supply such a function.
Returns a new T.


Methods

:"="(_ @ T, _ @ T)

:Destroy(self @ T) : Std.Object.T

Destroys all keys and values in the T and decrements its reference count by 1. If keys and/or values are dynamically allocated, you should either free them first or create the T with destroy notifiers using g_hash_table_new_full(). In the latter case the destroy functions you supplied will be called on all keys and values during the destruction phase.

hash_table a T.


:Find(self @ T, predicate @ Std.Function.T, user_data) : Std.Address.T

Calls the given function for key/value pairs in the T until predicate returns TRUE. The function is passed the key and value of each pair, and the given user_data parameter. The hash table may not be modified while iterating over it (you can't add/remove items).

Note, that hash tables are really only optimized for forward lookups, i.e. Lookup. So code that frequently issues Find or Foreach (e.g. in the order of once per every entry in a hash table) should probably be reworked to use additional or different data structures for reverse lookups (keep in mind that an O(n) find/foreach operation issued for all n values in a hash table ends up needing O(n*n) operations).

hash_table a T.
predicate function to test the key/value pairs for a certain property.
user_data user data to pass to the function.
Returns The value of the first key/value pair is returned, for which predicate evaluates to TRUE. If no pair with the requested property is found, NULL is returned.


:Foreach(self @ T, func @ Std.Function.T, user_data) : Std.Object.T

Calls the given function for each of the key/value pairs in the T. The function is passed the key and value of each pair, and the given user_data parameter. The hash table may not be modified while iterating over it (you can't add/remove items). To remove all items matching a predicate, use ForeachRemove.

See Find for performance caveats for linear order searches in contrast to Lookup.

hash_table a T.
func the function to call for each key/value pair.
user_data user data to pass to the function.


:ForeachRemove(self @ T, func @ Std.Function.T, user_data) : Std.Integer.SmallT

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

See Gtk.Glib.GHashTableIter.T for an alternative way to loop over the key/value pairs in the hash table.

hash_table a T.
func the function to call for each key/value pair.
user_data user data to pass to the function.
Returns the number of key/value pairs removed.


:ForeachSteal(self @ T, func @ Std.Function.T, user_data) : Std.Integer.SmallT

Calls the given function for each key/value pair in the T. If the function returns TRUE, then the key/value pair is removed from the T, but no key or value destroy functions are called.

See Gtk.Glib.GHashTableIter.T for an alternative way to loop over the key/value pairs in the hash table.

hash_table a T.
func the function to call for each key/value pair.
user_data user data to pass to the function.
Returns the number of key/value pairs removed.


:GetKeys(self @ T) : Std.Object.T

Retrieves every key inside hash_table. The returned data is valid until hash_table is modified.

hash_table a T
Returns a GList containing all the keys inside the hash table. The content of the list is owned by the hash table and should not be modified or freed. Use g_list_free() when done using the list.


:GetValues(self @ T) : Std.Object.T

Retrieves every value inside hash_table. The returned data is valid until hash_table is modified.

hash_table a T
Returns a GList containing all the values inside the hash table. The content of the list is owned by the hash table and should not be modified or freed. Use g_list_free() when done using the list.


:Insert(self @ T, key @ Std.Address.T, value @ Std.Address.T) : Std.Object.T

Inserts a new key and value into a T.

If the key already exists in the T its current value is replaced with the new value. If you supplied a value_destroy_func when creating the T, the old value is freed using that function. If you supplied a key_destroy_func when creating the T, the passed key is freed using that function.

hash_table a T.
key a key to insert.
value the value to associate with the key.


:Lookup(self @ T, key @ Std.Address.T) : Std.Address.T

Looks up a key in a T. Note that this function cannot distinguish between a key that is not present and one which is present and has the value NULL. If you need this distinction, use LookupExtended.

hash_table a T.
key the key to look up.
Returns the associated value, or NULL if the key is not found.


:LookupExtended(self @ T, lookup_key @ Std.Address.T, orig_key @ Std.Object.T, value @ Std.Object.T) : Std.Symbol.T

Looks up a key in the T, returning the original key and the associated value and a gboolean which is TRUE if the key was found. This is useful if you need to free the memory allocated for the original key, for example before calling Remove.

You can actually pass NULL for lookup_key to test whether the NULL key exists, provided the hash and equal functions of hash_table are NULL-safe.

hash_table a T
lookup_key the key to look up
orig_key return location for the original key, or NULL
value return location for the value associated with the key, or NULL
Returns TRUE if the key was found in the T.


:Ref(self @ T) : Gtk.Glib.GHashTable.T

Atomically increments the reference count of hash_table by one. This function is MT-safe and may be called from any thread.

hash_table a valid T.
Returns the passed in T.


:Remove(self @ T, key @ Std.Address.T) : Std.Symbol.T

Removes a key and its associated value from a T.

If the T 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.

hash_table a T.
key the key to remove.
Returns TRUE if the key was found and removed from the T.


:RemoveAll(self @ T) : Std.Object.T

Removes all keys and their associated values from a T.

If the T was created using g_hash_table_new_full(), the keys and values are freed using the supplied destroy functions, otherwise you have to make sure that any dynamically allocated values are freed yourself.

hash_table a T


:Replace(self @ T, key @ Std.Address.T, value @ Std.Address.T) : Std.Object.T

Inserts a new key and value into a T similar to Insert. The difference is that if the key already exists in the T, it gets replaced by the new key. If you supplied a value_destroy_func when creating the T, the old value is freed using that function. If you supplied a key_destroy_func when creating the T, the old key is freed using that function.

hash_table a T.
key a key to insert.
value the value to associate with the key.


:Size(self @ T) : Std.Integer.SmallT

Returns the number of elements contained in the T.

hash_table a T.
Returns the number of key/value pairs in the T.


:Steal(self @ T, key @ Std.Address.T) : Std.Symbol.T

Removes a key and its associated value from a T without calling the key and value destroy functions.

hash_table a T.
key the key to remove.
Returns TRUE if the key was found and removed from the T.


:StealAll(self @ T) : Std.Object.T

Removes all keys and their associated values from a T without calling the key and value destroy functions.

hash_table a T.


:Unref(self @ T) : Std.Object.T

Atomically decrements the reference count of hash_table by one. If the reference count drops to 0, all keys and values will be destroyed, and all memory allocated by the hash table is released. This function is MT-safe and may be called from any thread.

hash_table a valid T.


:"~="(_ @ T, _ @ T)