Fast hash function for `std::vector`

后端 未结 2 1033
忘了有多久
忘了有多久 2020-12-30 12:29

I implemented this solution for getting an hash value from vector:

namespace std
{
    template
    struct hash

        
2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-30 13:19

    NOTE: As per the comments, you get a 25-50x speed-up by compiling with optimizations. Do that, first. Then, if it's still too slow, see below.


    I don't think there's much you can do. You have to touch all the elements, and that combination function is about as fast as it gets.

    One option may be to parallelize the hash function. If you have 8 cores, you can run 8 threads to each hash 1/8th of the vector, then combine the 8 resulting values at the end. The synchronization overhead may be worth it for very large vectors.

提交回复
热议问题