eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'PowerSet':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: PowerSet


Inheritance:

   Object
   |
   +--Collection
      |
      +--PowerSet

Package:
stx:libbasic2
Category:
Collections-Unordered
Version:
rev: 1.8 date: 2023/11/15 07:26:24
user: cg
file: PowerSet.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


A PowerSet of a collection is the set of all possible (sub-)collections
built from the original collection's elements.
This includes the empty collection.

The PowerSet of [1 2 3] is therefore:
    []
    [1]
    [2]
    [3]
    [1 2]
    [1 3]
    [2 3]
    [1 2 3]

As the powerset can quickly become huge in size (for a baseSet of n elements, we
get a powerSet size of 2^N), the elements of the powerset are created dynamically.
I.e. they are only created on demand.
As this, this is a good example of polymorphism: powerSets represent collections,
but do not really store their elements (see Interval for another such Collection).

copyright

COPYRIGHT (c) 2006 by eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

instance creation
o  for: aCollection
Create & return a new instance for aCollection.


Instance protocol:

enumerating
o  do: aBlock
evaluate the argument, aBlock for each element

initialization
o  initializeFor: aCollection

queries
o  includes: aCollection
(comment from inherited method)
return true, if an element equal to the argument, searchedElement is in the collection.
This compares using #= (i.e. it does not look for the object itself,
instead, one that compares equal).
See #includesIdentical: when identity is asked for.
This is a *very* slow fallback - many subclasses redefine this for performance.

o  size
^ 2 raisedTo:baseSet size


Examples:


    |s p|

    s := #(1 2 3).
    p := PowerSet for:s.
    p size. 

    p do:[:eachSubSet |
        Transcript showCR:eachSubSet
    ].
A huge powerSet - do not enumerate its elements ;-)
    |s p|

    s := (1 to:1000).
    p := PowerSet for:s.

    Transcript show:'p''s size is: '; showCR:p size
    |s p|

    s := (1 to:10).
    p := PowerSet for:s.
    p size. 
    p includes:#(1 2 3) asSet.   
    p includes:#(1 2 4) asSet.   
    p includes:#(0 1 2) asSet.         


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 16:49:59 GMT