map.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
---------------------------> Sather 1.1 source file <--------------------------
-- $Id: map.sa,v 1.3 1996/04/09 10:05:11 borisv Exp $
-- Author: Holger Klawitter <holger@math.uni-muenster.de>
-- Benedict Gomes: Many changes..
-- Abstract and concrete mappings from K (items) to E (data).
--   $MAP{K,E}     :An abstract map
--   MAP_INCL{K,E} :Partial class for Maps
--   H_MAP{K,E}    :A concrete map based on data buckets
--   TEST_MAP      :Test class for MAP{K,E}


abstract class $RO_MAP{K,E} < $CONTAINER{E}, $STR

abstract class $RO_MAP{K,E} < $CONTAINER{E}, $STR is -- A read-only map abstraction that does not permit modifications. -- A mapping abstraction from elements of type K to elements of type E -- A map stores an element of type E under a key of type K. -- Each key can hold one element. -- -- Design note: It would also be reasonable to have a $RO_MAP be -- a subtype of $CONTAINER{TUP{K,E}}. However, since we are using -- the array notation, to avoid confusion with the way arrays behave -- we view maps as containers of the target elements, with the -- keys being a kind of indexing method. Arrays are then a special -- kind of map where the keys are integers. Though we don't make -- use of this possibility in this library, the use of array -- notation is consistent with it. -- has(e: E): BOOL; -- Inherited: Return true if the map contains the element "e". Could be -- very expensive has_ind(k:K): BOOL; -- Returns 'true' if 'k' is mapped to an element. has_elt(e: E): BOOL; -- Same as "has" aget(k:K): E; -- Returns the element k is mapped to. -- If k is absent: -- If E < $IS_NIL return E::nil othewise return void -- size: INT; -- Inherited: Returns the number of indices/elements in the mapping ind!: K; -- Yields the indices (keys) of the mapping -- elt!: E; -- Inherited: Yields the elements of the mapping pair!: TUP{K,E}; -- Yields the the elements or a tuple containing both -- in arbitrary order. end;

abstract class $MAP{K,E} < $RO_MAP{K,E}

abstract class $MAP{K,E} < $RO_MAP{K,E} is -- A modifiable MAP -- Elements are stored in a map using the aset notation. -- Further assignments to a key will result in a replacement. aset(k:K,e:E); -- Maps k to e. If k is already mapped, replace the old -- maping with ne new one. delete(k:K); delete(k:K): E; -- Removes the mapping from k. The element k was mapped to -- will be returned (or an appropiate non-value). end;