|
Class: SmallDictionary
Object
|
+--Collection
|
+--KeyedCollection
|
+--SmallDictionary
- Package:
- stx:libbasic
- Category:
- Collections-Unordered
- Version:
- rev:
1.11
date: 2019/07/31 21:16:47
- user: cg
- file: SmallDictionary.st directory: libbasic
- module: stx stc-classLibrary: libbasic
- Author:
- Stefan Vogel
A lightweight Dictionary implementation (without hashing)
for small dictionaries.
Use this, when you have to store a small number (e.g. < 20) key/value pairs.
As a side effect of the implementation, the dictionary is also ordered.
Inspired by and compatible with RBSmallDictionary from RefactoryBrowser
(although the implementaion is different).
[instance variables:]
keysAndValues Array keys are stored at odd indices, values at even indices
tally SmallInterger the number of valid key/value pairs
[class variables:]
Dictionary
MethodDictionary
instance creation
-
new
-
(comment from inherited method)
return an instance of myself without indexed variables
-
new: capacity
-
(comment from inherited method)
return an instance of myself with anInteger indexed variables
accessing
-
at: key ifAbsent: aBlock
-
return the element indexed by aKey -
return result of exceptionBlock if no element is stored under aKey
-
at: key ifAbsentPut: aBlock
-
return the element indexed by aKey if present,
if not present, store the result of evaluating valueBlock
under aKey and return it.
WARNING: do not add elements while iterating over the receiver.
Iterate over a copy to do this.
-
keys
-
return a collection containing the keys of the receiver
-
order
-
returns the keys in the order of their appearance
-
size
-
return the number of elements in the receiver.
adding
-
add: anAssociation
-
add the argument, anAssociation to the receiver.
Returns the argument, anAssociation.
WARNING: do not add elements while iterating over the receiver.
Iterate over a copy to do this.
-
at: key put: value
-
add the argument anObject under key, aKey to the receiver.
Return anObject (sigh).
WARNING: do not add elements while iterating over the receiver.
Iterate over a copy to do this.
copying-private
-
postCopy
-
(comment from inherited method)
this is for compatibility with ST-80 code, which uses postCopy for
cleanup after copying, while ST/X passes the original in postCopyFrom:
(see there)
enumerating
-
do: aBlock
-
enumerate the values
-
keysAndValuesDo: aBlock
-
(comment from inherited method)
evaluate aBlock for each key and value
-
keysDo: aBlock
-
(comment from inherited method)
evaluate the argument, aBlock for every key in the collection.
initialize-release
-
initialize: capacity
-
inspecting
-
inspector2TabLabel ( an extension from the stx:libtool package )
-
label of the main tab
-
inspectorExtraAttributes ( an extension from the stx:libtool package )
-
(comment from inherited method)
extra (pseudo instvar) entries to be shown in an inspector.
Answers a dictionary of aString -> aBlock.
aString is name of extra attribute and MUST start with minus ($-).
aBlock returns the object representing extra attribute
-
inspectorValueListIconFor: anInspector ( an extension from the stx:libtool package )
-
returns the icon to be shown alongside the value list of an inspector
private
-
grow: capacity
-
(comment from inherited method)
change the receiver's size
-
growKeysAndValues
-
duplicate the capacity
-
privateAt: key put: value
-
queries
-
includesKey: aKey
-
(comment from inherited method)
return true, if the argument, aKey is a key in the receiver
-
isEmpty
-
(comment from inherited method)
return true, if the receiver is empty
-
speciesForCollecting
-
(comment from inherited method)
like species, but used when doing collect operations.
Redefined for collections which return a different classes object when doing collect.
removing
-
empty
-
RefactoryBrowser compatibility
-
remove: anAssociation ifAbsent: anExceptionBlock
-
Modified (format): / 14-09-2018 / 15:40:44 / Stefan Vogel
-
removeAll
-
(comment from inherited method)
remove all elements from the receiver. Returns the receiver.
This should be reimplemented in subclasses for better
performance.
-
removeKey: key ifAbsent: aBlock
-
}
testing
-
isDictionary
-
return true, if the receiver is some kind of dictionary;
true returned here - the method is redefined from Object.
-
isFixedSize
-
return true if the receiver cannot grow - this will vanish once
Arrays and Strings learn how to grow ...
visiting
-
acceptVisitor: aVisitor with: aParameter
-
dispatch for visitor pattern; send #visitDictionary:with: to aVisitor
|