eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Interval':

Home

everywhere
www.exept.de
for:
[back]

Class: Interval


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--ReadOnlySequenceableCollection
            |
            +--Interval

Package:
stx:libbasic
Category:
Collections-Sequenceable
Version:
rev: 1.51 date: 2009/09/08 15:36:02
user: cg
file: Interval.st directory: libbasic
module: stx stc-classLibrary: libbasic
Author:
Claus Gittinger

Description:


Intervals represent a collection (or range) of numeric values specified by
a startValue, an endValue and a step. 
The interesting thing is that the elements are computed, not stored.
However, protocol-wise, intervals behave like any other (read-only) sequenceable collection.

For example, the interval (1 to:5) containes the elements (1 2 3 4 5) and
(1 to:6 by:2) contains (1 3 5).

examples:

    (1 to:10) do:[:i | Transcript showCR:i]

  notice, that this is semantically equivalent to:

    1 to:10 do:[:i | Transcript showCR:i]

  however, the second is preferred, since loops using to:do: are
  much faster and do not create temporary garbage objects. 
  Therefore, Intervals are generally NOT used for this kind of loops.

    (1 to:10) asArray  

    (1 to:10 by:2) asOrderedCollection  


Class protocol:

converting
o  decodeFromLiteralArray: anArray
create & return a new instance from information encoded in anArray.
Re-redefined, since the implementation in SequencableCollection creates instances with an initial
size, which is not allowed for intervals.

instance creation
o  from: start to: stop
return a new interval with elements from start to stop by 1

o  from: start to: stop by: step
return a new interval with elements from start to stop by step


Instance protocol:

accessing
o  at: index
return (i.e. compute) the index'th element

o  first
return the first element of the collection

o  increment
alias for #step; for ST-80 compatibility

o  last
return the last element of the collection

o  start
return the first number of the range

o  start: aNumber
set the first number of the range

o  step
return the step increment of the range.
OBSOLETE:
Please use #increment for ST-80 compatibility.

o  step: aNumber
set the step increment of the range

o  stop
return the end number of the range

o  stop: aNumber
set the end number of the range

bulk operations
o  sum
sum up all elements.

comparing
o  = anInterval

o  hash

converting
o  fromLiteralArrayEncoding: encoding
read my values from an encoding.
The encoding is supposed to be either of the form:
(#Interval start stop step)
This is the reverse operation to #literalArrayEncoding.

o  literalArrayEncoding
encode myself as an array literal, from which a copy of the receiver
can be reconstructed with #decodeAsLiteralArray.

converting-reindexed
o  from: startIndex
return a new collection representing the receivers elements starting at startIndex.

o  to: endIndex
return a new collection representing the receivers elements upTo and including endIndex.

enumerating
o  collect: aBlock
evaluate the argument, aBlock for every element in the collection
and return a collection of the results.
Redefined since SeqColl accesses the receiver via at:, which is slow for intervals

o  do: aBlock
evaluate the argument, aBlock for every element in the receiver-interval.
Redefined since SeqColl accesses the receiver with at:, which is slow for intervals.

o  reverseDo: aBlock
evaluate the argument, aBlock for every element in the receiver-interval in
reverse order.
Redefined since SeqColl accesses the receiver with at:, which is slow for intervals.

o  select: aBlock
evaluate the argument, aBlock for every element in the collection
and return a collection of all elements for which the block return true.
Redefined since SeqColl accesses the receiver with at:, which is slow for intervals.

printing & storing
o  displayString

o  printOn: aStream
append a printed representation to aStream

o  storeOn: aStream
store a representation which can reconstruct the receiver to aStream

private
o  setFrom: startInteger to: stopInteger by: stepInteger
set start, stop and step components

o  species
return the type of collection to be returned by collect, select etc.

queries
o  max
return the maximum value in the receiver collection,
redefined, since this can be easily computed.
Raises an error, if the receiver is empty.

o  min
return the minimum value in the receiver collection,
redefined, since this can be easily computed.
Raises an error, if the receiver is empty.

o  minMax
return the minimum and maximum values in the receiver collection
as a two element array.
Raises an error, if the receiver is empty.

o  size
return the number of elements in the collection

set operations
o  intersect: aCollection
return a new interval containing all elements of the receiver,
which are also contained in the argument collection

sorting & reordering
o  reversed
return a copy with elements in reverse order

testing
o  includes: anElement
return true if anElement is in the interval (Numeric compare using =)

visiting
o  acceptVisitor: aVisitor with: aParameter
this is special. Some encoders want to encode this as a sequenceable collection,
some want to encode a less expensive representation



ST/X 6.1.1; WebServer 1.620 at exept:8081; Wed, 23 May 2012 19:43:14 GMT