5388
|
1 |
"{ Encoding: utf8 }"
|
|
2 |
|
|
3 |
"
|
|
4 |
COPYRIGHT (c) 2018 by eXept Software AG
|
|
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 |
"
|
4819
|
14 |
"{ Package: 'stx:libbasic2' }"
|
|
15 |
|
|
16 |
"{ NameSpace: Smalltalk }"
|
|
17 |
|
|
18 |
VirtualArray subclass:#VirtualArrayWithCache
|
|
19 |
instanceVariableNames:'lruCache'
|
|
20 |
classVariableNames:''
|
|
21 |
poolDictionaries:''
|
4972
|
22 |
category:'Collections-Arrayed'
|
4819
|
23 |
!
|
|
24 |
|
|
25 |
!VirtualArrayWithCache class methodsFor:'documentation'!
|
|
26 |
|
5388
|
27 |
copyright
|
|
28 |
"
|
|
29 |
COPYRIGHT (c) 2018 by eXept Software AG
|
|
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 |
|
4819
|
41 |
documentation
|
|
42 |
"
|
|
43 |
like a VirtualArray, but caches the results of the last few accesses.
|
|
44 |
This might behave better, if it is expensive to compute the elements,
|
|
45 |
and they are often accessed repeatedly (as when showing in a listView).
|
|
46 |
|
|
47 |
[author:]
|
|
48 |
Claus Gittinger
|
|
49 |
|
|
50 |
[instance variables:]
|
|
51 |
|
|
52 |
[class variables:]
|
|
53 |
|
|
54 |
[see also:]
|
|
55 |
|
|
56 |
"
|
|
57 |
!
|
|
58 |
|
|
59 |
examples
|
|
60 |
"
|
|
61 |
[exBegin]
|
|
62 |
|factorialLines|
|
|
63 |
|
|
64 |
factorialLines := VirtualArrayWithCache new:10000.
|
|
65 |
factorialLines generator:[:index | index factorial printString].
|
|
66 |
factorialLines at:1000.
|
|
67 |
factorialLines at:1000.
|
|
68 |
factorialLines at:10000.
|
|
69 |
|
|
70 |
[exEnd]
|
|
71 |
"
|
|
72 |
! !
|
|
73 |
|
|
74 |
!VirtualArrayWithCache methodsFor:'collection protocol'!
|
|
75 |
|
|
76 |
at:index
|
|
77 |
lruCache isNil ifTrue:[
|
|
78 |
lruCache := CacheDictionary new:100.
|
|
79 |
].
|
|
80 |
^ lruCache at:index ifAbsentPut:[generator value:index]
|
|
81 |
|
|
82 |
"Created: / 01-03-2019 / 20:35:45 / Claus Gittinger"
|
|
83 |
! !
|
|
84 |
|
|
85 |
!VirtualArrayWithCache class methodsFor:'documentation'!
|
|
86 |
|
|
87 |
version_CVS
|
|
88 |
^ '$Header$'
|
|
89 |
! !
|
|
90 |
|