Levente Uzonyi uploaded a new version of Collections to project The Inbox:
http://source.squeak.org/inbox/Collections-ul.914.mcz ==================== Summary ==================== Name: Collections-ul.914 Author: ul Time: 28 September 2020, 11:50:07.373304 pm UUID: eb80ed0e-d5ed-4ff5-9206-18cc75e54990 Ancestors: Collections-eem.912 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.912 =============== 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 class 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 class arrayType new: self capacity! - order := self class arrayType new: n + 1 * 3 // 4! |
Free forum by Nabble | Edit this page |