HashTable

The glib.HashTable struct is an opaque data structure to represent a [Hash Table][glib-Hash-Tables]. It should only be accessed via the following functions.

Constructors

this
this(GHashTable* gHashTable, bool ownedRef)

Sets our main struct and passes it to the parent class.

this
this(GHashFunc hashFunc, GEqualFunc keyEqualFunc)

Creates a new glib.HashTable with a reference count of 1.

this
this(GHashFunc hashFunc, GEqualFunc keyEqualFunc, GDestroyNotify keyDestroyFunc, GDestroyNotify valueDestroyFunc)

Creates a new glib.HashTable like HashTable.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 glib.HashTable

Members

Functions

add
bool add(void* key)

This is a convenience function for using a glib.HashTable as a set. It is equivalent to calling HashTable.replace with key as both the key and the value.

contains
bool contains(void* key)

Checks if key is in hash_table.

destroy
void destroy()

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

find
void* find(GHRFunc predicate, void* userData)

Calls the given function for key/value pairs in the glib.HashTable 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).

foreachRemove
uint foreachRemove(GHRFunc func, void* userData)

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

foreachSteal
uint foreachSteal(GHRFunc func, void* userData)

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

foreach_
void foreach_(GHFunc func, void* userData)

Calls the given function for each of the key/value pairs in the glib.HashTable 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 HashTable.foreachRemove.

getHashTableStruct
GHashTable* getHashTableStruct(bool transferOwnership)

Get the main Gtk struct

getKeys
ListG getKeys()

Retrieves every key inside hash_table. The returned data is valid until changes to the hash release those keys.

getKeysAsArray
void*[] getKeysAsArray()

Retrieves every key inside hash_table, as an array.

getStruct
void* getStruct()

the main Gtk struct as a void*

getValues
ListG getValues()

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

insert
bool insert(void* key, void* value)

Inserts a new key and value into a glib.HashTable

lookup
void* lookup(void* key)

Looks up a key in a glib.HashTable 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 HashTable.lookupExtended.

lookupExtended
bool lookupExtended(void* lookupKey, void* origKey, void* value)

Looks up a key in the glib.HashTable, 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 HashTable.remove.

ref_
HashTable ref_()

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

remove
bool remove(void* key)

Removes a key and its associated value from a glib.HashTable

removeAll
void removeAll()

Removes all keys and their associated values from a glib.HashTable

replace
bool replace(void* key, void* value)

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

size
uint size()

Returns the number of elements contained in the glib.HashTable

steal
bool steal(void* key)

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

stealAll
void stealAll()

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

stealExtended
bool stealExtended(void* lookupKey, void* stolenKey, void* stolenValue)

Looks up a key in the glib.HashTable, stealing the original key and the associated value and returning TRUE if the key was found. If the key was not found, FALSE is returned.

unref
void unref()

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.

Static functions

directEqual
bool directEqual(void* v1, void* v2)

Compares two gpointer arguments and returns TRUE if they are equal. It can be passed to HashTable.new as the key_equal_func parameter, when using opaque pointers compared by pointer value as keys in a glib.HashTable

directHash
uint directHash(void* v)

Converts a gpointer to a hash value. It can be passed to HashTable.new as the hash_func parameter, when using opaque pointers compared by pointer value as keys in a glib.HashTable

doubleEqual
bool doubleEqual(void* v1, void* v2)

Compares the two gdouble values being pointed to and returns TRUE if they are equal. It can be passed to HashTable.new as the key_equal_func parameter, when using non-NULL pointers to doubles as keys in a glib.HashTable

doubleHash
uint doubleHash(void* v)

Converts a pointer to a gdouble to a hash value. It can be passed to HashTable.new as the hash_func parameter, It can be passed to HashTable.new as the hash_func parameter, when using non-NULL pointers to doubles as keys in a glib.HashTable

int64Equal
bool int64Equal(void* v1, void* v2)

Compares the two gint64 values being pointed to and returns TRUE if they are equal. It can be passed to HashTable.new as the key_equal_func parameter, when using non-NULL pointers to 64-bit integers as keys in a glib.HashTable

int64Hash
uint int64Hash(void* v)

Converts a pointer to a gint64 to a hash value.

intEqual
bool intEqual(void* v1, void* v2)

Compares the two gint values being pointed to and returns TRUE if they are equal. It can be passed to HashTable.new as the key_equal_func parameter, when using non-NULL pointers to integers as keys in a glib.HashTable

intHash
uint intHash(void* v)

Converts a pointer to a gint to a hash value. It can be passed to HashTable.new as the hash_func parameter, when using non-NULL pointers to integer values as keys in a glib.HashTable

strEqual
bool strEqual(void* v1, void* v2)

Compares two strings for byte-by-byte equality and returns TRUE if they are equal. It can be passed to HashTable.new as the key_equal_func parameter, when using non-NULL strings as keys in a glib.HashTable

strHash
uint strHash(void* v)

Converts a string to a hash value.

Variables

gHashTable
GHashTable* gHashTable;

the main Gtk struct