|
Class: PowerSet
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
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).
Set
Interval
instance creation
-
for: aCollection
-
Create & return a new instance for aCollection.
enumerating
-
do: aBlock
-
evaluate the argument, aBlock for each element
initialization
-
initializeFor: aCollection
-
queries
-
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.
-
size
-
|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.
|
|