From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.acm.org>
Subject: Re: Ada.Containers Hash function for a set of small integers
Date: Fri, 23 Apr 2010 16:08:17 -0700
Date: 2010-04-23T16:08:17-07:00 [thread overview]
Message-ID: <hqt9ot$fm8$1@tornado.tornevall.net> (raw)
In-Reply-To: <m28w8dyhjr.fsf@pushface.org>
Michael R <michael@zanyblue.com> writes:
> I'd like to use the generic Hashed_Maps container to store mappings
> from a set of small integers (three) to Wide_Strings
> (Indefinite_Hashed_Maps):
>
> (1, 10, 4) => "ABC",
> (10, 3, 5) => "XYZ",
>
> Does anyone have recommendations on how best to implement the Hash
> function for keys like this?
What is the definition of "small"? If it has a defined range, for example:
subtype Small is Natural range Low .. High;
then you can define
Offset = 0 - Low
Max = High + Offset
and for X = # bits needed to represent Max, if 3 * X <=
Ada.Containers.Hash_Type'Size, then you can do a perfect hash:
type Triple is record
A : Small;
B : Small;
C : Small;
end record;
Hash (R : Triple) = Shift_Left (R.A + Offset, 2 * X) or
Shift_Left (R.B + Offset, X) or
(R.C + Offset)
--
Jeff Carter
"I was in love with a beautiful blonde once, dear.
She drove me to drink. That's the one thing I'm
indebted to her for."
Never Give a Sucker an Even Break
109
next prev parent reply other threads:[~2010-04-23 23:08 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-22 23:26 Ada.Containers Hash function for a set of small integers Michael R
2010-04-23 1:39 ` John B. Matthews
2010-04-23 21:39 ` Simon Wright
2010-04-23 22:47 ` Michael R
2010-04-24 11:28 ` Simon Wright
2010-04-26 18:37 ` Robert A Duff
2010-04-26 21:05 ` Simon Wright
2010-04-26 21:50 ` Adam Beneschan
2010-04-27 4:50 ` AdaMagica
2010-04-27 19:04 ` Simon Wright
2010-04-27 19:08 ` Simon Wright
2010-04-23 23:08 ` Jeffrey R. Carter [this message]
2010-04-26 15:33 ` Warren
2010-04-26 18:14 ` Jeffrey R. Carter
2010-04-26 18:32 ` Charmed Snark
2010-05-05 4:29 ` Yannick Duchêne (Hibou57)
2010-05-06 15:46 ` Warren
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox