4817
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
2906
|
3 |
"
|
|
4 |
COPYRIGHT (c) 2012 by Claus Gittinger
|
|
5 |
All Rights Reserved
|
|
6 |
|
|
7 |
This software is furnished under a license and may be used
|
|
8 |
only in accordance with the terms of that license and with the
|
|
9 |
inclusion of the above copyright notice. This software may not
|
|
10 |
be provided or otherwise made available to, or used by, any
|
|
11 |
other person. No title to or ownership of the software is
|
|
12 |
hereby transferred.
|
|
13 |
"
|
2714
|
14 |
"{ Package: 'stx:libbasic2' }"
|
|
15 |
|
3479
|
16 |
"{ NameSpace: Smalltalk }"
|
|
17 |
|
2714
|
18 |
SequenceableCollection subclass:#VirtualArray
|
|
19 |
instanceVariableNames:'generator size'
|
|
20 |
classVariableNames:''
|
|
21 |
poolDictionaries:''
|
|
22 |
category:'Collections-Arrayed'
|
|
23 |
!
|
|
24 |
|
|
25 |
!VirtualArray class methodsFor:'documentation'!
|
|
26 |
|
2906
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 2012 by Claus Gittinger
|
|
30 |
All Rights Reserved
|
|
31 |
|
|
32 |
This software is furnished under a license and may be used
|
|
33 |
only in accordance with the terms of that license and with the
|
|
34 |
inclusion of the above copyright notice. This software may not
|
|
35 |
be provided or otherwise made available to, or used by, any
|
|
36 |
other person. No title to or ownership of the software is
|
|
37 |
hereby transferred.
|
|
38 |
"
|
|
39 |
!
|
|
40 |
|
2714
|
41 |
documentation
|
|
42 |
"
|
|
43 |
An Array which computes its values on demand and does NOT remember those values.
|
4818
|
44 |
This does not use any memory for the elements - however, trading speed for size, this
|
|
45 |
takes longer to access elements, as they are computed on the fly (for every access).
|
2714
|
46 |
Use this to present huge files/hex dumps to a text editor.
|
|
47 |
|
|
48 |
[author:]
|
|
49 |
Claus Gittinger
|
|
50 |
|
|
51 |
[see also:]
|
|
52 |
LazyArray
|
|
53 |
"
|
|
54 |
!
|
|
55 |
|
|
56 |
examples
|
|
57 |
"
|
|
58 |
[exBegin]
|
|
59 |
|squaresLines|
|
|
60 |
|
4817
|
61 |
squaresLines := VirtualArray new:100000.
|
2714
|
62 |
squaresLines generator:[:index | index squared printString].
|
|
63 |
|
|
64 |
squaresLines inspect.
|
4818
|
65 |
(TextView openWith:#()) list:squaresLines expandTabs:false
|
2714
|
66 |
[exEnd]
|
|
67 |
"
|
|
68 |
! !
|
|
69 |
|
4817
|
70 |
!VirtualArray class methodsFor:'instance creation'!
|
|
71 |
|
|
72 |
new:size
|
|
73 |
^ self new setSize:size.
|
|
74 |
|
|
75 |
"Created: / 01-03-2019 / 20:30:21 / Claus Gittinger"
|
|
76 |
! !
|
|
77 |
|
2714
|
78 |
!VirtualArray methodsFor:'accessing'!
|
|
79 |
|
|
80 |
generator
|
3768
|
81 |
"the element value generator; a block which gets the index as argument"
|
|
82 |
|
2714
|
83 |
^ generator
|
|
84 |
!
|
|
85 |
|
3768
|
86 |
generator:aBlock
|
|
87 |
"set the element value generator; a block which gets the index as argument"
|
|
88 |
|
|
89 |
generator := aBlock.
|
2714
|
90 |
!
|
|
91 |
|
3768
|
92 |
setSize:anInteger
|
|
93 |
size := anInteger.
|
2714
|
94 |
!
|
|
95 |
|
|
96 |
size
|
3768
|
97 |
"the virtual size"
|
|
98 |
|
2714
|
99 |
^ size
|
|
100 |
! !
|
|
101 |
|
|
102 |
!VirtualArray methodsFor:'collection protocol'!
|
|
103 |
|
|
104 |
at:index
|
|
105 |
^ generator value:index
|
|
106 |
|
|
107 |
"Created: / 27-02-2012 / 20:40:03 / cg"
|
|
108 |
!
|
|
109 |
|
|
110 |
at:index put:value
|
|
111 |
self noModificationError.
|
|
112 |
|
|
113 |
"Created: / 27-02-2012 / 20:40:33 / cg"
|
3326
|
114 |
!
|
|
115 |
|
|
116 |
grow:howBig
|
|
117 |
"change the receiver's size"
|
|
118 |
|
|
119 |
self setSize:howBig
|
2714
|
120 |
! !
|
|
121 |
|
3119
|
122 |
!VirtualArray methodsFor:'inspecting'!
|
|
123 |
|
|
124 |
displayOn:aGCOrStream
|
|
125 |
"print a representation of the receiver on aGCOrStream for display in inspectors etc."
|
|
126 |
|
|
127 |
"/ what a kludge - Dolphin and Squeak mean: printOn: a stream;
|
4350
|
128 |
"/ old ST80 means: draw-yourself on a GC.
|
3324
|
129 |
(aGCOrStream isStream) ifFalse:[
|
3119
|
130 |
^ super displayOn:aGCOrStream
|
|
131 |
].
|
|
132 |
|
|
133 |
aGCOrStream nextPutAll:('VirtualArray(size=%1, generator=%2)'
|
|
134 |
bindWith:size with:generator printString).
|
4350
|
135 |
|
|
136 |
"Modified (comment): / 22-02-2017 / 16:49:54 / cg"
|
3119
|
137 |
! !
|
|
138 |
|
3479
|
139 |
!VirtualArray methodsFor:'queries'!
|
|
140 |
|
|
141 |
species
|
3859
|
142 |
"return the type of collection to be returned by collect, select etc."
|
3479
|
143 |
|
|
144 |
^ OrderedCollection
|
|
145 |
! !
|
|
146 |
|
2714
|
147 |
!VirtualArray class methodsFor:'documentation'!
|
|
148 |
|
|
149 |
version
|
3768
|
150 |
^ '$Header$'
|
2714
|
151 |
!
|
|
152 |
|
|
153 |
version_CVS
|
3768
|
154 |
^ '$Header$'
|
2714
|
155 |
! !
|
2906
|
156 |
|