VirtualArray.st
author Claus Gittinger <cg@exept.de>
Thu, 10 Jul 2014 14:24:25 +0200
changeset 3324 cd20bb3b5472
parent 3119 5ef27ab5efd4
child 3326 e6b2b0bb8037
permissions -rw-r--r--
displayOn: cleanup
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2906
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
     1
"
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
     2
 COPYRIGHT (c) 2012 by Claus Gittinger
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
     3
              All Rights Reserved
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
     4
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
     5
 This software is furnished under a license and may be used
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
     6
 only in accordance with the terms of that license and with the
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
     8
 be provided or otherwise made available to, or used by, any
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
     9
 other person.  No title to or ownership of the software is
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
    10
 hereby transferred.
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
    11
"
2714
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
SequenceableCollection subclass:#VirtualArray
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
	instanceVariableNames:'generator size'
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	classVariableNames:''
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	category:'Collections-Arrayed'
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!VirtualArray class methodsFor:'documentation'!
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
2906
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
    23
copyright
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
    24
"
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
    25
 COPYRIGHT (c) 2012 by Claus Gittinger
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
    26
              All Rights Reserved
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
    27
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
    28
 This software is furnished under a license and may be used
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
    29
 only in accordance with the terms of that license and with the
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
    31
 be provided or otherwise made available to, or used by, any
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
    32
 other person.  No title to or ownership of the software is
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
    33
 hereby transferred.
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
    34
"
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
    35
!
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
    36
2714
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
documentation
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
"
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
    An Array which computes its values on demand and does NOT remember those values.
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
    Use this to present huge files/hex dumps to a text editor.
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    [author:]
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
        Claus Gittinger
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    [see also:]
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
        LazyArray
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
"
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
!
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
examples
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
"
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
                                                                [exBegin]
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    |squaresLines|
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    squaresLines := VirtualArray new.
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
    squaresLines generator:[:index | index squared printString].
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    squaresLines setSize:100000.
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
    squaresLines inspect.
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    TextView openWith:squaresLines
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
                                                                [exEnd]
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
"
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
! !
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
!VirtualArray methodsFor:'accessing'!
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
generator
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
    ^ generator
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
!
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
generator:something
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    generator := something.
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
!
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
setSize:something 
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
    size := something.
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
!
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
size
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
    ^ size
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
! !
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
!VirtualArray methodsFor:'collection protocol'!
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
at:index
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    ^ generator value:index
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    "Created: / 27-02-2012 / 20:40:03 / cg"
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
!
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
at:index put:value
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
    self noModificationError.
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
    "Created: / 27-02-2012 / 20:40:33 / cg"
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
! !
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
3119
5ef27ab5efd4 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
    97
!VirtualArray methodsFor:'inspecting'!
5ef27ab5efd4 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
    98
5ef27ab5efd4 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
    99
displayOn:aGCOrStream
5ef27ab5efd4 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   100
    "print a representation of the receiver on aGCOrStream for display in inspectors etc."
5ef27ab5efd4 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   101
5ef27ab5efd4 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   102
    "/ what a kludge - Dolphin and Squeak mean: printOn: a stream;
5ef27ab5efd4 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   103
    "/ ST/X (and some old ST80's) mean: draw-yourself on a GC.
3324
cd20bb3b5472 displayOn: cleanup
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   104
    (aGCOrStream isStream) ifFalse:[
3119
5ef27ab5efd4 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   105
        ^ super displayOn:aGCOrStream
5ef27ab5efd4 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   106
    ].
5ef27ab5efd4 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   107
5ef27ab5efd4 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   108
    aGCOrStream nextPutAll:('VirtualArray(size=%1, generator=%2)' 
5ef27ab5efd4 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   109
                                bindWith:size with:generator printString).
5ef27ab5efd4 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   110
! !
5ef27ab5efd4 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   111
2714
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
!VirtualArray class methodsFor:'documentation'!
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
version
3324
cd20bb3b5472 displayOn: cleanup
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   115
    ^ '$Header: /cvs/stx/stx/libbasic2/VirtualArray.st,v 1.4 2014-07-10 12:24:25 cg Exp $'
2714
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
!
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
version_CVS
3324
cd20bb3b5472 displayOn: cleanup
Claus Gittinger <cg@exept.de>
parents: 3119
diff changeset
   119
    ^ '$Header: /cvs/stx/stx/libbasic2/VirtualArray.st,v 1.4 2014-07-10 12:24:25 cg Exp $'
2714
8b675b3e4a3b initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
! !
2906
6838bf53c834 class: VirtualArray
Claus Gittinger <cg@exept.de>
parents: 2714
diff changeset
   121