comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jeffrey.carter@boeing.com>
Subject: Re: Parallel Merge Sort
Date: Mon, 18 Feb 2002 22:29:36 GMT
Date: 2002-02-18T22:29:36+00:00	[thread overview]
Message-ID: <3C718050.7CE63E36@boeing.com> (raw)
In-Reply-To: a4rq83$cis$1@star.cs.vu.nl

"R. Stegers" wrote:
> 
> Maybe someone can help me solve one final little issue.
> 
> The parallel Merge Sort works fine now. But when I want to use it I cannot
> directly declare for example an integer array:
> 
>   package IntSort is new SORT_PACKAGE(integer, compareInt);
>   use IntSort;
> 
>   -- This declaration does not work when I want to use ar as a parameter in
> a call to Sort.
>   ar : integer array(1..3);

This is invalid Ada. You might be trying to say

Ar : array (1 .. 3) of Integer;

Now Ar is of an anonymous array type. Since procedure Sort requires a
variable of type Element_Array, obviously this variable won't work.

> 
>   -- Instead I have to use this.
>   ar : IntSort.element_array(1.. 3);

This Ar has the correct type, which is why it works.

If your package were defined as

generic
   type Element is private;
   type Element_Array is array (Positive range <>) of Element;
...

Then you could write

type Integer_Array is array (Positive range <>) of Integer;

package Sort is new Sort_Package (Element => Integer, Element_Array =>
Integer_Array, ...);

Ar : Integer_Array (1 .. 3);

...

Sort.Sort (Inarray => Ar);

Even better might be

generic
   type Element is private;
   type Index is (<>);
   type Element_Array is array (Index range <>) of Element;
...

Then your instantiation would read

package Sort is new Sort_Package
   (Element => Integer, Index => Positive, Element_Array =>
Integer_Array);

However, I suspect you would have to modify most of your use of indices
in Sort_Package if you did this.

-- 
Jeffrey Carter



  reply	other threads:[~2002-02-18 22:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-15 21:34 Parallel Merge Sort R. Stegers
2002-02-15 21:46 ` Pat Rogers
2002-02-19  6:16   ` Adrian Hoe
2002-02-19  6:21   ` Adrian Hoe
2002-02-15 23:02 ` tmoran
2002-02-16 11:09   ` R. Stegers
2002-02-18 10:22     ` Peter Hermann
2002-02-18 20:41       ` R. Stegers
2002-02-18 21:02   ` R. Stegers
2002-02-18 22:29     ` Jeffrey Carter [this message]
2002-02-18 22:55     ` tmoran
2002-02-19 21:46   ` Kenneth Almquist
2002-02-24  3:22 ` Nick Roberts
2002-02-26 20:39   ` R. Stegers
replies disabled

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