From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,76e8d825615718a X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nntp.club.cc.cmu.edu!feeder.erje.net!news2.arglkargh.de!news.swapon.de!eternal-september.org!.POSTED!not-for-mail From: Warren Newsgroups: comp.lang.ada Subject: Re: Ada.Containers Hash function for a set of small integers Date: Mon, 26 Apr 2010 15:33:03 +0000 (UTC) Organization: A noiseless patient Spider Message-ID: References: <50701baa-7c05-450c-a42d-c699516ddc00@t14g2000prm.googlegroups.com> Injection-Date: Mon, 26 Apr 2010 15:33:03 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="9f8M0iN5t54V+4DF/iqO8g"; logging-data="23050"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19xfffzrfXjORiNh8e4gdMHvbzybliE9Jk=" User-Agent: Xnews/5.04.25 X-Face: &6@]C2>ZS=NM|HE-^zWuryN#Z/2_.s9E|G&~DRi|sav9{E}XQJb*\_>=a5"q]\%A;5}LKP][1mA{gZ,Q!j Cancel-Lock: sha1:0fCzL5efkQEADfAdHxCgp3BZVGc= Xref: g2news2.google.com comp.lang.ada:11183 Date: 2010-04-26T15:33:03+00:00 List-Id: Simon Wright expounded in news:m28w8dyhjr.fsf@pushface.org: .. > for use with Booch Maps, where the key components of Instance are > {A:Integer, B:Integer, C:Integer}: > > function Instance_Hash (I : Instance) return Natural is > type M is mod 2**31; > Result : M := 0; > begin > Result := Result xor M (I.A mod 2**31); > Result := Result * 10019; > Result := Result xor M (I.B mod 2**31); > Result := Result * 10019; > Result := Result xor M (I.C mod 2**31); > Result := Result * 10019; > return Natural (Result); > end Instance_Hash; > > I believe the 10019 came from Knuth, but can't see a reference. I think this is just a selected prime number: http://www.mathematical.com/primes3000kto4000k.html Probably a compromise between "wideness" and memory used in the map itself (affects number of buckets perhaps). Warren.