[FIX][ENH] SortedCollection robustness & speedup

Georg Gollmann georg.gollmann at tuwien.ac.at
Thu Apr 27 11:32:41 UTC 2000


Fix: Some methods that can destroy the sort order were not blocked.
      addAll: was inconsistent in not returning its argument.
Enhancement: Testing for inclusion is considerably faster now.


'From Squeak2.8alpha of 13 January 2000 [latest update: #2042] on 27 
April 2000 at 1:23:18 pm'!

!SortedCollection methodsFor: 'accessing' stamp: 'go 4/27/2000 11:05'!
at: anInteger put: anObject
	"Storing into a SortedCollection with at:put: is not allowed."

	self shouldNotImplement! !

!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 ]! !

!SortedCollection methodsFor: 'adding' stamp: 'go 4/27/2000 13:19'!
add: newObject

	^super insert: newObject before: (self indexForInserting: newObject)! !

!SortedCollection methodsFor: 'adding' stamp: 'go 4/27/2000 13:16'!
addAll: aCollection
	"Optimize for large additions."

	aCollection size > (self size // 3) ifTrue: [
		aCollection do: [ :each | super addLast: each ].
		self reSort ]
	 ifFalse: [ aCollection do: [ :each | self add: each ]].
	^aCollection! !

!SortedCollection methodsFor: 'adding' stamp: 'go 4/26/2000 17:26'!
addFirst: newObject

	self shouldNotImplement! !

!SortedCollection methodsFor: 'adding' stamp: 'go 4/26/2000 17:10'!
addLast: newObject

	self shouldNotImplement! !

!SortedCollection methodsFor: 'private' stamp: 'go 4/26/2000 17:17'!
insert: anObject before: spot

	self shouldNotImplement! !


-- 
----
Dipl.Ing. Georg Gollmann                TU-Wien, Zentraler Informatikdienst
                                         Wiedner Hauptstr. 8-10
phon:(+43-1) 58801 - 42022              A-1040 Wien
fax: (+43-1) 58801 - 42099
mail:gollmann at zid.tuwien.ac.at
http://macos.tuwien.ac.at/Gollmann.html





More information about the Squeak-dev mailing list