Re: Spellcheck.adb




"Albert Bachmann" <albert.bachmann@xxxxxx> wrote in message
news:1114548638.851249.246280@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>
> 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.


> 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.

> 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.


> hashmap.ads:
> ------------
>
> package hashmap is new ada.containers.hashed_maps(key_type =>
> types.word,

No. This should just be type String.


> and finally spellcheck2.adb:
> ----------------------------
>
> strings.fixed.delete(item, item_offset + 1, word'last);

You can get rid of this.


> 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.


> 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



.



Relevant Pages

  • Re: Spellcheck.adb
    ... >> Matthew) and went on with Ada.Containers. ... > instantiate the containers in your main subprogram. ... This should just be type String. ... > You can get rid of this. ...
    (comp.lang.ada)
  • Re: Charles container library usage examples
    ... and another to create a map of lists. ... > If you're using an Ada 95 compiler, then you'll have to instantiate the ... I used the ordered map instead of the hashed map. ...
    (comp.lang.ada)
  • Re: 100s of microsoft files and dont know how to get rid of them
    ... scans run forever as are checking ... "MAP" wrote: ... and I need help to know which microsoft forum to ask for help in how ... to get rid of these. ...
    (microsoft.public.windowsxp.general)
  • Re: 100s of microsoft files and dont know how to get rid of them
    ... scans run forever as are checking ... "MAP" wrote: ... and I need help to know which microsoft forum to ask for help in how ... to get rid of these. ...
    (microsoft.public.windowsxp.general)
  • Re: `Survivor loser makes church a winner
    ... roads, rivers, and mountains? ... out there looking to get rid of any map name that contains 'devil worship' ... words like 'dead', 'squaw', or various swear words. ...
    (alt.tv.survivor)

Loading