eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'MethodDictionary':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: MethodDictionary


Inheritance:

   Object
   |
   +--Collection
      |
      +--KeyedCollection
         |
         +--MethodDictionary

Package:
stx:libbasic
Category:
Kernel-Methods
Version:
rev: 1.53 date: 2023/08/02 16:14:48
user: stefan
file: MethodDictionary.st directory: libbasic
module: stx stc-classLibrary: libbasic

Description:


Instances of MethodDictionary store selector/method associations
in classes. Conceptionally, they behave like IdentityDictionaries, but are
implemented using a single array (instead of Dictionary, which uses
two arrays to store keys and values separately).
Also, they do not use hashing, since due to caching in the VM, hashing
does not make too much of a difference in speed, but complicates the 
VM implementation.

copyright

COPYRIGHT (c) 1995 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.

Class protocol:

instance creation
o  new
create and return an empty methodDictionary.
Because mDicts cannot grow, we return a singleton
(if any selectors are added later, a new instance
will be created anyway).
Using a singleton will speed up dynamic creation of
new classes which will be filled in later

o  new: sz
create and return a new methodDictionary holding sz
key->value associations

o  withAll: aDictionary
create a MethodDictionary from another Dictionary

Usage example(s):

        |d|

        d := Dictionary withKeys:#(a b c d e) andValues:#(1 2 3 4 5).
        MethodDictionary withAll:d.

o  withKeys: keys andValues: values
create a MethodDictionary from a key (selector) array and value (method) array

queries
o  isBuiltInClass
this class is known by the run-time-system


Instance protocol:

accessing
o  at: key ifAbsent: exceptionBlock
return the element indexed by aKey -
return result of exceptionBlock if no element is stored under aKey

o  at: key put: value
set the value for a given key, which is supposed to be a symbol.
In contrast to dictionaries, we allow adding elements only, if there is an
empty slot (nil key) present.

o  at: key putOrAppend: value
set the value for a given key, which is supposed to be a symbol.
In contrast to dictionaries, we allow adding elements only, if there is an
empty slot (nil key) present.
Otherwise a new MethodDictionary is created & returned

o  keyAtIdenticalValue: value ifAbsent: exceptionBlock
return the first key with value -
return result of exceptionBlock if no key can be found.
This is a slow access, since the receiver is searched sequentially.
NOTICE:
The value is searched using identity compare

o  keyAtValue: value
return the key under which value is stored.
Raise an error if not found.
This is a slow access, since the receiver is searched sequentially.
NOTICE:
The value is searched using identity compare.
use #keyAtEqualValue:ifAbsent: to compare for equality.

o  keyAtValue: value ifAbsent: exceptionBlock
return the key under which value is stored.
If not found, return the value from evaluating exceptionBlock.
This is a slow access, since the receiver is searched sequentially.
NOTICE:
The value is searched using identity compare;
use #keyAtEqualValue:ifAbsent: to compare for equality.

o  values
return a collection containing all values of the receiver.
Redefined to care for emptied slots.

enumerating
o  do: aBlock
evaluate aBlock for each value (i.e. each method)

o  includesIdenticalKey: searchedKey
return true, if the argument, aKey is a key in the receiver

o  keysAndValuesDo: aBlock
evaluate the 2 arg block aBlock for each key (i.e. each selector)
and each value (i.e. each method)

o  keysDo: aBlock
evaluate aBlock for each key (i.e. each selector)

private
o  atIndex: idx putKey: key andValue: value
set the key, which is supposed to be a symbol,
and the value at idx.
Only use this to initialize a methodDictionary fast,
when the set of methods is known beforehand
(avoids search for nil slots)

o  compressed
compress - return either myself or a new, compressed MethodDictionary

queries
o  fastSizeOr0
optimization for subclasses that can provide the collection's size in a fast way

o  size
return the number of elements (associations) in the receiver

o  speciesForAdding
like species, but redefined for collections which cannot grow easily.
Used by functions which create a growing collection (see collect:with:, for example)

o  speciesForCollecting
like species, but used when doing collect operations.
Redefined for collections which return a different classes object when doing collect.

removing
o  removeKey: key ifAbsent: failBlock
remove key from dictionary,
return the value previously stored there.
If it was not in the collection return the result
from evaluating failBlock.
We actually do not remove it, but set it to nil.

o  removeKeyAndCompress: key
remove key from dictionary.
A new, compressed MethodDictionary will be returned,
or nil, if key is not present.

testing
o  isDictionary
(comment from inherited method)
return true if the receiver is some kind of dictionary;
false returned here - the method is only redefined in Dictionary.



ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 02 Nov 2024 21:18:16 GMT