[Pkg] The Trunk: Collections-mt.596.mcz

commits at source.squeak.org commits at source.squeak.org
Fri Jan 16 09:55:22 UTC 2015


Marcel Taeumel uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-mt.596.mcz

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

Name: Collections-mt.596
Author: mt
Time: 16 January 2015, 10:55:07.303 am
UUID: ca58af47-b4d1-6046-810d-27726f7a19e2
Ancestors: Collections-mt.595

some fixes to OrderedDictionary including copy; small part of the protocol of OrderedCollection adopted (#sort, #first, ...).

=============== Diff against Collections-mt.595 ===============

Item was changed:
  Dictionary subclass: #OrderedDictionary
  	instanceVariableNames: 'order lastIndex'
  	classVariableNames: ''
  	poolDictionaries: ''
  	category: 'Collections-Sequenceable'!
  
+ !OrderedDictionary commentStamp: 'mt 1/16/2015 10:42' prior: 0!
- !OrderedDictionary commentStamp: 'mt 1/16/2015 09:08' 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.!
- The growth operation compacts the index and takes O(n) additional time.!

Item was added:
+ ----- Method: OrderedDictionary>>atIndex: (in category 'accessing') -----
+ atIndex: integer
+ 
+ 	^ self atIndex: integer ifAbsent: [self errorOutOfBounds]!

Item was added:
+ ----- Method: OrderedDictionary>>atIndex:ifAbsent: (in category 'accessing') -----
+ atIndex: integer ifAbsent: exceptionBlock
+ 	"As we are sequenceable, provide index-based access."
+ 
+ 	| found |
+ 	found := 0.
+ 	self associationsDo: [:element |
+ 		(found := found + 1) = integer ifTrue: [
+ 			^ element]].
+ 
+ 	^ exceptionBlock value!

Item was added:
+ ----- Method: OrderedDictionary>>eighth (in category 'accessing') -----
+ eighth
+ 	"Answer the eighth element of the receiver.
+ 	Raise an error if there are not enough elements."
+ 
+ 	^ self atIndex: 8!

Item was added:
+ ----- Method: OrderedDictionary>>fifth (in category 'accessing') -----
+ fifth
+ 	"Answer the fifth element of the receiver.
+ 	Raise an error if there are not enough elements."
+ 
+ 	^ self atIndex: 5!

Item was added:
+ ----- Method: OrderedDictionary>>first (in category 'accessing') -----
+ first
+ 	"Answer the first element of the receiver"
+ 
+ 	^ self atIndex: 1!

Item was added:
+ ----- Method: OrderedDictionary>>first: (in category 'accessing') -----
+ first: n
+ 
+ 	"Answer the first n elements of the receiver.
+ 	Raise an error if there are not enough elements."
+ 
+ 	^ self copyFrom: 1 to: n!

Item was added:
+ ----- Method: OrderedDictionary>>fourth (in category 'accessing') -----
+ fourth
+ 	"Answer the fourth element of the receiver.
+ 	Raise an error if there are not enough elements."
+ 
+ 	^ self atIndex: 4!

Item was added:
+ ----- Method: OrderedDictionary>>isSorted (in category 'sorting') -----
+ isSorted
+ 	"Return true if the receiver is sorted by #<=."
+ 	
+ 	self fixEmptySlots.
+ 	^ order
+ 		isSortedBetween: 1
+ 		and: lastIndex!

Item was added:
+ ----- Method: OrderedDictionary>>ninth (in category 'accessing') -----
+ ninth
+ 	"Answer the ninth element of the receiver.
+ 	Raise an error if there are not enough elements."
+ 
+ 	^ self atIndex: 9!

Item was added:
+ ----- Method: OrderedDictionary>>postCopy (in category 'copying') -----
+ postCopy
+ 	"We must not copy associations again but retrieve them from the array, which is already a copy. See super."
+ 
+ 	super postCopy.
+ 	order := order collect: [:association |
+ 		association ifNotNil: [array at: (self scanFor: association key)]].!

Item was added:
+ ----- Method: OrderedDictionary>>second (in category 'accessing') -----
+ second
+ 	"Answer the second element of the receiver.
+ 	Raise an error if there are not enough elements."
+ 
+ 	^ self atIndex: 2!

Item was added:
+ ----- Method: OrderedDictionary>>seventh (in category 'accessing') -----
+ seventh
+ 	"Answer the seventh element of the receiver.
+ 	Raise an error if there are not enough elements."
+ 
+ 	^ self atIndex: 7!

Item was added:
+ ----- Method: OrderedDictionary>>sixth (in category 'accessing') -----
+ sixth
+ 	"Answer the sixth element of the receiver.
+ 	Raise an error if there are not enough elements."
+ 
+ 	^ self atIndex: 6!

Item was added:
+ ----- Method: OrderedDictionary>>sort (in category 'sorting') -----
+ sort
+ 
+ 	self sort: [:a1 :a2| a1 key <= a2 key].!

Item was added:
+ ----- Method: OrderedDictionary>>sort: (in category 'sorting') -----
+ sort: aSortBlock
+ 	"Like in OrderedCollection, sort the associations according to the sort block."
+ 
+ 	self ifNotEmpty: [
+ 		self fixEmptySlots.
+ 		order
+ 			mergeSortFrom: 1
+ 			to: lastIndex
+ 			by: aSortBlock].!

Item was added:
+ ----- Method: OrderedDictionary>>sorted: (in category 'sorting') -----
+ sorted: aSortBlockOrNil
+ 
+ 	^ self copy sort: aSortBlockOrNil!

Item was added:
+ ----- Method: OrderedDictionary>>third (in category 'accessing') -----
+ third
+ 	"Answer the third element of the receiver.
+ 	Raise an error if there are not enough elements."
+ 
+ 	^ self atIndex: 3!



More information about the Packages mailing list