Frank Shearar uploaded a new version of System to project The Trunk:
http://source.squeak.org/trunk/System-fbs.621.mcz ==================== Summary ==================== Name: System-fbs.621 Author: fbs Time: 24 November 2013, 12:46:55.775 pm UUID: e2fe5f86-8d22-f843-af93-4a2bfb9aec7c Ancestors: System-fbs.620 Move LRUCache from System to Collections, because that's a more sensible home. This also has the nice property that it breaks the Balloon->System dependency. =============== Diff against System-fbs.620 =============== Item was removed: - Object subclass: #LRUCache - instanceVariableNames: 'size factory calls hits values' - classVariableNames: '' - poolDictionaries: '' - category: 'System-Support'! - - !LRUCache commentStamp: '<historical>' prior: 0! - I'm a cache of values, given a key I return a Value from the cache or from the factory! Item was removed: - ----- Method: LRUCache class>>size:factory: (in category 'instance creation') ----- - size: aNumber factory: aBlock - "answer an instance of the receiver" - ^ self new initializeSize: aNumber factory: aBlock! Item was removed: - ----- Method: LRUCache class>>test (in category 'testing') ----- - test - " - LRUCache test - " - | c | - c := LRUCache - size: 5 - factory: [:key | key * 2]. - c at: 1. - c at: 2. - c at: 3. - c at: 4. - c at: 1. - c at: 5. - c at: 6. - c at: 7. - c at: 8. - c at: 1. - ^ c! Item was removed: - ----- Method: LRUCache class>>test2 (in category 'testing') ----- - test2 - " - LRUCache test2. - Time millisecondsToRun:[LRUCache test2]. - MessageTally spyOn:[LRUCache test2]. - " - | c | - c := LRUCache - size: 600 - factory: [:key | key * 2]. - 1 - to: 6000 - do: [:each | c at: each]. - ^ c! Item was removed: - ----- Method: LRUCache>>at: (in category 'accessing') ----- - at: aKey - "answer the object for aKey, if not present in the cache creates it" - | element keyHash | - calls := calls + 1. - keyHash := aKey hash. - 1 - to: size - do: [:index | - element := values at: index. - (keyHash - = (element at: 2) - and: [aKey - = (element at: 1)]) - ifTrue: ["Found!!" - hits := hits + 1. - values - replaceFrom: 2 - to: index - with: (values first: index - 1). - values at: 1 put: element. - ^ element at: 3]]. - "Not found!!" - element := {aKey. keyHash. factory value: aKey}. - values - replaceFrom: 2 - to: size - with: values allButLast. - values at: 1 put: element. - ^ element at: 3! Item was removed: - ----- Method: LRUCache>>initializeSize:factory: (in category 'initialization') ----- - initializeSize: aNumber factory: aBlock - "initialize the receiver's size and factory" - size := aNumber. - values := Array new: aNumber withAll: {nil. nil. nil}. - factory := aBlock. - calls := 0. - hits := 0! Item was removed: - ----- Method: LRUCache>>printOn: (in category 'printing') ----- - printOn: aStream - "Append to the argument, aStream, a sequence of characters - that identifies the receiver." - aStream nextPutAll: self class name; - nextPutAll: ' size:'; - nextPutAll: size asString; - nextPutAll: ', calls:'; - nextPutAll: calls asString; - nextPutAll: ', hits:'; - nextPutAll: hits asString; - nextPutAll: ', ratio:'; - nextPutAll: ((hits isNumber and: [calls isNumber and: [calls ~= 0]]) - ifTrue: [hits / calls] - ifFalse: [0]) asFloat asString! |
Free forum by Nabble | Edit this page |