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.5 date: 2014/02/23 01:14:33
user: cg
file: PowerSet.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

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).


Related information:

    Set
    Interval

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


Examples:


    |s p|

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

    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 includes:#(1 2 3) asSet.   
    p includes:#(1 2 4) asSet.   
    p includes:#(0 1 2) asSet.         


ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Sat, 17 Nov 2018 08:52:10 GMT