[squeak-dev] The Trunk: Collections-ar.142.mcz

commits at source.squeak.org commits at source.squeak.org
Wed Sep 30 05:05:18 UTC 2009


Andreas Raab uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ar.142.mcz

==================== Summary ====================

Name: Collections-ar.142
Author: ar
Time: 29 September 2009, 10:04:47 am
UUID: 03cd4bc2-d806-7740-a2b3-5a4024943d81
Ancestors: Collections-ar.141, Collections-ul.141

Merging Collections-ul.141:

- rewritten Set >> #fixCollisionsFrom: and WeakSet >> #fixCollisionsFrom:, they use #scanFor: instead of #findElementOrNil:
- replaced KeyedSet >> #fixCollisionsFrom: with #keyAt:

- added #postCopy to Set and subclasses, to replace it's similar but unique mechanism with #copy and #withArray:, these methods have to be removed in another version, but MethodDictionary >> #postCopy has to be added first.

- Dictionary >> #values doesn't create an unnecessary copy of the result anymore.

=============== Diff against Collections-ar.141 ===============

Item was changed:
  ----- Method: Dictionary>>values (in category 'accessing') -----
  values
  	"Answer a Collection containing the receiver's values."
+ 
+ 	^Array new: self size streamContents: [ :stream |
+ 		self valuesDo: [ :value | stream nextPut: value] ]!
- 	| out |
- 	out := WriteStream on: (Array new: self size).
- 	self valuesDo: [:value | out nextPut: value].
- 	^ out contents!

Item was added:
+ ----- Method: KeyedSet>>keyAt: (in category 'private') -----
+ keyAt: index
+ 	
+ 	^keyBlock value: (array at: index)!

Item was added:
+ ----- Method: Set>>postCopy (in category 'copying') -----
+ postCopy
+ 
+ 	array := array shallowCopy!

Item was changed:
  ----- Method: WeakSet>>fixCollisionsFrom: (in category 'private') -----
+ fixCollisionsFrom: start
+ 	"The element at start has been removed and replaced by flag.
- fixCollisionsFrom: index
- 	"The element at index has been removed and replaced by nil.
  	This method moves forward from there, relocating any entries
+ 	that had been placed below due to collisions with this one.
+ 	We can be sure that there is an empty slot in this collection
+ 	so it's safe to use #scanFor: instead of #findElementOrNil:."
- 	that had been placed below due to collisions with this one"
  
+ 	| element newIndex |
+ 	start + 1 to: array size do: [ :index |
+ 		(element := self keyAt: index) == flag ifTrue: [ ^self ].
+ 		(newIndex := self scanFor: element) = index ifFalse: [
+ 			self swap: index with: newIndex ] ].
+ 	1 to: start do: [ :index |
+ 		(element := self keyAt: index) == flag ifTrue: [ ^self ].
+ 		(newIndex := self scanFor: element) = index ifFalse: [
+ 			self swap: index with: newIndex ] ]
+ !
- 	| length oldIndex newIndex element |
- 
- 	oldIndex := index.
- 	length := array size.
- 	[oldIndex = length
- 			ifTrue: [oldIndex := 1]
- 			ifFalse: [oldIndex := oldIndex + 1].
- 	(element := self keyAt: oldIndex) == flag]
- 		whileFalse: 
- 			[newIndex := self findElementOrNil: element.
- 			oldIndex = newIndex ifFalse: [self swap: oldIndex with: newIndex]]!

Item was added:
+ ----- Method: Dictionary>>postCopy (in category 'copying') -----
+ postCopy
+ 	"Must copy the associations, or later store will affect both the
+ original and the copy"
+ 
+ 	array := array collect: [ :association |
+ 		association ifNotNil: [ association copy ] ]!

Item was changed:
  ----- Method: Set>>fixCollisionsFrom: (in category 'private') -----
+ fixCollisionsFrom: start
+ 	"The element at start has been removed and replaced by nil.
- fixCollisionsFrom: index
- 	"The element at index has been removed and replaced by nil.
  	This method moves forward from there, relocating any entries
+ 	that had been placed below due to collisions with this one.
+ 	We can be sure that there is an empty slot in this collection
+ 	so it's safe to use #scanFor: instead of #findElementOrNil:."
- 	that had been placed below due to collisions with this one"
  
+ 	| element newIndex |
+ 	start + 1 to: array size do: [ :index |
+ 		(element := self keyAt: index) ifNil: [ ^self ].
+ 		(newIndex := self scanFor: element) = index ifFalse: [
+ 			self swap: index with: newIndex ] ].
+ 	1 to: start do: [ :index |
+ 		(element := self keyAt: index) ifNil: [ ^self ].
+ 		(newIndex := self scanFor: element) = index ifFalse: [
+ 			self swap: index with: newIndex ] ]!
- 	| length oldIndex newIndex element |
- 
- 	oldIndex := index.
- 	length := array size.
- 	[oldIndex = length
- 			ifTrue: [oldIndex := 1]
- 			ifFalse: [oldIndex := oldIndex + 1].
- 	(element := self keyAt: oldIndex) == nil]
- 		whileFalse: 
- 			[newIndex := self findElementOrNil: element.
- 			oldIndex = newIndex ifFalse: [self swap: oldIndex with: newIndex]]!

Item was removed:
- ----- Method: KeyedSet>>fixCollisionsFrom: (in category 'private') -----
- fixCollisionsFrom: index
- 	"The element at index has been removed and replaced by nil.
- 	This method moves forward from there, relocating any entries
- 	that had been placed below due to collisions with this one"
- 	| length oldIndex newIndex element |
- 	oldIndex := index.
- 	length := array size.
- 	[oldIndex = length
- 			ifTrue: [oldIndex :=  1]
- 			ifFalse: [oldIndex :=  oldIndex + 1].
- 	(element := self keyAt: oldIndex) == nil]
- 		whileFalse: 
- 			[newIndex := self findElementOrNil: (keyBlock value: element).
- 			oldIndex = newIndex ifFalse: [self swap: oldIndex with: newIndex]]!




More information about the Squeak-dev mailing list