[swift-evolution] Pluggable hash algorithm for containers

Dmitri Gribenko gribozavr at gmail.com
Thu Dec 3 22:29:06 CST 2015

On Thu, Dec 3, 2015 at 4:14 PM, Ray Fix <rayfix at gmail.com> wrote:
> 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
> A live presentation is here: 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.

Hi Ray,

A prototype is here (written before Howard's talk, so it probably uses
different terms):


However, I couldn't make it interoperate with NSObject.hash in both
directions: you should be able to override 'var hash' and get an
implementation of Hashable based on that, and vice versa.  It could be
solvable with protocol extensions now, I haven't looked at that
prototype for more than a year -- help and patches appreciated.


(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/

More information about the swift-evolution mailing list