eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'SmallDictionary':

Home

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

Class: SmallDictionary


Inheritance:

   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

Description:


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:]


Related information:

    Dictionary
    MethodDictionary

Class protocol:

instance creation
o  new
(comment from inherited method)
return an instance of myself without indexed variables

o  new: capacity
(comment from inherited method)
return an instance of myself with anInteger indexed variables


Instance protocol:

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

o  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.

o  keys
return a collection containing the keys of the receiver

o  order
returns the keys in the order of their appearance

o  size
return the number of elements in the receiver.

adding
o  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.

o  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
o  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
o  do: aBlock
enumerate the values

o  keysAndValuesDo: aBlock
(comment from inherited method)
evaluate aBlock for each key and value

o  keysDo: aBlock
(comment from inherited method)
evaluate the argument, aBlock for every key in the collection.

initialize-release
o  initialize: capacity

inspecting
o  inspector2TabLabel
( an extension from the stx:libtool package )
label of the main tab

o  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

o  inspectorValueListIconFor: anInspector
( an extension from the stx:libtool package )
returns the icon to be shown alongside the value list of an inspector

private
o  grow: capacity
(comment from inherited method)
change the receiver's size

o  growKeysAndValues
duplicate the capacity

o  privateAt: key put: value

queries
o  includesKey: aKey
(comment from inherited method)
return true, if the argument, aKey is a key in the receiver

o  isEmpty
(comment from inherited method)
return true, if the receiver is empty

o  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
o  empty
RefactoryBrowser compatibility

o  remove: anAssociation ifAbsent: anExceptionBlock
Modified (format): / 14-09-2018 / 15:40:44 / Stefan Vogel

o  removeAll
(comment from inherited method)
remove all elements from the receiver. Returns the receiver.
This should be reimplemented in subclasses for better
performance.

o  removeKey: key ifAbsent: aBlock
}

testing
o  isDictionary
return true, if the receiver is some kind of dictionary;
true returned here - the method is redefined from Object.

o  isFixedSize
return true if the receiver cannot grow - this will vanish once
Arrays and Strings learn how to grow ...

visiting
o  acceptVisitor: aVisitor with: aParameter
dispatch for visitor pattern; send #visitDictionary:with: to aVisitor



ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Thu, 26 May 2022 11:19:09 GMT