eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'ReindexedCollection':

Home

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

Class: ReindexedCollection


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--ReindexedCollection

Package:
stx:libbasic2
Category:
Collections-Sequenceable
Version:
rev: 1.13 date: 2017/02/22 09:57:03
user: cg
file: ReindexedCollection.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Travis Griggs (tgriggs@keyww.com or tkc@bmi.net)
Ported from Squeak by Claus Gittinger (not much of a port, though)

Description:


ReindexedCollection is a wrapper around a sequenceable collection that remaps the indices 
with in linear algorithm.  
The elements in the ReindexedCollection are the elements of the original collection 
at 'some start' to 'some stop' (optionally 'by some step').  

ReindexedCollection allows for efficient use of first/rest-like algorithms (i.e. aka Lisp)
applied to Sequenceable collections, as they avoid element-copying.

For example,
    coll1 := #(1 2 3 4 5 6 7 8 9 10).
    coll2 := coll1 from:8.
gives us a collection in coll2, which 'contains' 3 elements, 8, 9, 10
with indices 1,2,3. 
I.e. a slice from the other array.

The reindexed collection is 'read-only'. I.e. it does not allow for elements to be changed.

See class side examples.

[Instance Variables:]
    sequence        <SequenceableCollection>    the sequence that will be reindexed.
    interval        <Interval>                  the object that describes indicies of interest in the sequence.

[Origin:]
    Part of the Engineering Math Goodies package from Travis.



Class protocol:

instance creation
o  on: aSequence from: start
Create a reindexedCollection on aSequence from start to the end of aSequence

o  on: aSequence from: start by: step
Create a reindexedCollection on aSequence start to the end of aSequence
if step is positive, else
from start to the beginning of the sequence if step is negative.

o  on: aSequence from: start to: stop
Create a reindexedCollection on aSequence from start to stop by 1
(or -1 if start is greater than stop)

o  on: aSequence from: start to: stop by: step
Create a reindexedCollection on aSequence from start to stop by step

o  on: aSequence to: stop
Create a reindexedCollection on aSequence from 1 to stop by 1

o  on: aSequence to: stop by: step
Create a reindexedCollection on aSequence from 1 to stop (if step is
positive) or the end to stop (if
step is negative). Note: if step is not 1 or -1, there is a chance that the
index specified by stop may
not be in the interval.

o  on: aSequence with: anInterval
Create a reindexedCollection on aSequence


Instance protocol:

accessing
o  at: index
Answer the value of an indexable field in the sequence instance variable.

o  at: index put: value
Store the argument value in the indexable field of the sequence
instance variable indicated by index.
Answer the value that was stored.

o  size
Answer how many elements the receiver contains.

o  slide
slide by 1

o  slide: anIncrement
given an increment, adjust the reindex map by sliding it that far

adding & removing
o  add: anObject
report an error; reindexedCollections cannot add elements

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

o  from: startIndex to: stopIndex
return a new collection representing the receiver's elements
starting at startIndex upTo and including endIndex.

o  to: stopIndex
return a new collection representing the receiver's elements upTo and including endIndex.

initialization
o  initialize: aSequence from: start to: stop by: step

o  initialize: aSequence with: anInterval
Modified (format): / 22-02-2017 / 10:46:38 / cg

queries
o  isFixedSize
return true if the receiver cannot grow

o  species
Answer the preferred class for reconstructing the receiver,
that is, the sequence.

o  speciesForAdding
Answer the preferred class for reconstructing the receiver incrementally


Examples:


|coll| coll := #(1 2 3 4 5 6 7 8 9 10) from:8. Transcript show:'from 8: '; showCR:coll. Transcript show:'size: '; showCR:(coll size). Transcript show:'at 1: '; showCR:(coll at:1). Transcript show:'first: '; showCR:(coll first). Transcript show:'last: '; showCR:(coll last). coll do:[:each | Transcript show:'do: '; showCR:each]. coll reverseDo:[:each | Transcript show:'reverseDo: '; showCR:each]. |coll| coll := (1 to:10) asOrderedCollection from:3 to:8. coll. coll size. coll at:1. coll do:[:each | Transcript showCR:each]. |coll| coll := (1 to:10) asOrderedCollection to:4. coll. coll size. coll at:1. coll last. coll do:[:each | Transcript showCR:each].

ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Sun, 22 Jul 2018 03:03:34 GMT