* Shootout: Word Frequency
@ 2005-04-14 1:28 Jeffrey Carter
2005-04-14 8:08 ` Martin Dowie
0 siblings, 1 reply; 7+ messages in thread
From: Jeffrey Carter @ 2005-04-14 1:28 UTC (permalink / raw)
There have been some postings a solution to this in Ada, but I've only
now had a chance to check out the problem. I see that the Ada solution
is 168 LOC and 111 terminator semicolons. I'd be interested to know how
it compares to this version, which I posted here some time ago in
response to something else (some lines may wrap):
with Ada.Characters.Handling;
with Ada.Text_IO;
with Word_Count_Help;
procedure Word_Count is
use Ada.Characters.Handling;
use Ada.Text_IO;
use Word_Count_Help;
Word : Word_Input.Word;
Result : Word_Search.Result;
Set : Word_Search.Skip_List;
Item : Word_Info;
begin -- Word_Count
All_Words : loop
exit All_Words when End_Of_File;
Word_Input.Get (Word);
Item.Word := +To_Lower (+Word);
Result := Word_Search.Search (Set, Item);
if Result.Found then
Item.Count := Result.Item.Count + 1;
else
Item.Count := 1;
end if;
Word_Search.Insert (List => Set, Item => Item);
end loop All_Words;
Sort_Words : declare
type Context_Info is record
Index : Positive := 1;
List : Word_List (1 .. Word_Search.Length (Set) );
end record;
procedure Word_To_List (Item : in Word_Info; Context : in out
Context_Info; Continue : out Boolean) is
-- null;
begin -- Word_To_List
Continue := True;
Context.List (Context.Index) := Item;
Context.Index := Context.Index + 1;
end Word_To_List;
procedure Set_To_List is new Word_Search.Iterate (Context_Data =>
Context_Info, Action => Word_To_List);
Context : Context_Info;
begin -- Sort_Words
Set_To_List (List => Set, Context => Context);
Sort (Set => Context.List);
Output : for I in Context.List'range loop
Put_Line (Item => +Context.List (I).Word & Integer'Image
(Context.List (I).Count) );
end loop Output;
end Sort_Words;
end Word_Count;
with PragmARC.Assignment;
with PragmARC.Skip_List_Unbounded;
with PragmARC.Sort_Quick_In_Place;
with PragmARC.Word_Input;
package Word_Count_Help is
package Word_Input is new PragmARC.Word_Input;
function "+" (Right : Word_Input.Word) return String renames
Word_Input.V_String.To_String;
function "+" (Right : String) return Word_Input.Word;
type Word_Info is record
Word : Word_Input.Word;
Count : Natural := 0;
end record;
function "<" (Left : Word_Info; Right : Word_Info) return Boolean;
function ">" (Left : Word_Info; Right : Word_Info) return Boolean;
function "=" (Left : Word_Info; Right : Word_Info) return Boolean;
type Word_List is array (Positive range <>) of Word_Info;
procedure Assign is new PragmARC.Assignment (Element => Word_Info);
procedure Sort is new PragmARC.Sort_Quick_In_Place (Element =>
Word_Info, Index => Positive, Sort_Set => Word_List, "<" => ">");
package Word_Search is new PragmARC.Skip_List_Unbounded (Element =>
Word_Info);
end Word_Count_Help;
package body Word_Count_Help is
use type Word_Input.V_String.Bounded_String;
function "+" (Right : String) return Word_Input.Word is
-- null;
begin -- "+"
return Word_Input.V_String.To_Bounded_String (Right);
end "+";
function "<" (Left : Word_Info; Right : Word_Info) return Boolean is
-- null;
begin -- "<"
return Left.Word < Right.Word;
end "<";
function ">" (Left : Word_Info; Right : Word_Info) return Boolean is
-- null;
begin -- ">"
if Left.Count = Right.Count then
return Left.Word < Right.Word;
else
return Left.Count > Right.Count;
end if;
end ">";
function "=" (Left : Word_Info; Right : Word_Info) return Boolean is
-- null;
begin -- "="
return Left.Word = Right.Word;
end "=";
end Word_Count_Help;
which is 115 SLOC and 64 terminator semicolons. It could perhaps be sped
up by not checking End_Of_File and handling End_Error instead.
--
Jeff Carter
"Apart from the sanitation, the medicine, education, wine,
public order, irrigation, roads, the fresh water system,
and public health, what have the Romans ever done for us?"
Monty Python's Life of Brian
80
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Shootout: Word Frequency
2005-04-14 1:28 Shootout: Word Frequency Jeffrey Carter
@ 2005-04-14 8:08 ` Martin Dowie
2005-04-14 19:09 ` Jeffrey Carter
0 siblings, 1 reply; 7+ messages in thread
From: Martin Dowie @ 2005-04-14 8:08 UTC (permalink / raw)
Jeffrey Carter wrote:
> which is 115 SLOC and 64 terminator semicolons. It could perhaps be
> sped up by not checking End_Of_File and handling End_Error instead.
Unless PragmARC is distributed as part of Debian, aren't you going to
have to count those lines too?...
Cheers
-- Martin
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Shootout: Word Frequency
2005-04-14 8:08 ` Martin Dowie
@ 2005-04-14 19:09 ` Jeffrey Carter
2005-04-14 20:41 ` Martin Dowie
0 siblings, 1 reply; 7+ messages in thread
From: Jeffrey Carter @ 2005-04-14 19:09 UTC (permalink / raw)
Martin Dowie wrote:
> Unless PragmARC is distributed as part of Debian, aren't you going to
> have to count those lines too?...
I would think one should only have to count that code written to solve
the problem; the PragmARCs used were all originally developed prior to
1992 ...
--
Jeff Carter
"Death awaits you all, with nasty, big, pointy teeth!"
Monty Python & the Holy Grail
20
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Shootout: Word Frequency
2005-04-14 19:09 ` Jeffrey Carter
@ 2005-04-14 20:41 ` Martin Dowie
2005-04-15 1:01 ` Jeffrey Carter
2005-04-15 7:52 ` Ludovic Brenta
0 siblings, 2 replies; 7+ messages in thread
From: Martin Dowie @ 2005-04-14 20:41 UTC (permalink / raw)
Jeffrey Carter wrote:
> Martin Dowie wrote:
>
>> Unless PragmARC is distributed as part of Debian, aren't you going to
>> have to count those lines too?...
>
>
> I would think one should only have to count that code written to solve
> the problem; the PragmARCs used were all originally developed prior to
> 1992 ...
I agree and the FAQ on the shootout page doesn't say anything on the
matter. But I guess that if you have to provide the shootout team
with the package then they are going to count them too.
Perhaps Ludovic could package them up and get them into Debian? I see
that AdaBrowse has made it in...
http://packages.debian.org/unstable/devel/
Cheers
-- Martin
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Shootout: Word Frequency
2005-04-14 20:41 ` Martin Dowie
@ 2005-04-15 1:01 ` Jeffrey Carter
2005-04-15 7:52 ` Ludovic Brenta
1 sibling, 0 replies; 7+ messages in thread
From: Jeffrey Carter @ 2005-04-15 1:01 UTC (permalink / raw)
Martin Dowie wrote:
> I agree and the FAQ on the shootout page doesn't say anything on the
> matter. But I guess that if you have to provide the shootout team
> with the package then they are going to count them too.
It's only an issue if my version is also significantly faster than the
existing one, which I find unlikely.
--
Jeff Carter
"Death awaits you all, with nasty, big, pointy teeth!"
Monty Python & the Holy Grail
20
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Shootout: Word Frequency
2005-04-14 20:41 ` Martin Dowie
2005-04-15 1:01 ` Jeffrey Carter
@ 2005-04-15 7:52 ` Ludovic Brenta
2005-04-15 10:30 ` Martin Dowie
1 sibling, 1 reply; 7+ messages in thread
From: Ludovic Brenta @ 2005-04-15 7:52 UTC (permalink / raw)
Martin Dowie wrote...
> Jeffrey Carter wrote:
> > Martin Dowie wrote:
> >
> >> Unless PragmARC is distributed as part of Debian, aren't you going to
> >> have to count those lines too?...
> >
> >
> > I would think one should only have to count that code written to solve
> > the problem; the PragmARCs used were all originally developed prior to
> > 1992 ...
>
> I agree and the FAQ on the shootout page doesn't say anything on the
> matter. But I guess that if you have to provide the shootout team
> with the package then they are going to count them too.
>
> Perhaps Ludovic could package them up and get them into Debian? I see
> that AdaBrowse has made it in...
More to the point, Charles has made it in :)
I have already stated that I am unwilling to do more packaging than I
already do. That said, if several Debian users request a particular
package, I will reconsider. So, if anyone uses the PragMARC on Debian
and would like me to package them, let me know.
Let me take this opportunity to reiterate once again my call for help.
If anyone wants to join me in maintaining Ada packages in Debian, you
are more than welcome. I will help you get started if you send me a
private email. There are many, many free software packages that would
deserve to be packaged in Debian, PargmARC is but one of them.
> http://packages.debian.org/unstable/devel/
This lists all packages in the development section; there are thousands
of them. Unfortunately, Ada packages are only a small fraction of that :)
If you are only interested in Ada packages, see:
http://packages.debian.org/testing/devel/gnat
The package `gnat' recommends or suggests most other Ada packages; you can
use it as a starting point. Also:
http://qa.debian.org/developer.php?login=Ludovic+Brenta
http://qa.debian.org/developer.php?login=Phil+Brooke
--
Ludovic Brenta.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Shootout: Word Frequency
2005-04-15 7:52 ` Ludovic Brenta
@ 2005-04-15 10:30 ` Martin Dowie
0 siblings, 0 replies; 7+ messages in thread
From: Martin Dowie @ 2005-04-15 10:30 UTC (permalink / raw)
Ludovic Brenta wrote:
> Let me take this opportunity to reiterate once again my call for help.
> If anyone wants to join me in maintaining Ada packages in Debian, you
> are more than welcome. I will help you get started if you send me a
> private email. There are many, many free software packages that would
> deserve to be packaged in Debian, PargmARC is but one of them.
I would, if I could only get my internet connection working my Debian
machine... :-(
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-04-15 10:30 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-14 1:28 Shootout: Word Frequency Jeffrey Carter
2005-04-14 8:08 ` Martin Dowie
2005-04-14 19:09 ` Jeffrey Carter
2005-04-14 20:41 ` Martin Dowie
2005-04-15 1:01 ` Jeffrey Carter
2005-04-15 7:52 ` Ludovic Brenta
2005-04-15 10:30 ` Martin Dowie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox