|
DataMuseum.dkPresents historical artifacts from the history of: Rational R1000/400 Tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Rational R1000/400 Tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - downloadIndex: ┃ T V ┃
Length: 18173 (0x46fd) Types: TextFile Names: »V«
└─⟦85b835f43⟧ Bits:30000549 8mm tape, Rational 1000, Xlib rev 6.00 └─ ⟦0c20f784e⟧ »DATA« └─⟦1abbe589f⟧ └─⟦059497ac5⟧ └─⟦this⟧
with Xlbt_Arithmetic; use Xlbt_Arithmetic; generic ------------------------------------------------------------------------------ -- X Library String to Other type map generic -- -- Xlbp_String_Map_Generic - Map from an Ada string value to some other value ------------------------------------------------------------------------------ -- Copyright 1989 - 1991 by Rational, Santa Clara, California. -- -- All Rights Reserved. -- -- Permission to use, copy, modify, and distribute this software and its -- documentation for any purpose and without fee is hereby granted, -- provided that the above copyright notice(s) appear in all copies and that -- both that copyright notice(s) and this permission notice appear in -- supporting documentation, and that the name of Rational not be used in -- advertising or publicity pertaining to distribution of the software -- without specific, written prior permission. -- -- Rational disclaims all warranties with regard to this software, including -- all implied warranties of merchantability and fitness, in no event shall -- Rational be liable for any special, indirect or consequential damages or -- any damages whatsoever resulting from loss of use, data or profits, whether -- in an action of contract, negligence or other tortious action, arising out -- of or in connection with the use or performance of this software. ------------------------------------------------------------------------------ type Character is (<>); type Index is range <>; type String is array (Index range <>) of Character; type String_Pointer is access String; ------------------------------------------------------------------------------ -- String is the string type we are using for key values. ------------------------------------------------------------------------------ type Range_Type is private; ------------------------------------------------------------------------------ -- Range_Type - The data type to be stored within the map. This type must -- be fully constrained. ------------------------------------------------------------------------------ --/ if R1000 then pragma Must_Be_Constrained (Yes => Range_Type); --/ end if; -- R1000 Hash_Size : Positive := 13; ------------------------------------------------------------------------------ -- Specifies the size of the hash table to be used. The value should always be -- a prime number and should be "large enough" to allow for "good" hash table -- performance for the application. Some prime numbers that would be good -- candidates for the Hash_Size are: -- 13, 31, 59, 101, 211, 307, 401, 503, 751, 1009, 1511, 2003, 3001, 4001, -- 5003, 6007, 7001, 8009, 9001, 10007, 15013, 20011, 30011, 40009, 50021 ------------------------------------------------------------------------------ Exact_Case_Match : Boolean := True; ------------------------------------------------------------------------------ -- Specifies TRUE if "A" matches "A" but not "a". ------------------------------------------------------------------------------ package Xlbip_String_Map_Generic is type Map is private; type Iter is private; ------------------------------------------------------------------------------ -- Map - Variables of this type are String Maps; i.e. maps from string values -- to values of some Range_Type. -- Iter - Variables of this type are used to iterate through all entries -- within a map. ------------------------------------------------------------------------------ None_Map : constant Map; None_Iter : constant Iter; ------------------------------------------------------------------------------ -- Uninitialized values. ------------------------------------------------------------------------------ Duplicate_Entry : exception; Missing_Entry : exception; ------------------------------------------------------------------------------ -- Duplicate_Entry - raised by Insert when duplicate keys conflict -- Missing_Entry - raised by Delete/Locate when a key is missing ------------------------------------------------------------------------------ procedure New_Map (M : out Map); ------------------------------------------------------------------------------ -- M - Receives a new Map. -- -- Called to create and initialize a new Map. The Map Is_Empty. ------------------------------------------------------------------------------ procedure Free_Map (M : in out Map); ------------------------------------------------------------------------------ -- M - Specifies the existing Map to deallocate. -- -- Called to destroy an existing Map. Map may have a None_Map value. All map -- entries are destroyed. The Range_Type values contained in the map are -- merely dropped and are not deallocated or manipulated in any way. ------------------------------------------------------------------------------ function Is_Empty (M : in Map) return Boolean; ------------------------------------------------------------------------------ -- M - Specifies the map -- -- Returns TRUE if the map is completely empty. ------------------------------------------------------------------------------ function Cardinality (M : in Map) return S_Natural; ------------------------------------------------------------------------------ -- M - Specifies the map -- -- Returns the number of entries in the map. ------------------------------------------------------------------------------ procedure Find (M : in Map; Key : in String; Rt : in out Range_Type; Status : out Boolean); ------------------------------------------------------------------------------ -- M - Specifies the map to use -- Key - Specifies the string value to use for the lookup -- Rt - Receives the Range_Type value from the map or is unchanged -- Status - Receives TRUE if the Key was found and FALSE if not -- -- Called to perform a lookup within the map. If the Key string is found -- within the map then the associated Range_Type value is returned and -- Status is set to TRUE. If the Key string is not found then Status is -- set to FALSE and the Rt parameter remains unchanged. (Beware of -- uninitialized locals being passed to Find; they will often be the cause -- of Constraint_Errors.) ------------------------------------------------------------------------------ procedure Find (M : in Map; Key : in String; Ptr : in out String_Pointer; Rt : in out Range_Type; Status : out Boolean); ------------------------------------------------------------------------------ -- M - Specifies the map to use -- Key - Specifies the string value to use for the lookup -- Ptr - Receives the string pointer from the map or is unchanged -- Rt - Receives the Range_Type value from the map or is unchanged -- Status - Receives TRUE if the Key was found and FALSE if not -- -- Called to perform a lookup within the map. If the Key string is found -- within the map then the associated Range_Type value is returned and -- Status is set to TRUE. If the Key string is not found then Status is -- set to FALSE and the Rt parameter remains unchanged. (Beware of -- uninitialized locals being passed to Find; they will often be the cause -- of Constraint_Errors.) Do not free the Ptr value returned by a successful -- lookup. It is shared by the map and deallocating it will cause -- unpredicatble program behavior. ------------------------------------------------------------------------------ procedure Find_Ptr (M : in Map; Key : in out String_Pointer; Rt : in out Range_Type; Status : out Boolean); ------------------------------------------------------------------------------ -- M - Specifies the map to use -- Key - Specifies the string value to use for the lookup -- Rt - Receives the Range_Type value from the map or is unchanged -- Status - Receives TRUE if the Key was found and FALSE if not -- -- Called to perform a lookup within the map. If the Key string is found -- within the map then the associated Range_Type value and the String_Pointer -- used by the map are returned and Status is set to TRUE. If the Key string -- is not found then Status is set to FALSE and the Key and Rt parameters -- remain unchanged. (Beware of uninitialized locals being passed to Find; -- they will often be the cause of Constraint_Errors.) Do not free the -- Key value returned by a successful lookup. It is shared by the map and -- deallocating it will cause unpredicatble program behavior. ------------------------------------------------------------------------------ function Locate (M : in Map; Key : in String) return Range_Type; ------------------------------------------------------------------------------ -- M - Specifies the map to use -- Key - Specifies the string value to use for the lookup -- -- Called to perform a lookup within the map. If the Key string is found -- within the map then the associated Range_Type value is returned. -- If the Key string is not found then Missing_Entry is raised. ------------------------------------------------------------------------------ procedure Insert (M : in Map; Key : in String; Rt : in Range_Type; Dups_Ok : in Boolean := False); ------------------------------------------------------------------------------ -- M - Specifies the map to use -- Key - Specifies the string value to use for the insertion -- Rt - Specifies the Range_Type value to be placed into the map -- Dups_Ok - Specifies TRUE if the new entry is allowed to replace an -- existing entry. -- -- Called to insert a new Range_Type value into the map. If Dups_Ok => FALSE -- then a pre-existing map entry with the same Key value will cause -- Duplicate_Entry to be raised. ------------------------------------------------------------------------------ procedure Insert_Ptr (M : in Map; Key : in String_Pointer; Rt : in Range_Type; Dups_Ok : in Boolean := False); ------------------------------------------------------------------------------ -- M - Specifies the map to use -- Key - Specifies the string value to use for the insertion -- Rt - Specifies the Range_Type value to be placed into the map -- Dups_Ok - Specifies TRUE if the new entry is allowed to replace an -- existing entry. -- -- Called to insert a new Range_Type value into the map. If Dups_Ok => FALSE -- then a pre-existing map entry with the same Key value will cause -- Duplicate_Entry to be raised. If there is no preexisting entry, then a new -- entry is made and the Key value is stored into the map. Note: This means -- that the application must not free this string value or the program -- will behave unpredicatably. ------------------------------------------------------------------------------ procedure Delete (M : in Map; Key : in String; Missing_Ok : in Boolean := False); ------------------------------------------------------------------------------ -- M - Specifies the map to use -- Key - Specifies the string value to use for the lookup -- Missing_Ok - Specifies TRUE if the entry need not exist -- -- Called to delete an existing Range_Type value from the map. Raises -- Missing_Entry if no matching Key entry is found unless Missing_Ok => TRUE. ------------------------------------------------------------------------------ procedure Remove (M : in Map; Key : in String; Rt : in out Range_Type; Status : out Boolean); ------------------------------------------------------------------------------ -- M - Specifies the map to use -- Key - Specifies the string value to use for the lookup -- Rt - Receives the Range_Type value from the map or is unchanged -- Status - Receives TRUE if the Key was found and FALSE if not -- -- Called to lookup and remove an entry within the map. If the Key string is -- found -- within the map then the associated Range_Type value is returned and -- Status is set to TRUE. If the Key string is not found then Status is -- set to FALSE and the Rt parameter remains unchanged. (Beware of -- uninitialized locals being passed to Find; they will often be the cause -- of Constraint_Errors.) ------------------------------------------------------------------------------ procedure Initialize (M : in Map; I : in out Iter); ------------------------------------------------------------------------------ -- M - Specifies the map -- I - Receives the new iteration value -- -- Called to initialize an iterator for a particular map. Iterators are -- used in this fashion: -- declare -- I : Iter; -- M : Map; -- Rt : Range_Type; -- begin -- Initialize (M, I); -- while not Done (I) loop -- Rt := Value (I); -- .... Code using the Rt value .... -- Next (I); -- end loop; -- end; -- Iterators are affected by changes to the map. Deletions can cause -- dereferencing of null pointers. Insertions are benign and new map entries -- may or may not appear as Values in the iteration depending upon the -- state of the Iter when the Insert is performed and also depending upon the -- value of the Key string. -- -- The iterator will advance through all entries within the map and the -- processing order of the entries is determined by the hash value of the -- Key strings and may or may not have any externally sensible ordering. ------------------------------------------------------------------------------ procedure Initialize (M : in Map; I : in out Iter; Rng : in Range_Type); ------------------------------------------------------------------------------ -- M - Specifies the map -- I - Receives the new iteration value -- Rng - Specifies the Range_Type value that we are iterating upon -- -- Just like the other Initialize procedure except that the first value -- returned by this iterator will have a Range_Type value equal to Rng -- if Done(I) != TRUE. ------------------------------------------------------------------------------ function Done (I : in Iter) return Boolean; ------------------------------------------------------------------------------ -- I - Specifies the iterator to check -- -- Returns TRUE when there are no more map entries to iterate through. ------------------------------------------------------------------------------ function Value (I : in Iter) return Range_Type; ------------------------------------------------------------------------------ -- I - Specifies the iterator to check -- -- Returns the Range_Type value associated with the current value of the -- map iterator. Raises Missing_Entry if Done(I) = TRUE. ------------------------------------------------------------------------------ function Key (I : in Iter) return String; ------------------------------------------------------------------------------ -- I - Specifies the iterator to check -- -- Returns the string key associated with the current value of the -- map iterator. Raises Missing_Entry if Done(I) = TRUE. ------------------------------------------------------------------------------ function Key_Ptr (I : in Iter) return String_Pointer; ------------------------------------------------------------------------------ -- I - Specifies the iterator to check -- -- Returns the stored String_Pointer key associated with the current value of -- the map iterator. Raises Missing_Entry if Done(I) = TRUE. This value -- belongs to the map; do not deallocate it or the program will behave -- unpredictably. ------------------------------------------------------------------------------ procedure Next (I : in out Iter); ------------------------------------------------------------------------------ -- I - Specifies the iterator -- -- Advances the map iterator by one entry. Raises Missing_Entry if -- Done(I) = TRUE already. Done(I) = TRUE will be true when this routine -- returns and there are no more entries to be processed. ------------------------------------------------------------------------------ procedure Next (I : in out Iter; Rng : in Range_Type); ------------------------------------------------------------------------------ -- I - Specifies the iterator -- Rng - Specifies the Range_Type value that we are iterating upon -- -- Advances the map iterator by N entries. Stops advancing the iterator when -- the next entry with a Range_Type entry equal to Rng is found or when -- the last entry in the map has been passed over. Raises Missing_Entry if -- Done(I) = TRUE already. Done(I) = TRUE will be true when this routine -- returns and there are no more entries to be processed. ------------------------------------------------------------------------------ --\f private type Map_Rec; type Elem_Rec; type Element is access Elem_Rec; type Map is access Map_Rec; None_Map : constant Map := null; type Iter is record M : Map := null; Elem : Element := null; Index : S_Natural := 0; end record; None_Iter : constant Iter := (null, null, 0); --/ if R1000 then pragma Enable_Deallocation (Element); pragma Enable_Deallocation (Map); --/ end if; -- R1000 end Xlbip_String_Map_Generic;