1
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
Set subclass:#IdentitySet
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Collections-Unordered'
|
|
18 |
!
|
|
19 |
|
|
20 |
IdentitySet comment:'
|
|
21 |
|
|
22 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
|
23 |
All Rights Reserved
|
|
24 |
|
|
25 |
same as a Set but compares elements using == (i.e. they must be identical
|
|
26 |
- not just equal in structure).
|
|
27 |
Since compare is on identity, hashing is also done via
|
|
28 |
identityHash instead of hash.
|
|
29 |
|
3
|
30 |
$Header: /cvs/stx/stx/libbasic/Attic/IdSet.st,v 1.3 1993-10-13 00:16:12 claus Exp $
|
1
|
31 |
|
|
32 |
written jan 93 by claus
|
|
33 |
'!
|
|
34 |
|
|
35 |
!IdentitySet methodsFor:'private'!
|
|
36 |
|
|
37 |
find:key ifAbsent:aBlock
|
|
38 |
"Look for the key in the receiver. If it is found, return
|
|
39 |
the index of the slot containing the key, otherwise
|
|
40 |
return the value of evaluating aBlock.
|
|
41 |
Redefined to compare for identity instead of equality"
|
|
42 |
|
|
43 |
|index "{ Class:SmallInteger }"
|
3
|
44 |
length startIndex probe |
|
1
|
45 |
|
|
46 |
length := contentsArray basicSize.
|
|
47 |
startIndex := key identityHash \\ length + 1.
|
|
48 |
|
|
49 |
index := startIndex.
|
|
50 |
[true] whileTrue:[
|
|
51 |
probe := (contentsArray basicAt:index).
|
|
52 |
probe == key ifTrue:[^ index].
|
|
53 |
probe isNil ifTrue:[^ aBlock value].
|
|
54 |
|
|
55 |
index == length ifTrue:[
|
|
56 |
index := 1
|
|
57 |
] ifFalse:[
|
|
58 |
index := index + 1
|
|
59 |
].
|
|
60 |
index == startIndex ifTrue:[
|
|
61 |
^ aBlock value
|
|
62 |
]
|
|
63 |
]
|
|
64 |
!
|
|
65 |
|
|
66 |
findElementOrNil:key
|
|
67 |
"Look for the key in the receiver. Redefined to compare for
|
|
68 |
identity instead of equality"
|
|
69 |
|
|
70 |
|index "{ Class:SmallInteger }"
|
3
|
71 |
length startIndex probe |
|
1
|
72 |
|
|
73 |
length := contentsArray basicSize.
|
|
74 |
startIndex := key identityHash \\ length + 1.
|
|
75 |
|
|
76 |
index := startIndex.
|
|
77 |
[true] whileTrue:[
|
|
78 |
probe := contentsArray basicAt:index.
|
|
79 |
(probe isNil or: [key == probe]) ifTrue:[^ index].
|
|
80 |
|
|
81 |
index == length ifTrue:[
|
|
82 |
index := 1
|
|
83 |
] ifFalse:[
|
|
84 |
index := index + 1
|
|
85 |
].
|
|
86 |
index == startIndex ifTrue: [
|
|
87 |
^ self grow findElementOrNil:key
|
|
88 |
]
|
|
89 |
]
|
|
90 |
! !
|