|
Class: GeometricSeries
Object
|
+--Collection
|
+--SequenceableCollection
|
+--ReadOnlySequenceableCollection
|
+--GeometricSeries
- Package:
- stx:libbasic2
- Category:
- Collections-Sequenceable
- Version:
- rev:
1.10
date: 2021/11/13 13:29:44
- user: cg
- file: GeometricSeries.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
Much like intervals (which have a constant difference between elements),
these have a constant factor between them.
GeometricSeries represent a collection (or range) of values specified by
a startValue, an endValue and a *factor*.
Like with intervals, the elements are computed, not stored.
For example,
the GeometricSeries (1 to:100 byFactor:2) contains the elements (1 2 4 8 16 32 64).
and GeometricSeries (1 to:(1/100) byFactor:(1/2)) contains the elements (1 1/2 1/4 1/8 1/16 1/32 1/64).
examples:
(1 to:100 byFactor:2) do:[:i | Transcript showCR:i]
(1 to:100 byFactor:1.1) do:[:i | Transcript showCR:i]
(1 to:100 byFactor:2) asArray
(1 to:128 byFactor:2) asArray
(128 to:2 byFactor:(1/2)) asArray
(1 to:128 byFactor:2) sum
(1 to:128 byFactor:2) asArray sum
copyrightCOPYRIGHT (c) 2000 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.
instance creation
-
from: start to: stop byFactor: factor
-
return a new geometric series with elements from start
to stop by a factor
accessing
-
at: index
-
return (i.e. compute) the index'th element
Usage example(s):
(1 to:128 byFactor:2) do:[:v | Transcript showCR:v].
(1 to:128 byFactor:2) at:1.
(1 to:128 byFactor:2) at:2.
(1 to:128 byFactor:2) at:3.
(1 to:128 byFactor:2) last.
(1 to:100 byFactor:2) last.
(16 to:1 byFactor:(1/2)) do:[:v | Transcript showCR:v].
(16 to:1 byFactor:(1/2)) at:1.
(16 to:1 byFactor:(1/2)) at:2.
(16 to:1 byFactor:(1/2)) at:3.
(16 to:1 byFactor:(1/2)) last.
(16 to:3 byFactor:(1/2)) last.
|
-
first
-
return the first element
Usage example(s):
(1 to:100 byFactor:2) first.
(10 to:100 byFactor:3) first.
(100 to:10 byFactor:1/3) first.
|
-
last
-
return the last element
Usage example(s):
(1 to:100 byFactor:2) last.
(1 to:100 byFactor:3) last.
(10 to:100 byFactor:3) last.
(100 to:10 byFactor:1/3) last.
(100 to:1 byFactor:1/2) last.
(1 to:100 byFactor:2.0) last.
(1 to:64.0 byFactor:2.0) last.
(1 to:100 byFactor:3.0) last.
(10 to:100.0 byFactor:3) last.
(100 to:10.0 byFactor:0.3) last.
(100 to:3 byFactor:1/2) last.
(100 to:3 byFactor:0.5) last.
|
enumerating
-
do: aBlock
-
evaluate the argument, aBlock for every element in the receiver.
Redefined since SeqColl accesses the receiver with at:,
which is slow for intervals.
Usage example(s):
(1 to:128 byFactor:2) do:[:v | Transcript showCR:v]
(16 to:1 byFactor:(1/2)) do:[:v | Transcript showCR:v]
(1.0 to:128.0 byFactor:2) do:[:v | Transcript showCR:v]
(GeometricSeries from:1 to:128 byFactor:2) do:[:v | Transcript showCR:v]
|
printing & storing
-
printOn: aStream
-
append a printed representation to aStream
-
storeOn: aStream
-
store a representation which can reconstruct the receiver to aStream
private
-
setFrom: startVal to: stopVal byFactor: factorVal
-
set start, stop and factor components
-
species
-
return the type of collection to be returned by collect, select etc.
queries
-
size
-
return the number of elements in the collection (computed)
Usage example(s):
(1 to:100 byFactor:2) size
(1 to:100 byFactor:3) size
(10 to:100 byFactor:3) size
(100 to:10 byFactor:1/3) size
(100 to:1 byFactor:1/2) size
(1 to:100 byFactor:2.0) size
(1 to:64.0 byFactor:2.0) size
(1 to:100 byFactor:3.0) size
(10 to:100.0 byFactor:3) size
(100 to:10.0 byFactor:0.3) size
(100 to:3 byFactor:1/2) size
(100 to:3 byFactor:0.5) size
|
|