comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jeffrey.carter@boeing.com>
Subject: Re: Two Dimensional Array
Date: Fri, 15 Feb 2002 17:28:22 GMT
Date: 2002-02-15T17:28:22+00:00	[thread overview]
Message-ID: <3C6D4536.860B6EE5@boeing.com> (raw)
In-Reply-To: 3c6cf3db.11214605@news.demon.co.uk

Brian A Crawford wrote:
> 
> The code fragment shows the end result of my efforts so far.
> My problem is associating the values 1 or 0 to each cell of the array.
> By having the numbers 1 to 50 in numerical order the numbers 1 and 0
> are very haphazard placed and are difficult to define and update.
> 
> If the array was firstly defined as say 1,21,34,50,17,4, etc, 48,16
> then the 1 and 0 are placed together in the array and are very easy to
> associate quickly in groups of 5.
> Example
> Event :=  (1 => (1,1,1,1,1,0,0,0,0,0,1,1,1,1,1 etc
>         21 => (0,0,0,0,0,1,1,1,1,1,0,0,0,0,0, etc
>         34 => (0,0,0,0,0,0,0,0,0,0,1,1,1,1,1, etc
> and so on.
> 
> This is a code fragment.
>       Number1   : Integer;
>       Number2   : Integer;
> 
> subtype Firstevent is Integer range 1..50;
> subtype Secondevent is Integer range 1..50;
>       type Two_Events_Type is array (Firstevent, Secondevent) of
> Integer;
> Event : Two_Events_Type;
> 
> begin
>    --get input data
> 
>       Event :=   (0 =>
> (1,0,0,1,0,1,1,0,0,0,0,1,1,0,1,1,1,0,1,etc,0,1,0,1,1,1,0,0,1,1),
> 1=>(1,1,0,1,0,0,1,0,0,1,1,1,etc
> 2=> and so forth
> 
> as you can see the 1's and 0's are all over the place.
> How can I define subtypes FirstEvent and SecondEvent out of sequence?

First, since zero is not a value of Firstevent, you may have problems
with assigning this aggregate to Event.

Second, since the components of Two_Events_Type can only have the values
0 and 1, it is probably a good idea to specify this:

subtype Bit is Integer range 0 .. 1;
type Two_Events_Type is array (Firstevent, Secondevent) of Bit;

Third, since Event is a constant, it is probably a good idea to define
it as such:

Event : constant Two_Events_Type := (...);

Fourth, you probably ought to review ARM 4.3.3 on named array aggregates
and ARM 3.8.1 on discrete choices.

You can't define an out of order numeric (sub)type, but you can order
things any way you like in a named aggregate. So you can say

Event : constant Two_Events_Type :=
   (01 => (01 | 07 | 13 | ... => 0, others => 1),
    02 => (...),
    ...);

> 
> Secondly then can I make an abbreviation to the array referencing eg
> if AN is the sequence of 5 x 1's at {3,4,5,6,7} and BN is  is the
> sequence of 5 x 1's at {17,18,19,20,21} position and similar for CN DN
> EN etc how may I use that abbreviation in some way like this?
> 
> Event := (0 => (AN, BN, others => 0),
>         21 => (CN, others =>0),
>         34 => (DN, AN, CN, others 0)) etc

No, but a named aggregate has the same effect.

-- 
Jeffrey Carter



  reply	other threads:[~2002-02-15 17:28 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-15 12:30 Two Dimensional Array Brian A Crawford
2002-02-15 17:28 ` Jeffrey Carter [this message]
2002-02-15 18:15 ` Stephen Leake
2002-02-15 22:50   ` Brian A Crawford
2002-02-16  2:05     ` Mike Silva
2002-02-16  9:38       ` Brian A Crawford
2002-02-23 13:36         ` Nick Roberts
replies disabled

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