3 ms·
FWIW, this magic is how the Linux kernel implements generic linked lists, hash tables, and red-black trees: https://stackoverflow.com/questions/15832301/unders
by xtacy 8y ago
FWIW, this magic is how the Linux kernel implements generic linked lists, hash tables, and red-black trees:
https://stackoverflow.com/questions/15832301/understanding-container-of-macro-in-the-linux-kernel https://stackoverflow.com/questions/15832301/understanding-c...
- paavoova 8y agoSo this would be hashing the pointer? In which case it doesn't support keys, like strings, etc. I'm now wondering if this is the more common use case for hash tables, where you just need a reference to a unique object rather than a specific key.
- taeric 8y agoJava has IdentityHashMap for this use. I hesitate to claim it is more common.
- xtacy 8y agoNo, that's not true. The insert function (hash, rbtree, etc.) takes a hash node as an argument. So, in the kernel implementation the caller is expected to hash. EDIT: check out some examples to see for yourself: https://elixir.bootlin.com/linux/latest/ident/hlist_add_head https://elixir.bootlin.com/linux/latest/ident/hlist_add_head