eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'PluggableDictionary':

Home

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

Class: PluggableDictionary


Inheritance:

   Object
   |
   +--Collection
      |
      +--Set
         |
         +--Dictionary
            |
            +--PluggableDictionary
               |
               +--Dolphin::PluggableLookupTable

Package:
stx:libbasic2
Category:
Collections-Unordered
Version:
rev: 1.10 date: 2023/05/12 09:03:32
user: cg
file: PluggableDictionary.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


a dictionary where the hash- and compare functions can be provided externally.
Can be used eg. to implement dictionaries which ignore case differences,
or which map diareses to replacement sequences (as in german: Umlaut-u to ue).

copyright

COPYRIGHT (c) 2014 by Claus Gittinger 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  hashWith: hashFunctionArg compareWith: compareFunctionArg
return a dictionary which hashes using the given hash function
and compare function (both are one-arg blocks)


Instance protocol:

private
o  compareSame: element1 with: element2
compare two elements for being the same.
Here, return the value from compareFunction

o  find: key ifAbsent: aBlock
Look for the key in the receiver. If it is found, return
the index of the association containing the key, otherwise
return the value of evaluating aBlock.
Redefined - since we inherit this code from Set-Dictionary
(one of the seldom cases, where I could make use of multiple inheritance
and inherit from IdentitySet ... sigh)

o  findKeyOrNil: key
Look for the key in the receiver.
If it is found, return return the index of the first unused slot.
Grow the receiver, if key was not found, and no unused slots were present

o  findKeyOrNilOrDeletedEntry: key
Look for the key in the receiver.
If it is found, return return the index of the first unused slot.
Grow the receiver, if key was not found, and no unused slots were present

o  hashFor: aKey
return an initial index given a key.

o  hashWith: hashFunctionArg compareWith: compareFunctionArg
specify how to hash and how to compare elements
(see example on the class side)

queries
o  occurrencesOf: anObject
count & return how often anObject is stored in the dictionary.
This counts values - not keys.
Redefined to use compareFunction, instead of the inherited equality compare.


Examples:


a dictionary which ignores the case of its string-keys:
  |s|

  s := PluggableDictionary
      hashWith:[:k | k asLowercase hash] 
      compareWith:[:a :b | a notNil and:[b notNil and:[a asLowercase = b asLowercase]]].
  s at:'hello' put:123.
  s at:'world' put:222.
  s at:'abc' put:333.
  s at:'Hello'.
  s at:'heLLo'.
  s at:'ABC'.
  s at:'WORLD'.
  s size.
  s includesKey:'heLlo'.  
  s includesKey:'wOrLd'.  
  s includesKey:'wOrLds'.


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Thu, 21 Nov 2024 18:36:27 GMT