VirtualArray.st
changeset 2714 8b675b3e4a3b
child 2906 6838bf53c834
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VirtualArray.st	Mon Feb 27 21:11:43 2012 +0100
@@ -0,0 +1,80 @@
+"{ Package: 'stx:libbasic2' }"
+
+SequenceableCollection subclass:#VirtualArray
+	instanceVariableNames:'generator size'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Collections-Arrayed'
+!
+
+!VirtualArray class methodsFor:'documentation'!
+
+documentation
+"
+    An Array which computes its values on demand and does NOT remember those values.
+    Use this to present huge files/hex dumps to a text editor.
+
+    [author:]
+        Claus Gittinger
+
+    [see also:]
+        LazyArray
+"
+!
+
+examples
+"
+                                                                [exBegin]
+    |squaresLines|
+
+    squaresLines := VirtualArray new.
+    squaresLines generator:[:index | index squared printString].
+    squaresLines setSize:100000.
+
+    squaresLines inspect.
+    TextView openWith:squaresLines
+                                                                [exEnd]
+"
+! !
+
+!VirtualArray methodsFor:'accessing'!
+
+generator
+    ^ generator
+!
+
+generator:something
+    generator := something.
+!
+
+setSize:something 
+    size := something.
+!
+
+size
+    ^ size
+! !
+
+!VirtualArray methodsFor:'collection protocol'!
+
+at:index
+    ^ generator value:index
+
+    "Created: / 27-02-2012 / 20:40:03 / cg"
+!
+
+at:index put:value
+    self noModificationError.
+
+    "Created: / 27-02-2012 / 20:40:33 / cg"
+! !
+
+!VirtualArray class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/libbasic2/VirtualArray.st,v 1.1 2012-02-27 20:11:43 cg Exp $'
+!
+
+version_CVS
+    ^ '$Header: /cvs/stx/stx/libbasic2/VirtualArray.st,v 1.1 2012-02-27 20:11:43 cg Exp $'
+! !