From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Hash Type Size
Date: Mon, 19 Aug 2013 17:29:19 -0500
Date: 2013-08-19T17:29:19-05:00 [thread overview]
Message-ID: <kuu680$lva$1@loke.gir.dk> (raw)
In-Reply-To: kuu5q4$ls7$1@loke.gir.dk
I said:
...
> There's not much point anyway; you can't directly hash 32-bit signed
> integers in a 32-bit hash value without resorting to Unchecked_Conversion,
> and then you've already completely left the realm of safe and portable
> (neither Integer nor Hash_Type has a defined size by the RM).
I just remembered that you could use the 'Mod attribute function to do this
conversion. But of course that doesn't depend on the size of the type of
it's argument, so it will work on Integer (for instance) no matter what size
Integer has.
Doing so will eliminate the uppermost bits from the hash in some cases, but
that's usually not a problem as values rarely get anywhere near as large as
the maximum possible. (Hopefully, your types have ranges so you know for
sure.)
If you're actually using all 64-bits of an integer (and hopefully you are
declaring that explicitly, so compilers that don't support it can reject
it), then you'll have to use Unchecked_Conversion or streaming to convert it
into something hashable. Which I still think is the best idea in 99% of the
cases.
Randy.
next prev parent reply other threads:[~2013-08-19 22:29 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-18 21:05 Hash Type Size sbelmont700
2013-08-19 1:03 ` AdaMagica
2013-08-19 22:21 ` Randy Brukardt
2013-08-19 22:29 ` Randy Brukardt [this message]
2013-08-19 22:12 ` Randy Brukardt
2013-08-31 6:22 ` Peter Brooks
2013-08-31 15:57 ` sbelmont700
2013-09-03 1:47 ` Randy Brukardt
2013-09-03 2:31 ` Peter Brooks
2013-09-03 10:50 ` John B. Matthews
2013-09-03 17:18 ` Peter Brooks
2013-09-03 21:21 ` John B. Matthews
2013-09-04 4:50 ` Paul Rubin
2013-09-04 4:54 ` Paul Rubin
2013-09-05 19:30 ` John B. Matthews
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox