From: Jeffrey Carter <spam@spam.com>
Subject: Re: ANN: Simple components v 1.3
Date: Thu, 15 Jan 2004 18:18:07 GMT
Date: 2004-01-15T18:18:07+00:00 [thread overview]
Message-ID: <zPANb.11686$zj7.497@newsread1.news.pas.earthlink.net> (raw)
In-Reply-To: <matsw-E5F2FF.17223315012004@sicinfo.epfl.ch>
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
next prev parent reply other threads:[~2004-01-15 18:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-03 17:17 ANN: Simple components v 1.3 Dmitry A. Kazakov
2004-01-14 12:06 ` Preben Randhol
2004-01-14 13:15 ` Dmitry A. Kazakov
2004-01-15 14:01 ` Mats Weber
2004-01-15 15:04 ` Dmitry A. Kazakov
2004-01-15 16:22 ` Mats Weber
2004-01-15 18:18 ` Jeffrey Carter [this message]
2004-01-16 9:49 ` 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