Getting the hash of any value easily?
H. S. Teoh via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jul 31 12:40:30 PDT 2014
On Thu, Jul 31, 2014 at 07:08:16PM +0000, Brian Schott via Digitalmars-d wrote:
> On Thursday, 31 July 2014 at 17:39:43 UTC, H. S. Teoh via Digitalmars-d
> wrote:
> >It's about time somebody noticed this!!
> >
> >Why don't we just expose druntime's core.internal.hash.hashOf()
> >function somewhere? It's not as though it isn't already in druntime,
> >so the function is already present in the executable, we just need a
> >public declaration of it somewhere that users can make use of.
> >
> >Not to mention, it's already a template function that correctly
> >calculates the hash of various built-in types.
> >
> >
> >T
>
> I've often just put "import core.internal.hash;" in my code.
>
> Once we get this solved we need to work on the fact that many hash
> generation functions are not pure.
I'm not sure I understand why. Un- at safe (probably should be @trusted) I
can understand, since you basically have to treat arbitrary typed data
as ubyte[] in order to compute the hash, but impure? I don't see it. The
definition of hash function requires that its output depend only on its
input(s), so why can't it be pure?
> (Object.toHash not being pure prevents a lot of containers from being
> used in pure templated code)
Yeah, this is one of the things that prompted us to move towards
removing toHash from Object.
T
--
Spaghetti code may be tangly, but lasagna code is just cheesy.
More information about the Digitalmars-d
mailing list