Hash an arbitrary precision value (boost::multiprecision::cpp_int)

后端 未结 2 1770
余生分开走
余生分开走 2020-11-28 15:53

I need to get the hash of value with arbitrary precision (from Boost.Multiprecision); I use the cpp_int backend. For now, I came up with the following code:

         


        
2条回答
  •  孤街浪徒
    2020-11-28 16:24

    Just to say that I've just added native hashing support (for Boost.Hash and std::hash) to git develop. It works for all the number types including those from GMP etc. Unfortunately that code won't be released until Boost-1.62 now.

    The answer above that (ab)uses serialization support, is actually extremely cool and really rather clever ;) However, it wouldn't work if you wanted to use a vector-based hasher like CityHash, I added an example of using that by accessing the limbs directly to the docs: https://htmlpreview.github.io/?https://github.com/boostorg/multiprecision/blob/develop/doc/html/boost_multiprecision/tut/hash.html Either direct limb-access or the serialization tip will work with all previous releases of course.

提交回复
热议问题