Georg,
I am afraid your implementation of the #includes: method only works for the particular cases where the object is arithmetically compared directly.
I took a stab at (re)implementing #includes and #indexOf: for the SequenceableCollection classes.
'From Squeak2.8alpha of 19 January 2000 [latest update: #2042] on 26 April 2000 at 4:01:18 pm'!
!SequenceableCollection methodsFor: 'accessing' stamp: 'fm 4/26/2000 15:13'!
indexOf: anElement "Answer the index of anElement within the receiver. If the receiver does not contain anElement, answer 0." 1 to: self size do: [:i | (self at: i) = anElement ifTrue: [^ i]]. ^ 0! !
!SequenceableCollection methodsFor: 'testing' stamp: 'fm 4/26/2000 15:36'!
includes: anObject ^(self indexOf: anObject) ~~ 0! !
!OrderedCollection methodsFor: 'accessing' stamp: 'fm 4/26/2000 15:39'!
indexOf: anObject firstIndex to: lastIndex do: [:index | anObject = (array at: index) ifTrue: [^index + 1 - firstIndex]]. ^ 0! !
!SortedCollection methodsFor: 'accessing' stamp: 'fm 4/26/2000 15:08'!
indexOf: newObject | index low | low := self indexForInserting: newObject. sortBlock isNil ifTrue: [ index := low -1. ^[index >= firstIndex and: [(array at: index) = newObject] ] ifTrue: [low - firstIndex] ifFalse: [0]] ifFalse: [ index := low -1. [index >= firstIndex and: [(sortBlock value: (array at: index) value: newObject) and: [sortBlock value: newObject value: (array at: index)]]] whileTrue: [(array at: index) = newObject ifTrue: [^index + 1 - firstIndex]. index := index - 1]. index := low. [index <= lastIndex and: [(sortBlock value: (array at: index) value: newObject) not and: [(sortBlock value: newObject value: (array at: index)) not]]] whileTrue: [(array at: index) = newObject ifTrue: [^index + 1 - firstIndex]. index := index + 1]. ^0]! !
Cheers,
Florin
P.S. I have also included the above code as an attachement(See attached file: collections.1.cs)
<snip>
!SortedCollection methodsFor: 'testing' stamp: 'go 4/27/2000 13:05'! includes: anObject "Answer whether anObject is one of the receiver's elements."
| idx | idx := self indexForInserting: anObject. ^(array atPin: idx) = anObject or: [(array atPin: idx - 1) = anObject ]! !
<snip>
squeak-dev@lists.squeakfoundation.org