bag.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 2000 by K Hopper, University of Waikato, New Zealand        --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute  and/or modify it under the terms of the GNU Library General --
-- Public  License (LGPL)  as published  by the  Free  Software  Foundation; --
-- either version 2 of the license, or (at your option) any later version.   --
-- This  library  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details.       --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------


abstract class $RO_BAG{ETP} < $CONTAINER{ETP}

abstract class $RO_BAG{ETP} < $CONTAINER{ETP} is -- The bag abstraction is an object container in which there is no -- specified ordering. It may contain two or more equal objects. This -- specifies only the non-destructive read-only bag! -- Version 1.3 Nov 98. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 12 Jul 95 hk Original -- 9 Apr 96 bg Modified bag implementation to include -- partial classes, altering sub-typing. -- 13 Mar 97 kh Adapted to use CARD -- 5 Nov 98 kh Revised to 1.2 dist. equals( other : $RO_BAG{ETP} ) : BOOL ; -- This predicate returns true if and only if self and other contain -- the same elements with the same cardinality, irrespective of the order -- of such elements. n_unique : CARD ; -- This routine returns the count of unique elements in self. count( elem : ETP ) : CARD ; -- This routine returns the number of copies of elem in the bag. is_subset_of( arg : $RO_BAG{ETP} ) : BOOL ; -- This predicate returns true if and only if self is a subset of arg. -- -- NOTE For the bag self to be a subset of arg where an element occurs in -- both then the number of occurrences in arg must be no less than -- the number in self. add( elem : ETP ) : $RO_BAG{ETP} ; -- This routine returns a new bag containing all of the elements of -- self - as well as the given element. delete( elem : ETP ) : $RO_BAG{ETP} ; -- This routine returns a new bag containing all of the elements of self -- except for one copy of an element equal to elem (if one exists!). delete_all( elem : ETP ) : $RO_BAG{ETP} ; -- This routine returns a new bag containing all of the elements of self -- except for ALL instances of an element equal to elem! concat( arg : $ELT{ETP} ) : $RO_BAG{ETP} ; -- This routine returns a new bag which contains all of the elements of -- self and arg. For elements which have multiple occurrences then the -- result contains the sum of the numbers in self and arg. union( arg : $RO_BAG{ETP} ) : $RO_BAG{ETP} ; -- This routine returns a new bag contining the elements of self and -- arg. For elements which occur multiple times the reult contains the -- larger number of occurrences in self or arg. intersection( arg : $RO_BAG{ETP} ) : $RO_BAG{ETP} ; -- This routine returns a new bag containing the elements common to self -- and arg. For elements with multiple occurrences the result contains the -- lesser of the number in self and arg. unique! : ETP ; -- This iter yields all of the unique elements of self (only once!). end ; --$RO_BAG{ETP}

abstract class $VBAG{ETP} < $RO_BAG{ETP}, $HASH

abstract class $VBAG{ETP} < $RO_BAG{ETP}, $HASH is -- This abstraction models the mathematical notion of a bag. -- -- IMPORTANT: This is a value abstraction which is stricter than the -- read-only abstraction. Subtypes must not support *any* -- operations that modify self. The Sather language cannot -- enforce this restriction. -- Version 1.1 Nov 98. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 12 Dec 95 bg Original -- 5 Nov 98 kh Revised to 1.2 dist. equals( other : $VBAG{ETP} ) : BOOL ; -- This predicate returns true if and only if self and other contain -- the same elements with the same cardinality, irrespective of the order -- of such elements. add( elem : ETP ) : $VBAG{ETP} ; -- This routine returns a new bag containing all of the elements of -- self - as well as the given element. delete( elem : ETP ) : $VBAG{ETP} ; -- This routine returns a new bag containing all of the elements of self -- except for one copy of an element equal to elem (if one exists!). delete_all( elem : ETP ) : $VBAG{ETP} ; -- This routine returns a new bag containing all of the elements of self -- except for ALL instances of an element equal to elem! concat( arg : $ELT{ETP} ) : $VBAG{ETP} ; -- This routine returns a new bag which contains all of the elements of -- self and arg. For elements which have multiple occurrences then the -- result contains the sum of the numbers in self and arg. union( arg : $RO_BAG{ETP} ) : $VBAG{ETP} ; -- This routine returns a new bag contining the elements of self and -- arg. For elements which occur multiple times the reult contains the -- larger number of occurrences in self or arg. intersection( arg : $RO_BAG{ETP} ) : $VBAG{ETP} ; -- This routine returns a new bag containing the elements common to self -- and arg. For elements with multiple occurrences the result contains the -- lesser of the number in self and arg. end ; -- $VBAG{ETP}

abstract class $BAG{ETP} < $RO_BAG{ETP}, $VAR

abstract class $BAG{ETP} < $RO_BAG{ETP}, $VAR is -- This abstraction models the mathematical notion of a bag, supporting -- operations that modify. Instances of subtypes may be viewed as variables -- with a value of $VBAG{ETP} -- Version 1.1 Nov 98. Copyright K Hopper, U of Waikato -- Development History -- ------------------- -- Date Who By Detail -- ---- ------ ------ -- 12 Dec 95 bg Original -- 5 Nov 98 kh Revised to 1.2 dist. add( elem : ETP ) ; -- This routine adds the given element to self. add( elem : ETP ) : $BAG{ETP} ; -- This routine returns a new bag which is the result of adding elem -- to self. delete( elem : ETP ) ; -- This routine deletes one copy of the element given if its present -- in self. delete( elem : ETP ) : $BAG{ETP} ; -- This routine returns a new bag which is identical to self except that -- one element equal to elem (if any) has been deleted. delete_all( elem : ETP ) ; -- This routine deletes from self ALL instances of elements equal to -- elem! delete_all( elem : ETP ) : $BAG{ETP} ; -- This routine returns a new bag identical to sell except that it -- contains no elements equal to elem. clear ; -- This routine clears all elements of self, resetting the size to zero! to_concat( arg : $RO_BAG{ETP} ) ; -- This routine concatenates the elements of arg to self. to_union( arg : $RO_BAG{ETP} ) ; -- This routine sets self to be the bag which is a union of self and arg. to_intersection( arg : $RO_BAG{ETP} ) ; -- This routine sets self to be the intersection of self and arg. as_value : $VBAG{ETP} ; -- This routine returns a copy of self as a new value. end ; -- $BAG{ETP}