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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED.8dY8omnix++EB5/QBRk4Sw.user.gioia.aioe.org!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Tally Date: Thu, 16 Jan 2020 11:34:55 +0000 Organization: Aioe.org NNTP Server Message-ID: References: <3c6f1486-293d-4eb5-a379-279b108248d8@googlegroups.com> NNTP-Posting-Host: 8dY8omnix++EB5/QBRk4Sw.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (darwin) Cancel-Lock: sha1:ahKMQhWsHUJQFBW1cVG8wgTQBwU= X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader01.eternal-september.org comp.lang.ada:57850 Date: 2020-01-16T11:34:55+00:00 List-Id: Jere writes: > 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; Yes, I thought about that. More LoC/less clarity without the comments are the only objections I can see (though fairly compelling for toy examples!)