What is a good hash function for a collection (i.e., multi-set) of integers?

后端 未结 6 1303
不知归路
不知归路 2021-02-05 06:03

I\'m looking for a function that maps a multi-set of integers to an integer, hopefully with some kind of guarantee like pairwise independence.

Ideally, memory usage woul

6条回答
  •  耶瑟儿~
    2021-02-05 06:33

    The Knuth touches on this on TAoCP, and this is a near duplicate of What integer hash function are good that accepts an integer hash key?.

    For your situation, turning your multi-set into a single integer and then performing the hash described in the linked post may be what you want to do. Turning a collection into a number is trivial; a concatenation of the digits will do.

    For more info on Knuth's method, search for 'Knuth's Multiplicative Method'

    -tjw

提交回复
热议问题