6.6 Dictionary Interface

ORIGIN 'container';
BODY 'private/dictionaryBody'
(*
 * COPYRIGHT
 *       Copyright (C) Mjolner Informatics, 1997
 *       All rights reserved.
 *)
--- lib:attributes ---
dictionary: container
  (* A dictionary is an efficient data structure for storing associations
   * between two objects (the Key and the Entry).  The Key object acts as the
   * lookup value for the Entry object, such that the Entry object can be
   * located in the dictionary given the Key object.
   * 
   * Defines the operations: 
   *      hashFunction, associate, disassociate, lookup, scanAssociations
   *)
  (# <<SLOT dictionaryLib:attributes>>;
     
     key:< object
       (* The qualification of the Key objects of THIS(dictionary) *);
     keyEqual:< booleanValue
       (* Defines the equality test on key objetcs.  Users of
        * container patterns must further bind equal to contain the
        * proper equality test for the specified key type.  Default
        * equality test for equal references (i.e. the same object)
        *)
       (# left,right: ^key
       enter (left[],right[])
       do (left[] = right[])->value; INNER
       #);
     init::< (# ... #);
     clear::(# ... #);
     empty::(# ... #);
     size::(# ... #);
     has::(# ... #);
     find::(# ... #);
     copy::(# ... #);
     hashFunction:< integerValue
       (* Internally, the dictionary is organized as a hashTable, and this
        * pattern is invoked on all Keys defined in THIS(dictionary) to define
        * the location of the association.  The default behaviour will generate
        * many collisions, and specialization is therefore strongly advised
        *)
       (# k: ^key
       enter k[] 
       do INNER
       #);
     associate:
       (* Associates the element 'e' with the key 'k' *)
       (# k: ^key; e: ^element
       enter (k[], e[])
       ...
       #);
     lookup:
       (* Returns the element associated with the key 'k'.  Returns
        * NONE of no associations exists with key 'k'
        *)
       (# k: ^key; e: ^element
       enter k[]
       ...
       exit e[]
       #);
     disassociate:
       (* Removes an possible association between key 'k' and element
        * 'e'.  Does nothing if no associateion exists.
        *)
       (# k: ^key; e: ^element
       enter k[]
       ...
       exit e[]
       #);
     scanAssociations:
       (* Scans this(dictionary).  For each assiciation in
        * this(dictionary), 'k' will refer to the key and 'e' will
        * refer to the associated element
        *)
       (# where:< elementPredicate(# k: ^key enter k[] do INNER #);
          k: ^key; e: ^element;
          start:< object;
          end:< object;
       ...
       #);
     theScanner::<
       (# 
       ...
       #);
     storage: (* Private *) @...;
  #)


6.6 Dictionary Interface
© 1992-2002 Mjølner Informatics
[Modified: Thursday December 3rd 1998 at 17:33]