|
Class: VirtualDictionary
Object
|
+--Collection
|
+--VirtualDictionary
|
+--VirtualDictionaryWithCache
- Package:
- stx:libbasic2
- Category:
- Collections-Unordered
- Version:
- rev:
1.12
date: 2023/11/15 07:22:18
- user: cg
- file: VirtualDictionary.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
a collection which looks like a (usually read-only) dictionary to the outside,
but invokes a pluggable fetchBlock to retrieve keys and optional storeBlock
to change values.
The fetchBlock is called for at:ifAbsent: and is supposed to
return an object for the given argument(key) or nil if there is no such value.
For example,
VirtualDictionary new fetchBlock:[:key | key squared]
will respond to:
at:4
with 16.
VirtualDictionary does not remember previously computed values,
whereas VirtualDictionaryWithCache does.
Caveat:
a virtual dictionary does not support:
size
do: (and all other enumeration messages)
actually it does not behave at all like a dictionary.
[instance variables:]
[class variables:]
copyrightCOPYRIGHT (c) 2018 by eXept Software AG
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.
accessing
-
at: aKey
-
retrieve a value from this (virtual) dictionary.
-
at: aKey ifAbsent: exceptionValue
-
retrieve a value from this (virtual) dictionary.
-
at: aKey put: aValue
-
store a value in this (virtual) dictionary.
May raise an error, if storing is not allowed or if the key is wrong
-
do: aBlock
-
enumerate the elements (if possible); raise an error if not.
-
includesKey: aKey
-
return true if aKey is in this (virtual) dictionary.
-
size
-
return the size (if known); raise an error if not known.
initializing
-
checkKeyBlock: aOneArgBlock
-
define the checkKeyblock; this is invoked with the key to check for presence
-
doBlock: aOneArgBlock
-
define the doblock; this is invoked to enumerate the virtual elements
-
fetchBlock: aOneArgBlock
-
define the fetchblock; this is invoked with the key to fetch
-
sizeBlock: aBlock
-
define the sizeblock; this is invoked to ask for the virtual size
-
storeBlock: aTwoArgBlock
-
define the storeblock; this is invoked with the key and value to store
testing
-
isVirtualCollection
-
(comment from inherited method)
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.
-
isVirtualDictionary
-
|