[英]GLib HashTable passing the functions as the parameters
I am learning the GLib GHashTable source code. 我正在学习GLib GHashTable源代码。 You can see the source code from the link here.
您可以从此处的链接中查看源代码。
https://github.com/GNOME/glib/blob/master/glib/ghash.c https://github.com/GNOME/glib/blob/master/glib/ghash.c
https://github.com/GNOME/glib/blob/master/glib/ghash.h https://github.com/GNOME/glib/blob/master/glib/ghash.h
GHashTable *g_hash_table_new (GHashFunc hash_func,
GEqualFunc key_equal_func)
g_hash_table_new function create the basic hash table here. g_hash_table_new函数在此处创建基本哈希表。 My question is the parameters.
我的问题是参数。 The first two parameters " GHashFunc hash_func, GEqualFunc key_equal_func " are passing to the function.
前两个参数“ GHashFunc hash_func,GEqualFunc key_equal_func ”传递给该函数。
In the ghash.h , there are no hash_func and key_equal_func, they are just symbols. 在ghash.h中 ,没有hash_func和key_equal_func,它们只是符号。 They will be replaced by the real hash functions.
它们将被实际的哈希函数代替。 How do the two functions become parameters here?
这两个函数如何成为参数?
I know there are some hash functions in ghash.h files, like: 我知道ghash.h文件中有一些哈希函数,例如:
guint g_int_hash (gconstpointer v)
guint g_str_hash (gconstpointer v)
Those functions will be passing to "g_hash_table_new " during the running time to replace "hash_func" and "key_equal_func ". 这些函数将在运行时传递给“ g_hash_table_new”,以替换“ hash_func”和“ key_equal_func”。 But I do not know what kind of technique is that?
但是我不知道那是什么技术? How to passing a function as a parameter to another function and replace it during the running time.
如何在运行期间将一个函数作为参数传递给另一个函数并替换它。
Thanks 谢谢
you pass param is a point, you define hash compute function. 您传递参数是一点,您定义哈希计算函数。 all function process is callback function.
所有函数过程都是回调函数。 hash table just pass param to your equel function.
哈希表只是将参数传递给您的equel函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.