From: Simon Wright <simon@pushface.org>
Subject: Re: Tally
Date: Wed, 15 Jan 2020 11:52:56 +0000
Date: 2020-01-15T11:52:56+00:00 [thread overview]
Message-ID: <lyk15tym07.fsf@pushface.org> (raw)
In-Reply-To: lysgkiymkc.fsf@pushface.org
Simon Wright <simon@pushface.org> writes:
> The Booch Components included Bags, which would solve this directly!
> (not that I'd recommend anyone to use the BCs for a new project)
This is what it'd look like (it's a lot uglier in Ada 95, because the
containers and iterators, while tagged, can't use dotted notation).
Sorry about the silly Hash function.
with BC.Containers.Bags.Unmanaged;
with Ada.Text_IO; use Ada.Text_IO;
procedure Main
is
package Abstract_Containers is new BC.Containers (Natural);
package Abstract_Bags is new Abstract_Containers.Bags;
function Hash (N : Natural) return Natural is (N);
package Bags is new Abstract_Bags.Unmanaged
(Buckets => 43,
Hash => Hash);
type Input_Data is array (Natural range <>) of Natural;
Input : Input_Data := (2, 3, 8, 2, 2, 2, 7, 2, 3, 4, 8);
Counts : Bags.Bag;
begin
for Number of Input loop
Counts.Add (Number);
end loop;
declare
It : Abstract_Containers.Iterator'Class := Counts.New_Iterator;
begin
while not It.Is_Done loop
Put_Line (It.Current_Item'Image
& " -> "
& Counts.Count (It.Current_Item)'Image);
It.Next;
end loop;
end;
end Main;
next prev parent reply other threads:[~2020-01-15 11:52 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-14 15:27 Tally Gilbert Gosseyn
2020-01-14 16:22 ` Tally Niklas Holsti
2020-01-14 17:28 ` Tally Simon Wright
2020-01-15 11:52 ` Simon Wright [this message]
2020-01-14 21:08 ` Tally Jeffrey R. Carter
2020-01-15 3:40 ` Tally Brad Moore
2020-01-15 9:03 ` Tally Simon Wright
2020-01-15 23:09 ` Tally Jere
2020-01-16 11:34 ` Tally Simon Wright
2020-01-16 15:35 ` Tally Brad Moore
2020-01-16 20:20 ` Tally Randy Brukardt
2020-01-16 22:03 ` Tally Jeffrey R. Carter
2020-01-16 22:00 ` Tally Jeffrey R. Carter
2020-01-16 22:25 ` Tally Simon Wright
2020-01-17 2:51 ` Tally Brad Moore
2020-01-17 3:08 ` Tally Brad Moore
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox