PluggableDictionary.st
author Claus Gittinger <cg@exept.de>
Tue, 18 Feb 2014 22:21:01 +0100
changeset 3178 5d24b4312240
parent 3175 6e8b85b13546
child 4021 12a732f6d443
permissions -rw-r--r--
don't call compareFunction on nil
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
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
Dictionary subclass:#PluggableDictionary
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
	instanceVariableNames:'hashFunction compareFunction'
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	classVariableNames:''
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	category:'Collections-Unordered'
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!PluggableDictionary class methodsFor:'documentation'!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
copyright
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 (c) 2014 by Claus Gittinger
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
              All Rights Reserved
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
 This software is furnished under a license and may be used
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 only in accordance with the terms of that license and with the
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 be provided or otherwise made available to, or used by, any
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 other person.  No title to or ownership of the software is
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 hereby transferred.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
documentation
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
    a dictionary where the hash- and compare functions can be provided externally.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    [author:]
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
        Claus Gittinger
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
examples
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    |s|
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 := PluggableDictionary
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
        hashWith:[:k | k size] 
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
        compareWith:[:a :b | a notNil and:[b notNil and:[a asLowercase = b asLowercase]]].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    s at:'hello' put:123.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    s at:'world' put:222.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    s at:'abc' put:333.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
    s at:'Hello'.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    s at:'heLLo'.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
    s at:'ABC'.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
    s at:'WORLD'.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    s size.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
    s includesKey:'heLlo'.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
    s includesKey:'wOrLd'.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
    s includesKey:'wOrLds'.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
! !
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
!PluggableDictionary class methodsFor:'instance creation'!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
hashWith:hashFunctionArg compareWith:compareFunctionArg
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    ^ self new hashWith:hashFunctionArg compareWith:compareFunctionArg
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
! !
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
!PluggableDictionary methodsFor:'accessing'!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
hashWith:hashFunctionArg compareWith:compareFunctionArg 
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
    hashFunction := hashFunctionArg.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
    compareFunction := compareFunctionArg.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
! !
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
!PluggableDictionary methodsFor:'private'!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
compareSame:element1 with:element2
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
    "compare two elements for being the same. 
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
     Here, return the value from compareFunction"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    ^ compareFunction value:element1 value:element2
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
emptyCollectionForKeys
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
    "return an empty collection used for keys.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
     Here, an IdentitySet is returned.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
     Made a separate method to allow redefinition for different kind of
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
     containers in subclasses."
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
    ^ PluggableSet new:(self size) hashWith:hashFunction compareWith:compareFunction
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
find:key ifAbsent:aBlock
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
    "Look for the key in the receiver.  If it is found, return
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
     the index of the association containing the key, otherwise
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
     return the value of evaluating aBlock.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
     Redefined - since we inherit this code from Set-Dictionary
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
     (one of the seldom cases, where I could make use of multiple inheritance
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
     and inherit from IdentitySet ... sigh)"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
    |index  "{ Class:SmallInteger }"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
     length "{ Class:SmallInteger }"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
     startIndex probe|
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
    length := keyArray basicSize.
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
"/    length < 10 ifTrue:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
"/      "assuming, that for small dictionaries the overhead of hashing
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
"/       is large ... maybe that proves wrong (if overhead of comparing
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
"/       is high)"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
"/      ^ keyArray identityIndexOf:key ifAbsent:aBlock.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
"/    ].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
"/
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
    startIndex := index := self initialIndexForKey:key.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
    [true] whileTrue:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
        probe := keyArray basicAt:index.
3178
5d24b4312240 don't call compareFunction on nil
Claus Gittinger <cg@exept.de>
parents: 3175
diff changeset
   125
        probe notNil ifTrue:[
5d24b4312240 don't call compareFunction on nil
Claus Gittinger <cg@exept.de>
parents: 3175
diff changeset
   126
            (compareFunction value:probe value:key) ifTrue:[^ index].         "<<<< == is different from inherited"
5d24b4312240 don't call compareFunction on nil
Claus Gittinger <cg@exept.de>
parents: 3175
diff changeset
   127
        ].
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
        (self slotIsEmpty:probe) ifTrue:[^ aBlock value].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
        index == length ifTrue:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
            index := 1
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
        ] ifFalse:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
            index := index + 1
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
        ].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
        index == startIndex ifTrue:[^ aBlock value]
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
    ]
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
findKeyOrNil:key
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
    "Look for the key in the receiver.  
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
     If it is found, return return the index of the first unused slot. 
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
     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
   143
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
    |index  "{ Class:SmallInteger }"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
     length "{ Class:SmallInteger }"
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
     startIndex probe 
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
     delIndex "{ Class:SmallInteger }" |
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
    delIndex := 0.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
    length := keyArray basicSize.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
    startIndex := index := self initialIndexForKey:key.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
    [true] whileTrue:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
        probe := keyArray basicAt:index.
3178
5d24b4312240 don't call compareFunction on nil
Claus Gittinger <cg@exept.de>
parents: 3175
diff changeset
   156
        probe notNil ifTrue:[
5d24b4312240 don't call compareFunction on nil
Claus Gittinger <cg@exept.de>
parents: 3175
diff changeset
   157
            (compareFunction value:probe value:key) ifTrue:[^ index].
5d24b4312240 don't call compareFunction on nil
Claus Gittinger <cg@exept.de>
parents: 3175
diff changeset
   158
        ].
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
        (self slotIsEmpty:probe) ifTrue:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
            delIndex == 0 ifTrue:[^ index].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
            keyArray basicAt:delIndex put:nil.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
            ^ delIndex
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
        ].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
        probe == DeletedEntry ifTrue:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
            delIndex == 0 ifTrue:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
                delIndex := index
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
            ]
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
        ].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
        index == length ifTrue:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
            index := 1
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
        ] ifFalse:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
            index := index + 1
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   175
        ].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   176
        index == startIndex ifTrue:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
            delIndex ~~ 0 ifTrue:[
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
                keyArray basicAt:delIndex put:nil.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
                ^ delIndex
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
            ].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
            ^ self grow findKeyOrNil:key
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
        ].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
    ]
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
hashFor:aKey
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
    "return an initial index given a key."
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
    ^ hashFunction value:aKey
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
! !
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
!PluggableDictionary methodsFor:'testing'!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
occurrencesOf:anObject
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
    "count & return how often anObject is stored in the dictionary.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
     This counts values - not keys.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
     Redefined to use #== (identity compare), NOT equality compare."
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
    |cnt|
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
    anObject isNil ifTrue:[^ super occurrencesOf:anObject].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
    cnt := 0.
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
    valueArray do:[:element |
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
       (compareFunction value:element value:anObject) ifTrue:[cnt := cnt + 1]
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
    ].
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
    ^ cnt
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
! !
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
!PluggableDictionary class methodsFor:'documentation'!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
version
3178
5d24b4312240 don't call compareFunction on nil
Claus Gittinger <cg@exept.de>
parents: 3175
diff changeset
   213
    ^ '$Header: /cvs/stx/stx/libbasic2/PluggableDictionary.st,v 1.2 2014-02-18 21:21:01 cg Exp $'
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
!
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
version_CVS
3178
5d24b4312240 don't call compareFunction on nil
Claus Gittinger <cg@exept.de>
parents: 3175
diff changeset
   217
    ^ '$Header: /cvs/stx/stx/libbasic2/PluggableDictionary.st,v 1.2 2014-02-18 21:21:01 cg Exp $'
3175
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
! !
6e8b85b13546 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219