|
Class: VirtualArray
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
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.
copyrightCOPYRIGHT (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.
instance creation
-
new: size
-
(comment from inherited method)
return an instance of myself with anInteger indexed variables
-
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) ).
|
accessing
-
generator
-
the element value generator; a block which gets the index as argument
-
generator: aBlock
-
set the element value generator; a block which gets the index as argument
-
setSize: anInteger
-
-
size
-
the virtual size
collection protocol
-
at: index
-
return the element at index.
The value is computed by the generator
-
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)
-
ensureCapacity: howBig
-
change the receiver's size
-
grow: howBig
-
change the receiver's size
-
removeTrailingBlankLines
-
inspecting
-
displayOn: aGCOrStream
-
print a representation of the receiver on aGCOrStream for display in inspectors etc.
printing
-
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
-
species
-
return the type of collection to be returned by collect, select etc.
testing
-
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.
|squaresLines|
squaresLines := VirtualArray new:100000.
squaresLines generator:[:index | index squared printString].
squaresLines inspect.
(TextView openWith:#()) list:squaresLines expandTabs:false
|
|