------------------------------------------------------------------ -- -- NAME: DICTIONARY -- DISCREPANCY REPORTS: -- ------------------------------------------------------------------ -- File: DICTIONARY.ADA -- Level: all generic type KEY_TYPE is private; with function "<" (LEFT, RIGHT : in KEY_TYPE) return BOOLEAN; type VALUE_TYPE is private; type KEY_LIST_TYPE is array (POSITIVE range <>) of KEY_TYPE; type VALUE_LIST_TYPE is array (POSITIVE range <>) of VALUE_TYPE; package DICTIONARY is -- Package DICTIONARY defines an ASSOCIATION_TYPE and a DICTIONARY_TYPE. -- -- An association between a KEY_TYPE value and a VALUE_TYPE value is -- represented by an ASSOCIATION_TYPE value, which is a record with -- components KEY, containing the KEY_TYPE value, and VALUE, containing -- the VALUE_TYPE value associated with KEY. -- -- A set of associations is called a dictionary, by analogy of the set -- of associations between words and their definitions. Dictionaries may -- be represented with objects of the type DICTIONARY_TYPE. -- -- A dictionary serves as an associative memory, associating VALUE's to -- KEY's. For any KEY, the associated VALUE can be found. -- -- A pure associative memory, like a set, imposes no order on the -- entries. This dictionary, like Webster's dictionary, is sorted. -- The sorted order is used internally to speed-up searching for a KEY. -- In order to impose a sorting order the "<" function is imported. The -- lists which can be derived from the dictionary, ASSOCIATION_LIST, -- KEY_LIST, and VALUE_LIST, are returned in this sorted order. -- -- DICTIONARY_TYPE is actually an access type. Simple assignment of one -- DICTIONARY_TYPE object to another only results in having two ways to -- reference the same dictionary. A COPY procedure is provided to -- generate a new copy. type ASSOCIATION_TYPE is record KEY : KEY_TYPE; VALUE : VALUE_TYPE; end record; type ASSOCIATION_LIST_TYPE is array (POSITIVE range <>) of ASSOCIATION_TYPE; type DICTIONARY_TYPE is private; KEY_IN_USE : exception; KEY_NOT_FOUND : exception; procedure CREATE (DICTIONARY : in out DICTIONARY_TYPE; ASSOCIATION : in ASSOCIATION_TYPE); procedure CREATE (DICTIONARY : in out DICTIONARY_TYPE; KEY : in KEY_TYPE; VALUE : in VALUE_TYPE); procedure ALTER (DICTIONARY : in DICTIONARY_TYPE; ASSOCIATION : in ASSOCIATION_TYPE); procedure ALTER (DICTIONARY : in DICTIONARY_TYPE; KEY : in KEY_TYPE; VALUE : in VALUE_TYPE); procedure ENTER (DICTIONARY : in out DICTIONARY_TYPE; ASSOCIATION : in ASSOCIATION_TYPE); procedure ENTER (DICTIONARY : in out DICTIONARY_TYPE; KEY : in KEY_TYPE; VALUE : in VALUE_TYPE); procedure REMOVE (DICTIONARY : in out DICTIONARY_TYPE; KEY : in KEY_TYPE); procedure PURGE (DICTIONARY : in out DICTIONARY_TYPE; KEY : in KEY_TYPE); function IS_IN (DICTIONARY : in DICTIONARY_TYPE; KEY : in KEY_TYPE) return BOOLEAN; function ASSOCIATION (DICTIONARY : in DICTIONARY_TYPE; KEY : in KEY_TYPE) return ASSOCIATION_TYPE; function VALUE (DICTIONARY : in DICTIONARY_TYPE; KEY : in KEY_TYPE) return VALUE_TYPE; function SIZE (DICTIONARY : in DICTIONARY_TYPE) return NATURAL; function ASSOCIATION_LIST (DICTIONARY : in DICTIONARY_TYPE) return ASSOCIATION_LIST_TYPE; function KEY_LIST (DICTIONARY : in DICTIONARY_TYPE) return KEY_LIST_TYPE; function VALUE_LIST (DICTIONARY : in DICTIONARY_TYPE) return VALUE_LIST_TYPE; function COPY (ORIGINAL : in DICTIONARY_TYPE) return DICTIONARY_TYPE; private type DICTIONARY_NODE_TYPE; type DICTIONARY_TYPE is access DICTIONARY_NODE_TYPE; end DICTIONARY;