BlockContext's caller is now stored in sender field
[panda.git] / st / Set.st
blob335f55df04331bac1e4562bf2ec5d31fe7321471
2 "testing"
4 Set method!
5 includeAll: aCollection
6         | index |
8         aCollection do: [ :e | self include: e ].
10         ^ aCollection!
12 Set method!
13 includes: anObject
14         | index |
16         (array at: (self find: anObject)) ifNil: [^ false].
18         ^ true!
20 Set method!
21 occurancesOf: anObject
22         (self includes: anObject)
23                 ifTrue: [^ 1]
24                 ifFalse: [^ 0]!
26 "including"
28 Set method!
29 add: anObject
30         ^ self include: anObject!
32 Set method!
33 include: anObject
34         | index |
35         anObject ifNil: [ self error: 'Sets cannot meaningfully contain nil'].
37         index := self find: anObject.
38         (array at: index) ifNotNil: [^ anObject].
39         self at: index include: anObject.
40         ^ anObject!
43 "removing"
45 HashedCollection method!
46 remove: anObject ifAbsent: aBlock
47         | index |
49         index := self find: anObject.
51         (array at: index) ifNil: [^ aBlock value]. 
52         
53         self removeAtIndex: index.
55         ^ anObject!
58 "private"
60 Set method!
61 find: anObject in: anArray
62         | i mask |
64         mask := anArray size - 1.
66         i := (anObject hash bitAnd: mask) + 1.
68         [ | object | 
70           object := anArray at: i.
72           (object = anObject) | (object == nil)
73                   ifTrue: [^ i].
75           i := (i + 106720 bitAnd: mask) + 1.
77         ] repeat!