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-Thread: 103376,703c4f68db81387d X-Google-Thread: 109fba,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Thread: f43e6,703c4f68db81387d X-Google-Attributes: gid103376,gid109fba,gid115aec,gidf43e6,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!proxad.net!gatel-ffm!gatel-ffm!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!news.arcor.de!not-for-mail Date: Tue, 22 Mar 2005 10:49:25 +0100 From: Georg Bauhaus User-Agent: Debian Thunderbird 1.0 (X11/20050116) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada,comp.lang.c++,comp.realtime,comp.software-eng Subject: Re: Teaching new tricks to an old dog (C++ -->Ada) References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <1110032222.447846.167060@g14g2000cwa.googlegroups.com> <871xau9nlh.fsf@insalien.org> <3SjWd.103128$Vf.3969241@news000.worldonline.dk> <87r7iu85lf.fsf@insalien.org> <1110052142.832650@athnrd02> <1110284070.410136.205090@o13g2000cwo.googlegroups.com> <395uqaF5rhu2mU1@individual.net> <1110329098.642196@athnrd02> <1110361741.551255@athnrd02> <422edaec$0$26554$9b4e6d93@newsread4.arcor-online.net> <1111464133.508323@athnrd02> In-Reply-To: <1111464133.508323@athnrd02> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <423fe9df$0$11476$9b4e6d93@newsread2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 22 Mar 2005 10:48:15 MET NNTP-Posting-Host: 99406d1e.newsread2.arcor-online.net X-Trace: DXC=f\mhW@DKPko^O_h>VFi7[bQ5U85hF6f;djW\KbG]kaMh]kI_X=5Keaf<[nmYnX2?PjhP3YJKgE\jlMkJlfM<=nbd X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:9717 comp.lang.c++:46664 comp.realtime:1582 comp.software-eng:5183 Date: 2005-03-22T10:48:15+01:00 List-Id: Ioannis Vranos wrote: > adaworks@sbcglobal.net wrote: > >> OK. Try this in straight C++. >> type Index is range -800_000..12_000_000; >> type Decimal_Fraction is digits 12 range -473.0 .. 2_000.0; >> >> type Vector is array (Index range <>) of Decimal_Fraction; >> >> V1 : Vector ( -47..600); -- note the negative index range >> function Scan (The_Vector : Vector ; Scan_Value : >> Decimal_Fraction ) >> return Natural; >> for I in The_Vector'Range -- No way to index off the > I think you mean something like: [redesigning the problem?] > map id; > > id[-400]= 7.1; > for(map::const_iterator p= id.begin(); p!=id.end(); ++p) > I think this is even faster than yours, which scans the entire range. Hm. Searching a *map* of entries at numeric keys is different from scanning an array of values and counting occurences. What are you trying to do here? The std::vector is missing an instantiation argument which adds the guarantee that no index value is outside the range -800_000..12_000_000; std::map is a different beast entirely, with unknown size. Consider Vector ( -47..600); (How do you make a subrange of double, which is missing from your example.) Imagine an array shared between a number of threads. The program's task is to count the number of occurences of a particular value in the array. Examples: 1) A shop has 10 unique doors (use an enum). For each door 4 states can be measured: open/closed, van/no van at the door. 2) A 5-player team, each team is identified by number drawn from a fixed set of team numbers. An array (an array, not some other data structure) measures the number of players from each team present in a room. Count the number of odd-team players in a room. I hope these example illustrate some points. They are not meant to trigger a discussion as to whether an array is the best data structure for everything. (Note that it might be necessary to read values from the array/Vector using random access in O(1), and to store and replace values in O(1), another reason to use an array.) > And a more elegant and with the same efficiency solution: A solution to a different problem, I think. > In C++ you can create whatever you want. Even a container with abstract > conceptual features (you are limited only by your imagination). You can do that using assembly language or SmallTalk, whatever. I think this was not the point, but I should have Richard Riehle's message speak for itself. For example, look here, and reconsider the programming task as originally stated: >> Yes, I know you can do this in C++, but >> from my >> perspective, it is not nearly as easy, expressive, or readable. Georg