Package ch.bailu.gtk.glib
Class HashTable
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.type.Record
ch.bailu.gtk.glib.HashTable
- All Implemented Interfaces:
PointerInterface
The #GHashTable struct is an opaque data structure to represent a
[Hash Table][glib-Hash-Tables]. It should only be accessed via the
following functions.
[Hash Table][glib-Hash-Tables]. It should only be accessed via the
following functions.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
static interface
static interface
static interface
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic HashTable
_new
(HashTable.OnHashFunc hash_func, HashTable.OnEqualFunc key_equal_func) Creates a new #GHashTable with a reference count of 1.static boolean
This is a convenience function for using a #GHashTable as a set.static boolean
Checks if @key is in @hash_table.static void
Destroys all keys and values in the #GHashTable and decrements its
reference count by 1.static Pointer
find
(HashTable hash_table, HashTable.OnHRFunc predicate, Pointer user_data) Calls the given function for key/value pairs in the #GHashTable
until @predicate returns %TRUE.static void
foreach
(HashTable hash_table, HashTable.OnHFunc func, Pointer user_data) Calls the given function for each of the key/value pairs in the
#GHashTable.static int
foreachRemove
(HashTable hash_table, HashTable.OnHRFunc func, Pointer user_data) Calls the given function for each key/value pair in the
#GHashTable.static int
foreachSteal
(HashTable hash_table, HashTable.OnHRFunc func, Pointer user_data) Calls the given function for each key/value pair in the
#GHashTable.static ClassHandler
static int
static List
Retrieves every key inside @hash_table.static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
static List
Retrieves every value inside @hash_table.static boolean
Inserts a new key and value into a #GHashTable.static Pointer
Looks up a key in a #GHashTable.static HashTable
newFull
(HashTable.OnHashFunc hash_func, HashTable.OnEqualFunc key_equal_func, HashTable.OnDestroyNotify key_destroy_func, HashTable.OnDestroyNotify value_destroy_func) Creates a new #GHashTable 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 #GHashTable.static HashTable
newSimilar
(HashTable other_hash_table) Creates a new #GHashTable like g_hash_table_new_full() with a reference
count of 1.static HashTable
Atomically increments the reference count of @hash_table by one.static boolean
Removes a key and its associated value from a #GHashTable.static void
Removes all keys and their associated values from a #GHashTable.static boolean
Inserts a new key and value into a #GHashTable similar to
g_hash_table_insert().static int
Returns the number of elements contained in the #GHashTable.static boolean
Removes a key and its associated value from a #GHashTable without
calling the key and value destroy functions.static void
Removes all keys and their associated values from a #GHashTable
without calling the key and value destroy functions.static void
Atomically decrements the reference count of @hash_table by one.Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Constructor Details
-
HashTable
-
-
Method Details
-
getClassHandler
-
add
This is a convenience function for using a #GHashTable as a set. It
is equivalent to calling g_hash_table_replace() with @key as both the
key and the value.
In particular, this means that if @key already exists in the hash table, then
the old copy of @key in the hash table is freed and @key replaces it in the
table.
When a hash table only ever contains keys that have themselves as the
corresponding value it is able to be stored more efficiently. See
the discussion in the section description.
Starting from GLib 2.40, this function returns a boolean value to
indicate whether the newly added value was already in the hash table
or not.- Parameters:
hash_table
- a #GHashTablekey
- a key to insert- Returns:
- %TRUE if the key did not exist yet
-
contains
Checks if @key is in @hash_table.- Parameters:
hash_table
- a #GHashTablekey
- a key to check- Returns:
- %TRUE if @key is in @hash_table, %FALSE otherwise.
-
destroy
Destroys all keys and values in the #GHashTable and decrements its
reference count by 1. If keys and/or values are dynamically allocated,
you should either free them first or create the #GHashTable 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.- Parameters:
hash_table
- a #GHashTable
-
find
public static Pointer find(@Nonnull HashTable hash_table, HashTable.OnHRFunc predicate, @Nullable Pointer user_data) Calls the given function for key/value pairs in the #GHashTable
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. g_hash_table_lookup(). So code that frequently issues
g_hash_table_find() or g_hash_table_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).- Parameters:
hash_table
- a #GHashTablepredicate
- function to test the key/value pairs for a certain propertyuser_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
public static void foreach(@Nonnull HashTable hash_table, HashTable.OnHFunc func, @Nullable Pointer user_data) Calls the given function for each of the key/value pairs in the
#GHashTable. 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
g_hash_table_foreach_remove().
The order in which g_hash_table_foreach() iterates over the keys/values in
the hash table is not defined.
See g_hash_table_find() for performance caveats for linear
order searches in contrast to g_hash_table_lookup().- Parameters:
hash_table
- a #GHashTablefunc
- the function to call for each key/value pairuser_data
- user data to pass to the function
-
foreachRemove
public static int foreachRemove(@Nonnull HashTable hash_table, HashTable.OnHRFunc func, @Nullable Pointer user_data) Calls the given function for each key/value pair in the
#GHashTable. If the function returns %TRUE, then the key/value
pair is removed from the #GHashTable. If you supplied key or
value destroy functions when creating the #GHashTable, they are
used to free the memory allocated for the removed keys and values.
See #GHashTableIter for an alternative way to loop over the
key/value pairs in the hash table.- Parameters:
hash_table
- a #GHashTablefunc
- the function to call for each key/value pairuser_data
- user data to pass to the function- Returns:
- the number of key/value pairs removed
-
foreachSteal
public static int foreachSteal(@Nonnull HashTable hash_table, HashTable.OnHRFunc func, @Nullable Pointer user_data) Calls the given function for each key/value pair in the
#GHashTable. If the function returns %TRUE, then the key/value
pair is removed from the #GHashTable, but no key or value
destroy functions are called.
See #GHashTableIter for an alternative way to loop over the
key/value pairs in the hash table.- Parameters:
hash_table
- a #GHashTablefunc
- the function to call for each key/value pairuser_data
- user data to pass to the function- Returns:
- the number of key/value pairs removed.
-
getKeys
Retrieves every key inside @hash_table. The returned data is valid
until changes to the hash release those keys.
This iterates over every entry in the hash table to build its return value.
To iterate over the entries in a #GHashTable more efficiently, use a
#GHashTableIter.- Parameters:
hash_table
- a #GHashTable- 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
Retrieves every value inside @hash_table. The returned data
is valid until @hash_table is modified.
This iterates over every entry in the hash table to build its return value.
To iterate over the entries in a #GHashTable more efficiently, use a
#GHashTableIter.- Parameters:
hash_table
- a #GHashTable- 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
public static boolean insert(@Nonnull HashTable hash_table, @Nullable Pointer key, @Nullable Pointer value) Inserts a new key and value into a #GHashTable.
If the key already exists in the #GHashTable its current
value is replaced with the new value. If you supplied a
@value_destroy_func when creating the #GHashTable, the old
value is freed using that function. If you supplied a
@key_destroy_func when creating the #GHashTable, the passed
key is freed using that function.
Starting from GLib 2.40, this function returns a boolean value to
indicate whether the newly added value was already in the hash table
or not.- Parameters:
hash_table
- a #GHashTablekey
- a key to insertvalue
- the value to associate with the key- Returns:
- %TRUE if the key did not exist yet
-
lookup
Looks up a key in a #GHashTable. 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
g_hash_table_lookup_extended().- Parameters:
hash_table
- a #GHashTablekey
- the key to look up- Returns:
- the associated value, or %NULL if the key is not found
-
_new
Creates a new #GHashTable with a reference count of 1.
Hash values returned by @hash_func are used to determine where keys
are stored within the #GHashTable 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 is used when looking up keys in the #GHashTable.
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. @key_equal_func is called with the key from the hash table
as its first parameter, and the user-provided key to check against as
its second.- Parameters:
hash_func
- a function to create a hash value from a keykey_equal_func
- a function to check two keys for equality- Returns:
- a new #GHashTable
-
newFull
public static HashTable newFull(HashTable.OnHashFunc hash_func, HashTable.OnEqualFunc key_equal_func, HashTable.OnDestroyNotify key_destroy_func, HashTable.OnDestroyNotify value_destroy_func) Creates a new #GHashTable 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 #GHashTable.
Since version 2.42 it is permissible for destroy notify functions to
recursively remove further items from the hash table. This is only
permissible if the application still holds a reference to the hash table.
This means that you may need to ensure that the hash table is empty by
calling g_hash_table_remove_all() before releasing the last reference using
g_hash_table_unref().- Parameters:
hash_func
- a function to create a hash value from a keykey_equal_func
- a function to check two keys for equalitykey_destroy_func
- a function to free the memory allocated for the key used when removing the entry from the #GHashTable, 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 #GHashTable, or %NULL if you don't want to supply such a function.- Returns:
- a new #GHashTable
-
newSimilar
Creates a new #GHashTable like g_hash_table_new_full() with a reference
count of 1.
It inherits the hash function, the key equal function, the key destroy function,
as well as the value destroy function, from @other_hash_table.
The returned hash table will be empty; it will not contain the keys
or values from @other_hash_table.- Parameters:
other_hash_table
- Another #GHashTable- Returns:
- a new #GHashTable
-
ref
Atomically increments the reference count of @hash_table by one.
This function is MT-safe and may be called from any thread.- Parameters:
hash_table
- a valid #GHashTable- Returns:
- the passed in #GHashTable
-
remove
Removes a key and its associated value from a #GHashTable.
If the #GHashTable 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.- Parameters:
hash_table
- a #GHashTablekey
- the key to remove- Returns:
- %TRUE if the key was found and removed from the #GHashTable
-
removeAll
Removes all keys and their associated values from a #GHashTable.
If the #GHashTable 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.- Parameters:
hash_table
- a #GHashTable
-
replace
public static boolean replace(@Nonnull HashTable hash_table, @Nullable Pointer key, @Nullable Pointer value) Inserts a new key and value into a #GHashTable similar to
g_hash_table_insert(). The difference is that if the key
already exists in the #GHashTable, it gets replaced by the
new key. If you supplied a @value_destroy_func when creating
the #GHashTable, the old value is freed using that function.
If you supplied a @key_destroy_func when creating the
#GHashTable, the old key is freed using that function.
Starting from GLib 2.40, this function returns a boolean value to
indicate whether the newly added value was already in the hash table
or not.- Parameters:
hash_table
- a #GHashTablekey
- a key to insertvalue
- the value to associate with the key- Returns:
- %TRUE if the key did not exist yet
-
size
Returns the number of elements contained in the #GHashTable.- Parameters:
hash_table
- a #GHashTable- Returns:
- the number of key/value pairs in the #GHashTable.
-
steal
Removes a key and its associated value from a #GHashTable without
calling the key and value destroy functions.- Parameters:
hash_table
- a #GHashTablekey
- the key to remove- Returns:
- %TRUE if the key was found and removed from the #GHashTable
-
stealAll
Removes all keys and their associated values from a #GHashTable
without calling the key and value destroy functions.- Parameters:
hash_table
- a #GHashTable
-
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.- Parameters:
hash_table
- a valid #GHashTable
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-