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,FREEMAIL_FROM, WEIRD_PORT autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,64fc02e079586f1b X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!newsfeed.arcor.de!news.arcor.de!not-for-mail From: Albert Bachmann Subject: Re: Spellcheck.adb Date: Thu, 28 Apr 2005 00:49:20 +0200 User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.) Message-ID: Newsgroups: comp.lang.ada References: <1114464642.518876.137610@f14g2000cwb.googlegroups.com> <1114548638.851249.246280@f14g2000cwb.googlegroups.com> <426fab8a$0$3712$39cecf19@news.twtelecom.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Organization: Arcor NNTP-Posting-Date: 28 Apr 2005 00:49:20 MEST NNTP-Posting-Host: c350acae.newsread4.arcor-online.net X-Trace: DXC=5ci@_D2mZJ?2j7j^L?86D8:ejgIfPPld4jW\KbG]kaM8liQbn6H@_E9>X=Wh5fgO@?V[]9NUANcn7i^BfHUI;QC7PA:g<><;PM< X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:10760 Date: 2005-04-28T00:49:20+02:00 List-Id: On Wed, 27 Apr 2005 11:11:06 -0400, Matthew Heaney wrote: > > "Albert Bachmann" wrote in message > news:1114548638.851249.246280@f14g2000cwb.googlegroups.com... >> >> 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 > > This is no longer true in Ada 2005. Eventually you'll be able to > instantiate the containers in your main subprogram. That may be true but with GNAT (as of GCC-4.0.0) I get an error: gcc -c -gnat05 -O3 spellcheck3.adb spellcheck3.adb:10:09: instantiation error at a-cohata.ads:29 spellcheck3.adb:10:09: instantiation error at a-cihase.ads:214 spellcheck3.adb:10:09: controlled type must be declared at the library level gnatmake: "spellcheck3.adb" compilation error > > >> which requires now a total of 3 >> files since the instantiation of ada.containers.hashed_maps needs a >> definite subtype for its key_type. > > True, but that's why we have the Indefinite_Hashed_Maps container package. > If you're manipulating strings, you should probably be using that. > > Also, as I mentioned in an earlier post, you don't really need a map, since > all you're doing is performing a membership test. Hence, a (hashed) set > will do. > When I use and instance of indefinite_hashed_sets or indefinite_hashed_maps the program compiles fine but I get an exception during runtime: raised CONSTRAINT_ERROR : a-cihama.adb:443 explicit raise (for the map) raised CONSTRAINT_ERROR : a-cihase.adb:375 explicit raise (for the set) >> types.ads: >> ---------- >> >> package types is >> subtype word is string(1 .. 128); >> end types; > > Get rid of this. Instantiate the Indefinite_Hashed_Sets (or _Maps, if you > prefer) with type String. > Ok. > >> hashmap.ads: >> ------------ >> >> package hashmap is new ada.containers.hashed_maps(key_type => >> types.word, > > No. This should just be type String. > Ok. > >> and finally spellcheck2.adb: >> ---------------------------- >> >> strings.fixed.delete(item, item_offset + 1, word'last); > > You can get rid of this. I did. > > >> hashmap.insert(dict, item, true); > > If you used a (hashed) set, then all you'd have to say is > > insert(dict, item); > > >> strings.fixed.delete(item, item_offset + 1, word'last); > > You can get rid of this. > Here too. > >> if not hashmap.contains(dict, item) then > > See, you're not using the map element at all. You're only using the key. > > >> 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. > > You can get rid of the types file, by using the indefinite hashed map (or > set), and instantiating it with type String. > > -Matt I post the modified source. Maybe I've overlooked something because as I said above during runtime I get an exception. However thanks for those valuable information Matthew! hashed_set.ads: -------------- with ada.containers.indefinite_hashed_sets; with ada.strings.hash; --with hash_function; package hashed_set is new ada.containers.indefinite_hashed_set( element_type => string, hash => ada.strings.hash, --hash_function, equivalent_keys => "="); spellcheck3.adb: ---------------- with ada.strings.fixed; with ada.text_io; with hashed_set; use ada; procedure spellcheck3 is file : text_io.file_type; item : string(1 .. 128); item_offset : natural; dict : hashed_set.set; 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); hashed_set.insert(dict, item); end loop; while not text_io.end_of_file loop text_io.get_line(item, item_offset); if not hashed_set.contains(dict, item) then text_io.put_line(item); end if; end loop; text_io.close(file); end spellcheck3; Regards, Albert