OvS: data structure analysis

时间:2022-01-20 23:41:29

hmap usage:

in include/openvswitch/shash.h, we have:

OvS: data structure analysis

at first glance, it is a hmap encapsulated in shash.

In case we forget what is a hmap:

OvS: data structure analysis

OvS: data structure analysis

Obviously, it is the simplist hash map linked list. The mask means the max-hash value, the n means the total number of hashed members saved in hmap. Buckets[i] all have same hash value according to mask.

When we save key-value things, first put it in a shash_node, together with hmap_node inside it, push the hmap_node to the hmap hash linked list defined inside shash. When we search for search value of a key, gen key's hash and find in the hmap inside shash, get the hmap_node, CONTAINER_OF the hmap_node is the shash_node, then shash_node->name, shash_node->data is reachable.