3 ms·
Why would one need to hash pointers? Seems like a bad idea and data strutures made of pointers like trees are pretty well behaved.
by anfilt 8y ago
Why would one need to hash pointers? Seems like a bad idea and data strutures made of pointers like trees are pretty well behaved.
- xamuel 8y agoSay you have an array of pointers and you want to take its distinct members. For each pointer, you could look up its hash in a table. If it's not there, you can be sure the pointer hasn't been seen before: append it to your result and put its hash in the table. If the hash is there, you learn nothing since it could be a collision, and you'll need to do something else (like iterate through your whole result so far). But if the original input has few distinct members, this shouldn't happen often.
- anfilt 8y agoYea a list of pointers can be handy. However, if the code managing this list is receiving duplicate pointers this sounds like an other problem. If it's newly allocated memory it should probably be submitted to this list on creation. If we have some sort sub-allocater that sounds like a problem with sub-allotments. I think is probably more common ways to avoid the need for hashing, and not needing to do a linear search of your list.
- rurban 8y agocloning trees, garbage collection, serialization on structures with references. graphs.