Since this is a multiset, you want the hash value to be the same for the same multisets, the presentation of which can have the same elements, presented, added or deleted in a different order. Then you would like the hash value to be commutative, easily updated, and changed for each change in the elements. You would also like the two changes to not easily reverse their effect on the hash.
One operation, which corresponds to all but the last, is an addition. Just summarize the elements. To save a limited amount, sum the amount to the size of your hash value. (For example, modulo 2 64 for a 64-bit hash.) To make sure that inserting or deleting null values changes the hash, first add them to each value.
The disadvantage of this amount is that the two changes can be easily undone. For instance. replacing 1 3 with 2 2. To solve this, you can use the same approach and summarize the polynomial of entries, while maintaining commutativity. For instance. instead of summing x + 1, you can summarize x 2 + x + 1. Now it’s harder to come up with a lot of changes with the same amount.
source share