[squeak-dev] The Trunk: Collections-ul.915.mcz

commits at source.squeak.org commits at source.squeak.org
Sun Oct 4 22:31:44 UTC 2020


Levente Uzonyi uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-ul.915.mcz

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

Name: Collections-ul.915
Author: ul
Time: 5 October 2020, 12:30:33.597525 am
UUID: 93341c2a-ebb2-4d2b-abee-e3f42f509836
Ancestors: Collections-eem.913

HashedCollection changes:
- make #capacity return the actual capacity of the collection instead of the size of the internal array. This change is obviously not backwards compatible.
- improve the performance of #isEmpty when tally is 0

OrderedDictionary changes:
- make it a subclass of PluggableDictionary. This lets one create e.g. an ordered identity dictionary without creating a subclass with duplicated behavior
- simplify #initialize and #growTo: now that #capacity is accurate

=============== Diff against Collections-eem.913 ===============

Item was changed:
  ----- Method: HashedCollection>>capacity (in category 'accessing') -----
  capacity
+ 	"Answer the current capacity of the receiver - aka the number of elements the receiver can hold without growing."
- 	"Answer the current capacity of the receiver."
  
+ 	^ array size * 3 // 4!
- 	^ array size!

Item was changed:
  ----- Method: HashedCollection>>isEmpty (in category 'testing') -----
  isEmpty
  	"For non-weak collections, we can use the tally to speed up the empty check. For weak collections, we must use the traditional way because the tally is unreliable. Also see #size vs. #slowSize."
  
+ 	tally = 0 ifTrue: [ ^true ].
+ 	^array class isWeak and: [ super isEmpty ]!
- 	^ array class isWeak
- 		ifFalse: [ tally = 0 ]
- 		ifTrue: [ super isEmpty ]!

Item was changed:
  ----- Method: HashedCollection>>removeAll (in category 'removing') -----
  removeAll
  	"remove all elements from this collection.
  	Preserve the capacity"
  	
+ 	self initialize: array size!
- 	self initialize: self capacity!

Item was changed:
+ PluggableDictionary subclass: #OrderedDictionary
- Dictionary subclass: #OrderedDictionary
  	instanceVariableNames: 'order'
  	classVariableNames: ''
  	poolDictionaries: ''
  	category: 'Collections-Sequenceable'!
  
  !OrderedDictionary commentStamp: 'mt 1/16/2015 10:42' prior: 0!
  I am an ordered dictionary. I have an additional index (called 'order') to keep track of the insertion order of my associations.
  
  The read access is not affected by the additional index.
  
  The index is updated in O(1) [time] when inserting new keys. For present keys, that insertion involves actions in O(n) to move the respective element to the end of the order.
  
  The growth operation compacts the index and takes O(n) additional time.
  
  NOTE: This is still no instance of SequenceableCollection. Having this, some protocols are missing and may require working on #associations, which is an Array and thus sequenceable.!

Item was changed:
  ----- Method: OrderedDictionary>>growTo: (in category 'private') -----
  growTo: anInteger
  
- 	| oldOrder |
  	super growTo: anInteger.
+ 	order := order grownBy: self capacity - order size!
- 	oldOrder := order.
- 	"Grow only to 75%. See #atNewIndex:put: in HashedCollection."
- 	order := self arrayType new: anInteger + 1 * 3 // 4.
- 	order
- 		replaceFrom: 1
- 		to: tally
- 		with: oldOrder
- 		startingAt: 1!

Item was changed:
  ----- Method: OrderedDictionary>>initialize: (in category 'private') -----
  initialize: n
  
  	super initialize: n.
+ 	order := self arrayType new: self capacity!
- 	order := self arrayType new: n + 1 * 3 // 4!



More information about the Squeak-dev mailing list