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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,16016085da246cdf X-Google-Attributes: gid103376,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: Looking for generic hash function Date: 1996/08/19 Message-ID: #1/1 X-Deja-AN: 175177006 references: <4v23jd$mg9@News.Dal.Ca> organization: The Mitre Corp., Bedford, MA. newsgroups: comp.lang.ada Date: 1996-08-19T00:00:00+00:00 List-Id: In article <4v23jd$mg9@News.Dal.Ca> grandyre@newton.ccs.tuns.ca (Robert Grandy) writes: > The function would return a pretty much random Integer based on its > generic parameter. I was thinking of using the 'size attribute, but > does anyone have any other suggestions. This is one case where I wouldn't complain about someone converting a value of type System.Address to an Integer (assuming Ada 95): with System.Storage_Elements; function get_data_id return Integer is Foo: Integer; begin return Integer(System.Storage_Elements.To_Integer(Foo'ADDRESS)); exception when others => return Integer(System.Storage_Elements.To_Integer(Foo'ADDRESS) mod System.Storage_Elements.Integer_Address(Integer'LAST)); -- this return statement can only raise an exception when the -- previous one does not. end get_data_id; Note that, if Integer is 32-bits then every instance will create its own return value. And if all instances are at library level and one per type, then the value returned for a particular type will be unique within the partition. If this is not what you are looking for there are other variants. Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is... -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...