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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9d0f079e3d2d7be7 X-Google-Attributes: gid103376,public From: "Nick Roberts" Subject: Re: Array index ? Date: 1998/01/31 Message-ID: <01bd2e90$af2ef360$LocalHost@xhv46.dial.pipex.com>#1/1 X-Deja-AN: 320946264 Content-Transfer-Encoding: 7bit References: Content-Type: text/plain; charset=ISO-8859-1 Organization: UUNet UK server (post doesn't reflect views of UUNet UK) Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1998-01-31T00:00:00+00:00 List-Id: One simple scheme might be to do a simple conversion from the string T_Index to a discrete type, an integer type T_Int_Index say. Supposing the string will only ever contain the digits 0 to 9, the following function would do the conversion: type T_Int_Index is Integer range 0..9999; function To_Int(S: T_Index) return T_Int_Index is begin return S(1)*1000 + S(2)*100 + S(3)*10 + S(4); end; The array could then be declared as: type T is array(T_Int_Index) of R; then an array, such as Stock: T; could be accessed by an index N like this: Q1 := Q1 + Stock(To_Int(N)).Quant_In; This is a simple example of 'hashing'. The disadvantage of this simple system may be that the array, which has 10000 elements, may be much too big (in that most of it remains unsed). If this is the case, you might be able to get around the problem with a more complicated 'hashing index' -- the function defined above. Have fun! -- == Nick Roberts ================================================ == Croydon, UK =========================== == ================ == Proprietor, ThoughtWing Software ========== == Independent Software Development Consultant ====== == Nick.Roberts@dial.pipex.com ==== == Voicemail & Fax +44 181-405 1124 === == == == I live not in myself, but I become == === Portion of that around me; and to me == ==== High mountains are a feeling, but the hum == ======= Of human cities torture. =========== -- Byron [Childe Harold] Matthew Heaney wrote in article ... > Do you mean you want an array whose index subtype is a subtype of String, as in > > subtype T_Index is String (1 .. 4); > > type T is array (T_Index) of R; > > If so, you can't do that, because arrays can only have a discrete subtype > (integer or enumeration type) as the index subtype. > > You probably want a more abstract data structure, such as a dictionary > (sort of like a symbol table - consult you fave compiler book) or a > trie-structure (not a misspell) or a hash table, etc.