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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9c8d43df5d883263 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-02-23 05:35:56 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!ppp-3-97.5800-12.telinco.NET!not-for-mail From: nickroberts@ukf.net (Nick Roberts) Newsgroups: comp.lang.ada Subject: Re: Two Dimensional Array Date: Sat, 23 Feb 2002 13:36:05 GMT Message-ID: <3c778671.310328464@news.cis.dfn.de> References: <3c6cf3db.11214605@news.demon.co.uk> <3c6d8b32.18156525@news.demon.co.uk> <27085883.0202151805.2c557ce7@posting.google.com> <3c6e2709.601229@news.demon.co.uk> NNTP-Posting-Host: ppp-3-97.5800-12.telinco.net (212.1.142.97) X-Trace: fu-berlin.de 1014471355 5647807 212.1.142.97 (16 [25716]) X-Newsreader: Forte Free Agent 1.21/32.243 Xref: archiver1.google.com comp.lang.ada:20294 Date: 2002-02-23T13:36:05+00:00 List-Id: Brian, I can give you an idea that you may or may not find useful. If you have an array that you would like to index in some arbitrary order, e.g.: Data Array Index: 23 14 3 10 27 13 12 20 21 2 19 ... Value: 0 0 0 0 0 1 1 1 1 1 0 ... The 'classic' way to do this is with a 'mapping' array, e.g.: Mapping Array Index: 23 14 3 10 27 13 12 20 21 2 19 ... Value: 1 2 3 4 5 6 7 8 9 10 11 ... This array 'maps' 23 -> 1, 14 -> 2, 3 -> 3, 10 -> 4, and so on. In Ada, the mapping array could be defined as follows: type Index_Type is range 1..50; Map: constant array (Index_Type) of Index_Type := ( 23 => 1, 14 => 2, 3 => 3, 10 => 4, 27 => 5, 13 => 6, 12 => 6 20 => 8, ........... ); You could then declare an array convenient for declaring the data: Data: constant array (Index_Type) of Bit := ( 1.. 5 => 0, 6..10 => 1, 11..15 => 0, 16..20 => 1, 21..25 => 0, 26..30 => 0, 31..35 => 1, 36..40 => 1, 41..45 => 1, 46..50 => 0 ); You could then construct the actual array you need using the map: Work: array (Index_Type) of Bit; procedure Initialize_Work is begin for i in Work'Range loop Work(i) := Data(Map(i)); end loop; end; The 'tricky' bit here is how the Map array is used to generate an index for indexing the Data array [Data(Map(i))]. It is important that you study this construct until you understand how it works. After Initialize_Work is called, the array Work will contain the bits in the places they really should be. Hope this helps. You might be interested that this particular kind of map is called a 'bijection'. A bijection is a mapping that is both an 'injection' and a 'surjection'. In simple terms, an injection is a mapping which never maps to the same thing twice, and a surjection is a mapping that is complete. In order to help ensure that you have not made a mistake, you may wish to write procedures that check the Map array for being an injection and a surjection. I'll leave how to code these tests as an exercise! -- Nick Roberts