Hash value of NSDictionary

后端 未结 5 1839
温柔的废话
温柔的废话 2020-12-30 07:54

I ran into an issue, where I got the same hash value for different dictionaries. Maybe I\'m doing something obvious wrong, but I thought, objects with different content (a.k

5条回答
  •  囚心锁ツ
    2020-12-30 08:47

    The function 'hash' is not a real hash function. It gives different values for strings (all predictable) but for collections (arrays and dictionaries) it just returns the count. If you want a unique hash you can calculate it yourself using primes, or the functions srandom() and random() or explore a real hash function like SHA1 available in CommonCrypto/CommonDigest.h

提交回复
热议问题