-- $Date: 2004/02/14 02:24:18 $
-- $Revision: 1.8 $
-- $Author: jcrocholl $

package body String_Hash_Tables is

   ------------------------------
   -- Storing and retrieving data
   ------------------------------

   -- Check for available space in the table, grow if necessary, then
   -- insert the key item pair into the table.
   -- Raises Key_Exists if the key is already in use.
   procedure Put
     (This : in out Hash_Table_Access-- Add pair to this hash table.
      Key  : in String;                -- Create this key.
      Item : in Item_Type)             -- Associate this item.
   is
      Pair : Inner_Tables.Pair_Access := new Inner_Tables.Pair;
   begin
      To_String_Access(Key, Pair.Key);
      Pair.Item := Item;
      Inner_Tables.Put(This, Pair);
   end Put;
   pragma Inline(Put);

   -- Retrieve an item from the table.
   -- Output parameter Found is True if and only if the key was found.
   procedure Get
     (This  : access Hash_Table-- Get value from this hash table.
      Key   : in String;         -- Look up this key.
      Item  : out Item_Type;     -- The item that was found.
      Found : out Boolean)       -- True if the item was found.
   is
      Index : Positive;
   begin
      Get_Index(This, Key, Index, Found);
      if not Found then return; end if;
      Item := Get_Item(This, Index);
   end Get;
   pragma Inline(Get);

   -- Retrieve an item from the table.
   -- Raises Key_Not_Found if the key is not in the table.
   function Get
     (This : access Hash_Table-- Get value from this hash table.
      Key  : in String)         -- Look up this key.
     return Item_Type is        -- The item that was found.
   begin
      return Get_Item(This, Get_Index(This, Key));
   end Get;
   pragma Inline(Get);

   -----------------
   -- Indexed access
   -----------------

   -- Get the index of a given key.
   procedure Get_Index
     (This  : access Hash_Table-- Get key from this hash table.
      Key   : in String;         -- Iteration pointer to the current field.
      Index : out Positive;      -- The index of the requested key.
      Found : out Boolean)       -- True if the key was found.
   is
      Temp : String_Access;
   begin
      To_String_Access(Key, Temp);
      Inner_Tables.Get_Index(This, Temp, Index, Found);
      Free(Temp);
   end Get_Index;
   pragma Inline(Get_Index);

   -- Get the index of a given key.
   function Get_Index
     (This : access Hash_Table-- Get key from this hash table.
      Key  : in String)         -- Iteration pointer to the current field.
     return Positive            -- The index of the requested key.
   is
      Temp  : String_Access;
      Index : Positive;
   begin
      To_String_Access(Key, Temp);
      Index := Inner_Tables.Get_Index(This, Temp);
      Free(Temp);
      return Index;
   end Get_Index;
   pragma Inline(Get_Index);

   -- Get the key at a given index position.
   function Get_Key
     (This  : access Hash_Table-- Get key from this hash table.
      Index : in Positive)       -- Iteration pointer to the current field.
     return String is            -- The requested key.
   begin
      return To_String(Inner_Tables.Get_Key(This, Index));
   end Get_Key;
   pragma Inline(Get_Key);

end String_Hash_Tables;