eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'VirtualArray':

Home

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

Class: VirtualArray


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--VirtualArray
            |
            +--VirtualArrayWithCache
            |
            +--VirtualReadOnlyBinaryFileContents

Package:
stx:libbasic2
Category:
Collections-Arrayed
Version:
rev: 1.18 date: 2024/02/23 07:22:22
user: cg
file: VirtualArray.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


An Array which computes its values on demand and does NOT remember those values.

This does not use any memory for the elements - however, trading speed for size, this
takes longer to access elements, as they are computed on the fly (for every access).
Used for example to present huge files/hex dumps to a text editor.

copyright

COPYRIGHT (c) 2012 by Claus Gittinger 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.

Class protocol:

instance creation
o  new: size
(comment from inherited method)
return an instance of myself with anInteger indexed variables

o  new: size withAll: constantValue
return a virtual array which consists of size repetitions
of the same constant value

Usage example(s):

     v := VirtualArray new:10 withAll:12345.
     self assert:( v size == 10 ).
     self assert:( v first == 12345 ).
     self assert:( v last == 12345 ).
     self assert:( v occurrencesOf:12345) == 10 ).
     self assert:( v asArray = (Array new:10 withAll:12345) ).


Instance protocol:

accessing
o  generator
the element value generator; a block which gets the index as argument

o  generator: aBlock
set the element value generator; a block which gets the index as argument

o  setSize: anInteger

o  size
the virtual size

collection protocol
o  at: index
return the element at index.
The value is computed by the generator

o  at: index put: value
(comment from inherited method)
store the 2nd arg, anObject as indexed instvar with index, anInteger.
this method can be redefined in subclasses. Returns anObject (sigh)

o  ensureCapacity: howBig
change the receiver's size

o  grow: howBig
change the receiver's size

o  removeTrailingBlankLines

inspecting
o  displayOn: aGCOrStream
print a representation of the receiver on aGCOrStream for display in inspectors etc.

printing
o  printOn: aStream
(comment from inherited method)
append a user readable representation of the receiver to aStream.
The text appended is not meant to be read back for reconstruction of
the receiver. Also, this method limits the size of generated string.

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

testing
o  isVirtualCollection
true if this is a collection which generates elements via
some algorithm (such as reading a file).
Some care should be taken then, as not all operations are possible then.


Examples:


    |squaresLines|

    squaresLines := VirtualArray new:100000.
    squaresLines generator:[:index | index squared printString].

    squaresLines inspect.
    (TextView openWith:#()) list:squaresLines expandTabs:false


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Tue, 22 Oct 2024 14:26:43 GMT