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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,94f331aa4ac6827f X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-01-15 10:18:08 PST Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: Jeffrey Carter Organization: jrcarter commercial-at acm [period | full stop] org User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: ANN: Simple components v 1.3 References: <75ga001eokc2r1aijtvu9d70ck3i6j1p0m@4ax.com> <629d00tlqvu326hi1vsomlmnvkobvbc0bl@4ax.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Thu, 15 Jan 2004 18:18:07 GMT NNTP-Posting-Host: 63.184.1.216 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.news.pas.earthlink.net 1074190687 63.184.1.216 (Thu, 15 Jan 2004 10:18:07 PST) NNTP-Posting-Date: Thu, 15 Jan 2004 10:18:07 PST Xref: archiver1.google.com comp.lang.ada:4441 Date: 2004-01-15T18:18:07+00:00 List-Id: Mats Weber wrote: > I think not, because with maps, you have to be able to extract an item > given its key, which you cannot do with Generic_Sets as there is no key > type. Following is the function that does that in my package: > > function Search (Key : Key_Type; Within : Bag) return Item_Type; > -- Returns the first item in FROM that has a key equal to KEY. > -- NONEXISTENT_KEY will be raised if no such item is > -- found in the bag. It should not be necessary for the component to know about the difference between keys and values. To my mind, a map is a way of using a searchable structure, such as a balanced tree or a skip list. For example, using PragmARC.Skip_List_Unbounded, one would define the Element type actual as type Map_Data is record Key : Unbounded_String; Value : Data := Null_Data; end record; Then the necessary comparison routines: function "=" (Left, Right : Map_Data) return Boolean is begin -- "=" return Left.Key = Right.Key; end "="; function "<" (Left, Right : Map_Data) return Boolean is begin -- "<" return Left.Key < Right.Key; end "<"; After instantiating Skip_List_Unbounded, one can insert and search by key: Key : constant Unbounded_String := To_Unbound_String ("Your key here"); Thing : Map_Data := (Key, Some_Value); Map : Skip_List; Found : Result; ... Insert (List => Map, Item => Thing); Thing := (Key, Null_Data); -- Value component not used in Search Found := Search (Map, Thing); if Found.Found then -- Do something with Found.Item, type Map_Data, which contains -- (Key => Key, Value => Some_Value) end if; -- Jeff Carter "I wave my private parts at your aunties." Monty Python & the Holy Grail 13