PluggableDictionary.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 4803 5040e2b3e0c5
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 2014 by Claus Gittinger
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
4021
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
    14
"{ NameSpace: Smalltalk }"
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
    15
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
Dictionary subclass:#PluggableDictionary
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:'hashFunction compareFunction'
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	category:'Collections-Unordered'
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!PluggableDictionary class methodsFor:'documentation'!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
copyright
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 2014 by Claus Gittinger
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
              All Rights Reserved
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
documentation
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    a dictionary where the hash- and compare functions can be provided externally.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    [author:]
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
        Claus Gittinger
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
examples
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    |s|
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    s := PluggableDictionary
4021
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
    53
        hashWith:[:k | k asLowercase hash] 
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
        compareWith:[:a :b | a notNil and:[b notNil and:[a asLowercase = b asLowercase]]].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    s at:'hello' put:123.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
    s at:'world' put:222.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    s at:'abc' put:333.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
    s at:'Hello'.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
    s at:'heLLo'.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    s at:'ABC'.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
    s at:'WORLD'.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
    s size.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
    s includesKey:'heLlo'.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
    s includesKey:'wOrLd'.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
    s includesKey:'wOrLds'.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
! !
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
!PluggableDictionary class methodsFor:'instance creation'!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
hashWith:hashFunctionArg compareWith:compareFunctionArg
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
    ^ self new hashWith:hashFunctionArg compareWith:compareFunctionArg
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
! !
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
!PluggableDictionary methodsFor:'accessing'!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
hashWith:hashFunctionArg compareWith:compareFunctionArg 
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
    hashFunction := hashFunctionArg.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    compareFunction := compareFunctionArg.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
! !
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
!PluggableDictionary methodsFor:'private'!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
compareSame:element1 with:element2
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
    "compare two elements for being the same. 
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
     Here, return the value from compareFunction"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    ^ compareFunction value:element1 value:element2
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
find:key ifAbsent:aBlock
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
    "Look for the key in the receiver.  If it is found, return
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
     the index of the association containing the key, otherwise
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
     return the value of evaluating aBlock.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
     Redefined - since we inherit this code from Set-Dictionary
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
     (one of the seldom cases, where I could make use of multiple inheritance
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
     and inherit from IdentitySet ... sigh)"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
    |index  "{ Class:SmallInteger }"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
     length "{ Class:SmallInteger }"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
     startIndex probe|
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
    length := keyArray basicSize.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
"/
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
"/    length < 10 ifTrue:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
"/      "assuming, that for small dictionaries the overhead of hashing
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
"/       is large ... maybe that proves wrong (if overhead of comparing
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
"/       is high)"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
"/      ^ keyArray identityIndexOf:key ifAbsent:aBlock.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
"/    ].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
"/
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
    startIndex := index := self initialIndexForKey:key.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
4021
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   116
    [
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
        probe := keyArray basicAt:index.
4021
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   118
        probe isNil ifTrue:[
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   119
            ^ aBlock value.
3178
5d24b4312240 don't call compareFunction on nil
Claus Gittinger <cg@exept.de>
parents: 3175
diff changeset
   120
        ].
4021
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   121
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   122
        (probe ~~ DeletedEntry 
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   123
         and:[compareFunction value:probe value:key]) ifTrue:[ "<<<< == is different from inherited"
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   124
            ^ index
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   125
         ].         
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
        index == length ifTrue:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
            index := 1
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
        ] ifFalse:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
            index := index + 1
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
        ].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
        index == startIndex ifTrue:[^ aBlock value]
4021
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   133
    ] loop.
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
findKeyOrNil:key
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
    "Look for the key in the receiver.  
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
     If it is found, return return the index of the first unused slot. 
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
     Grow the receiver, if key was not found, and no unused slots were present"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
    |index  "{ Class:SmallInteger }"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
     length "{ Class:SmallInteger }"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
     startIndex probe 
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
     delIndex "{ Class:SmallInteger }" |
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
    delIndex := 0.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
    length := keyArray basicSize.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
    startIndex := index := self initialIndexForKey:key.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
4021
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   151
    [
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
        probe := keyArray basicAt:index.
4021
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   153
        probe isNil ifTrue:[
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
            delIndex == 0 ifTrue:[^ index].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
            keyArray basicAt:delIndex put:nil.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
            ^ delIndex
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
        ].
4021
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   158
        (probe == DeletedEntry and:[delIndex == 0]) ifTrue:[
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   159
            delIndex := index.
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   160
        ] ifFalse:[
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   161
            (compareFunction value:probe value:key) ifTrue:[^ index]
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
        ].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
        index == length ifTrue:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
            index := 1
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
        ] ifFalse:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
            index := index + 1
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
        ].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
        index == startIndex ifTrue:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
            delIndex ~~ 0 ifTrue:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
                keyArray basicAt:delIndex put:nil.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
                ^ delIndex
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
            ].
4021
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   174
            self grow.
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   175
            length := keyArray basicSize.
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   176
            startIndex := index := self initialIndexForKey:key.
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
        ].
4021
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   178
    ] loop.
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   179
!
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   180
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   181
findKeyOrNilOrDeletedEntry:key
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   182
    "Look for the key in the receiver.  
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   183
     If it is found, return return the index of the first unused slot. 
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   184
     Grow the receiver, if key was not found, and no unused slots were present"
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   185
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   186
    |index  "{ Class:SmallInteger }"
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   187
     length "{ Class:SmallInteger }"
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   188
     startIndex probe 
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   189
     delIndex "{ Class:SmallInteger }" |
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   190
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   191
    delIndex := 0.
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   192
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   193
    length := keyArray basicSize.
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   194
    startIndex := index := self initialIndexForKey:key.
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   195
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   196
    [
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   197
        probe := keyArray basicAt:index.
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   198
        probe isNil ifTrue:[
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   199
            delIndex == 0 ifTrue:[^ index].
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   200
            ^ delIndex
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   201
        ].
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   202
        (probe == DeletedEntry and:[delIndex == 0]) ifTrue:[
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   203
            delIndex := index.
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   204
        ] ifFalse:[
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   205
            (compareFunction value:probe value:key) ifTrue:[^ index]
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   206
        ].
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   207
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   208
        index == length ifTrue:[
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   209
            index := 1
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   210
        ] ifFalse:[
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   211
            index := index + 1
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   212
        ].
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   213
        index == startIndex ifTrue:[
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   214
            delIndex ~~ 0 ifTrue:[
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   215
                ^ delIndex
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   216
            ].
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   217
            self grow.
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   218
            length := keyArray basicSize.
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   219
            startIndex := index := self initialIndexForKey:key.
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   220
        ].
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   221
    ] loop.
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
hashFor:aKey
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
    "return an initial index given a key."
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
    ^ hashFunction value:aKey
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
! !
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
4803
5040e2b3e0c5 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4023
diff changeset
   230
!PluggableDictionary methodsFor:'queries'!
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
occurrencesOf:anObject
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
    "count & return how often anObject is stored in the dictionary.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
     This counts values - not keys.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
     Redefined to use #== (identity compare), NOT equality compare."
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
    |cnt|
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
    anObject isNil ifTrue:[^ super occurrencesOf:anObject].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
    cnt := 0.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
    valueArray do:[:element |
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
       (compareFunction value:element value:anObject) ifTrue:[cnt := cnt + 1]
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
    ].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
    ^ cnt
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
! !
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
!PluggableDictionary class methodsFor:'documentation'!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
version
4021
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   251
    ^ '$Header$'
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
version_CVS
4021
12a732f6d443 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 3178
diff changeset
   255
    ^ '$Header$'
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
! !
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257