I'm trying to understand and use the kernel hash tables and I've already read this and this link, but I didn't understand none of them. My first question is: Why our struct has to have the struct h_list
inside it? If we're gonna access our struct through the struct h_list
our struct shouldn't be within struct h_list
and not the opposite? After reading the tutorial I've tried to write the following code:
DECLARE_HASHTABLE(nodes_hash, 3)hash_init(nodes_hash);struct h_node{ int data; char name[MAX_NAME_SIZE]; /*The key is the name of lua state*/ struct hlist_node node;};struct h_node a = { .data = 3, .name = "foo", .node = 0 };struct h_node b = { .data = 7, .name = "bar", .node = 0 }; hash_add(nodes_hash,&a.node, "foo");hash_add(nodes_hash,&b.node, "bar");
But this does not even compile. What I'm doing wrong? I need that the key be the same name present in the struct h_node
. So I would like that my hash table be like this:
PS: In my hash table it will never occur a collision (I'll handle it to never occur) so the key can be the name in the struct h_node