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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:a0c:a541:: with SMTP id y59mr929843qvy.169.1579129793762; Wed, 15 Jan 2020 15:09:53 -0800 (PST) X-Received: by 2002:aca:4b46:: with SMTP id y67mr1890139oia.121.1579129793584; Wed, 15 Jan 2020 15:09:53 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!g89no874510qtd.0!news-out.google.com!w29ni1302qtc.0!nntp.google.com!g89no874508qtd.0!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 15 Jan 2020 15:09:53 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=70.109.61.2; posting-account=QF6XPQoAAABce2NyPxxDAaKdAkN6RgAf NNTP-Posting-Host: 70.109.61.2 References: <3c6f1486-293d-4eb5-a379-279b108248d8@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Tally From: Jere Injection-Date: Wed, 15 Jan 2020 23:09:53 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:57848 Date: 2020-01-15T15:09:53-08:00 List-Id: On Wednesday, January 15, 2020 at 4:03:14 AM UTC-5, Simon Wright wrote: > Brad Moore writes: > > > for Number of Input loop > > Counts (Number) := Counts (Number) + 1; > > end loop; > > for Number of Input loop > if Counts.Contains (Number) then > Counts (Number) := Counts (Number) + 1; > else > Counts.Insert (Number, 1); > end if; > end loop; > > and then of course > > for C in Counts.Iterate loop > Put_Line (Count_Maps.Key (C)'Image > & " -> " > & Count_Maps.Element (C)'Image); > end loop; I might recommend using insert every iteration and seeing if it fails or succeeds. Since it gives a cursor regardless of success, you can use that get the element and avoid doing all the searches each time: for Number of Input loop -- Try to insert a new element. This will -- fail if the element already exists Counts.Insert (Key => Number, New_Item => 1, Position => Position, Inserted => Inserted); -- Since the element already exists, simply -- increment the count if not inserted then Counts(Position) := Counts(Position) + 1; end if; end loop;