IdentityDictionary.st
changeset 39 bcf183a31bbb
parent 13 62303f84ff5f
child 77 6c38ca59927f
equal deleted inserted replaced
38:454b1b94a48e 39:bcf183a31bbb
    24 
    24 
    25 same as a Dictionary but key must be identical - not just equal.
    25 same as a Dictionary but key must be identical - not just equal.
    26 Since compare is on identity keys, hashing is also done via
    26 Since compare is on identity keys, hashing is also done via
    27 identityHash instead of hash.
    27 identityHash instead of hash.
    28 
    28 
    29 $Header: /cvs/stx/stx/libbasic/IdentityDictionary.st,v 1.5 1993-12-11 00:49:19 claus Exp $
    29 $Header: /cvs/stx/stx/libbasic/IdentityDictionary.st,v 1.6 1994-01-09 21:17:23 claus Exp $
    30 
    30 
    31 written jul 92 by claus
    31 written jul 92 by claus
    32 '!
    32 '!
    33 
    33 
    34 !IdentityDictionary methodsFor:'accessing'!
    34 !IdentityDictionary methodsFor:'accessing'!
    37     "return the key whose value equals the argument, the value of the 
    37     "return the key whose value equals the argument, the value of the 
    38      exceptionBlock if none is found.
    38      exceptionBlock if none is found.
    39      This is a slow access, since there is no fast reverse mapping"
    39      This is a slow access, since there is no fast reverse mapping"
    40 
    40 
    41     keyArray keysAndValuesDo:[:index :aKey |
    41     keyArray keysAndValuesDo:[:index :aKey |
    42         aKey notNil ifTrue:[
    42         (aKey notNil and:[aKey ~~ DeletedEntry]) ifTrue:[
    43             (valueArray at:index) == aValue ifTrue:[^ aKey].
    43             (valueArray at:index) == aValue ifTrue:[^ aKey].
    44         ]
    44         ]
    45     ].
    45     ].
    46     ^ exceptionBlock value
    46     ^ exceptionBlock value
    47 ! !
    47 ! !
    61     startIndex := key identityHash \\ length + 1.
    61     startIndex := key identityHash \\ length + 1.
    62 
    62 
    63     index := startIndex.
    63     index := startIndex.
    64     [true] whileTrue:[
    64     [true] whileTrue:[
    65         probe := keyArray basicAt:index.
    65         probe := keyArray basicAt:index.
       
    66         probe == DeletedEntry ifTrue:[
       
    67             keyArray basicAt:index put:nil.
       
    68             ^ index
       
    69         ].
    66         (probe isNil or: [probe == key]) ifTrue:[^ index].
    70         (probe isNil or: [probe == key]) ifTrue:[^ index].
    67 
    71 
    68         index == length ifTrue:[
    72         index == length ifTrue:[
    69             index := 1
    73             index := 1
    70         ] ifFalse:[
    74         ] ifFalse:[