[swift-evolution] Pluggable hash algorithm for containers

Ray Fix rayfix at gmail.com
Thu Dec 3 18:14:36 CST 2015


Last year, Howard Hinnant proposed a composable hash algorithm framework for C++ that I was impressed with.

His proposal is here: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3980.html <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3980.html>
A live presentation is here: https://www.youtube.com/watch?v=Njjp_MJsgt8 <https://www.youtube.com/watch?v=Njjp_MJsgt8>

A type with multiple fields you inevitably want to do a hash_combine but this pollutes the hashing algorithm.  It turns out that (nearly) all hashing algorithms can be abstracted into 3 phases: initialization, digestion and finalization.  It might be cool if Swift Hashable adopted this pluggable architecture.  

1. Easily adopt Hashable
2. Easily change and compare hash algorithms based on performance / security needs
3. Make good hash implementations trivial for users.

Wondering if anyone has thought about this already / if it would be worthwhile pursuing more.

Best wishes,
Ray

PS:  I have always thought that it is a bummer that compound types such as tuples can’t conform to protocols and therefore be Hashable.  

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151203/5717295b/attachment-0001.html>


More information about the swift-evolution mailing list