comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <jrcarter@acm.org>
Subject: Re: Ada.Containers.Indefinite_Hashed_Maps
Date: Wed, 25 Apr 2007 17:43:44 GMT
Date: 2007-04-25T17:43:44+00:00	[thread overview]
Message-ID: <krMXh.15008$n_.5528@attbi_s21> (raw)
In-Reply-To: <1177510391.733055.133060@n35g2000prd.googlegroups.com>

markp wrote:
> I am using a hash table via Ada.Containers.Indefinite_Hashed_Maps to
> hash an array of records. We have a predfined array of records called
> X. The insert function works fine by passing in X(1), X(2), etc. I am
> having trouble with the syntax of the Update call, specifically the
> Process parameter. Could somebody provide a quick snippet of code that
> show how to setup this code and how the procedure actually looks to
> update the data?

There is no update; I presume you mean Update_Element.

Given a map:

package Maps is new Ada.Containers.Indefinite_Hashed_Maps
    (Key_Type => Key_Value, Element_Type => Integer, ...);

procedure Process (Key : in Key_Value; Item : in out Integer) is
    -- null;
begin -- Process
    if Some_Quality (Key) then
       Item := Item + 1;
    end if;
end Process;

Map      : Maps.Map;
Some_Key : Key_Value;
Position : Maps.Cursor;

-- Put some values in Map.

Some_Key := Get;

if Maps.Contains (Map, Some_Key) then
    Position := Maps.Find (Map, Key => Some_Key);
    Maps.Update_Element (Container => Map,
                         Position  => Position,
                         Process   => Process'access);
end if;

If you've put a value in Map for the key with the value in Some_Key, and 
Some_Quality (Some_Key) returns True, then this will increment the value 
associated with that key value.

For this kind of situation, you'd probably use Element and Replace 
rather than Find and Update_Element. Update_Element is more useful when 
you've got a cursor without knowing the key value, and want to modify 
the corresponding element.

-- 
Jeff Carter
"Apart from the sanitation, the medicine, education, wine,
public order, irrigation, roads, the fresh water system,
and public health, what have the Romans ever done for us?"
Monty Python's Life of Brian
80



  reply	other threads:[~2007-04-25 17:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-25 14:13 Ada.Containers.Indefinite_Hashed_Maps markp
2007-04-25 17:43 ` Jeffrey R. Carter [this message]
2007-04-26 12:12   ` Ada.Containers.Indefinite_Hashed_Maps Maciej Sobczak
2007-04-26 12:55     ` Ada.Containers.Indefinite_Hashed_Maps Stefan Bellon
2007-04-26 16:13       ` Ada.Containers.Indefinite_Hashed_Maps Matthew Heaney
2007-04-27  4:39     ` Ada.Containers.Indefinite_Hashed_Maps Jeffrey R. Carter
2007-04-26 15:52 ` Ada.Containers.Indefinite_Hashed_Maps Matthew Heaney
2007-04-26 19:56   ` Ada.Containers.Indefinite_Hashed_Maps Matthew Heaney
2007-04-26 16:12 ` Ada.Containers.Indefinite_Hashed_Maps Matthew Heaney
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox