comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen & Tammy House <house@ro.com>
To: Robert Grandy <grandyre@newton.ccs.tuns.ca>
Subject: Re: Looking for generic hash function
Date: 1996/08/16
Date: 1996-08-16T00:00:00+00:00	[thread overview]
Message-ID: <3215244B.4BBF@ro.com> (raw)
In-Reply-To: 4v23jd$mg9@News.Dal.Ca


Robert Grandy wrote:
> 
> Hello,
> 
> I am looking for a function that will return a random-type integer based
> on a generic parameter. What I have in mind is:
> 
> generic
>   type data_type is private;
> function get_data_id return Integer;

You could try taking in one step further with:
generic
  type data_type is private;
  type id is (<>);
function data_id (d : data_type) return id;

function data_id (d : data_type) return id is
  type integers is array (integer range <>) of integer;
  local_d : constant data_type := d;
  --alias I integer array to same location as local_d, basically
begin
  return --normalize sum of all I into id'range
end data_id;

I don't remember all the syntax of alises, and I'd have to work out the
conversion into the id'range, but this should work for big or small
data_type structures.  Of course, if data_type'size < integer'size,
you'll need to have an alternate plan going.  You might make a local
integer type based upon min(data_type'size, standard.integer'size) to
avoid this problem.




  parent reply	other threads:[~1996-08-16  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-08-16  0:00 Looking for generic hash function Robert Grandy
1996-08-16  0:00 ` Robert Dewar
1996-08-16  0:00 ` Stephen & Tammy House [this message]
1996-08-19  0:00 ` Robert I. Eachus
1996-08-21  0:00   ` Stephen & Tammy House
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox