From: "Albert Bachmann" <albert.bachmann@gmx.de>
Subject: Re: Spellcheck.adb
Date: 26 Apr 2005 13:50:38 -0700
Date: 2005-04-26T13:50:38-07:00 [thread overview]
Message-ID: <1114548638.851249.246280@f14g2000cwb.googlegroups.com> (raw)
In-Reply-To: <sLwbe.50677$Of5.32567@nntpserver.swip.net>
Hello David,
my system is a Fedora Core 3 Linux box with a Pentium 4 running at 2.4
GHz with 512MB RAM. I use GNAT from GCC-4.0.0. with -O3. All my timings
are for n = 1.
In the meantime I followed the advice from Matthew Heaney (thanks
Matthew) and went on with Ada.Containers. I again tried a simple
implementation. Unfortunately I recognized that controlled types have
to be instantiated at library level which requires now a total of 3
files since the instantiation of ada.containers.hashed_maps needs a
definite subtype for its key_type.
Anyway the resulting solution runs with the following times:
real 0m0.352s
user 0m0.318s
sys 0m0.015s
Here are the file contents:
types.ads:
----------
package types is
subtype word is string(1 .. 128);
end types;
hashmap.ads:
------------
with ada.strings.fixed;
with ada.strings.hash;
with ada.containers.hashed_maps;
with types;
package hashmap is new ada.containers.hashed_maps(key_type =>
types.word,
element_type => boolean,
hash => ada.strings.hash,
equivalent_keys => "=");
and finally spellcheck2.adb:
----------------------------
with ada.strings.fixed;
with ada.strings.hash;
with ada.text_io;
with ada.integer_text_io;
with hashmap;
with types;
use types;
use ada;
procedure spellcheck2 is
subtype index is natural range 0 .. 2760;
file : text_io.file_type;
item : word;
item_offset : natural;
dict : hashmap.map;
begin
text_io.open(file, text_io.in_file, "spellcheck-dict.txt");
while not text_io.end_of_file(file) loop
text_io.get_line(file, item, item_offset);
strings.fixed.delete(item, item_offset + 1, word'last);
hashmap.insert(dict, item, true);
end loop;
while not text_io.end_of_file loop
text_io.get_line(item, item_offset);
strings.fixed.delete(item, item_offset + 1, word'last);
if not hashmap.contains(dict, item) then
text_io.put_line(item);
end if;
end loop;
text_io.close(file);
end spellcheck2;
Please note that those attempts are only quick and dirty hacks. If
someone knows how to get rid of the seperate types.ads file I would
welcome his advice.
So far I have not tested your proposed solution but eventually I will
do so and let you know about any possible issues.
Regards,
Albert
next prev parent reply other threads:[~2005-04-26 20:50 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-25 21:30 [Shootout] Spellcheck.adb albert.bachmann
2005-04-25 21:57 ` Spellcheck.adb Albert Bachmann
2005-04-25 23:27 ` [Shootout] Spellcheck.adb Marius Amado Alves
2005-04-26 18:04 ` Spellcheck.adb Matthew Heaney
2005-04-26 19:36 ` [Shootout] Spellcheck.adb David Sauvage
2005-04-26 20:50 ` Albert Bachmann [this message]
2005-04-27 15:11 ` Spellcheck.adb Matthew Heaney
2005-04-27 22:49 ` Spellcheck.adb Albert Bachmann
2005-04-27 23:35 ` Spellcheck.adb Marius Amado Alves
2005-04-27 23:58 ` Spellcheck.adb Albert Bachmann
2005-04-28 0:19 ` Spellcheck.adb Marius Amado Alves
2005-04-29 10:22 ` Spellcheck.adb Albert Bachmann
2005-04-28 0:58 ` Spellcheck.adb Matthew Heaney
2005-04-29 10:19 ` Spellcheck.adb Albert Bachmann
2005-04-28 0:41 ` Spellcheck.adb Matthew Heaney
2005-04-28 21:20 ` Spellcheck.adb Simon Wright
2005-04-29 10:05 ` Spellcheck.adb Albert Bachmann
2005-04-29 12:35 ` Spellcheck.adb Matthew Heaney
2005-04-26 21:21 ` Spellcheck.adb Albert Bachmann
2005-04-26 22:04 ` Spellcheck.adb David Sauvage
2005-04-26 20:36 ` [Shootout] Spellcheck.adb Dmitry A. Kazakov
2005-04-26 21:50 ` David Sauvage
2005-04-27 8:40 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox