WALRUCache


Seaside-Utilities

Comment:



Hierarchy:

ProtoObject
Object
WALRUCache

Summary:

instance variables:

ageTable max table

methods:

instance class
as yet unclassified as yet unclassified

Detail:

instance variables:

ageTable
InitialValue:
a Dictionary()
inferredType:
Dictionary
max
InitialValue:
20
inferredType:
SmallInteger
table
InitialValue:
a Dictionary()
inferredType:
Dictionary

instance methods:

as yet unclassified
at: key

	^ self at: key ifAbsent: [self error: 'No entry for ', key]
at: key ifAbsent: errorBlock

	|val|
	val _ table at: key ifAbsent: [^ errorBlock value].
	ageTable at: val put: 0.
	^ val.
at: key put: val

	|removals|
	table at: key put: val.
	ageTable at: val put: 0.
	removals _ OrderedCollection new.
	ageTable associationsDo:
		[:assoc |
		assoc value > max ifTrue: [removals add: assoc key].
		assoc value: assoc value + 1].
	removals do: [:ea | self remove: ea].
	
capacity: aNumber

	max _ aNumber
initialize

	max _ 20.
	table _ Dictionary new.
	ageTable _ Dictionary new.
isEmpty

	^ table isEmpty
nextKey

	|key|
	[table includesKey: (key _ WAExternalID new asString)] whileTrue.
	^ key
remove: anObject

	ageTable removeKey: anObject.
	table removeKey: (table keyAtValue: anObject)
store: anObject

	|key|
	key _ self nextKey.
	self at: key put: anObject.
	^ key

class methods:

as yet unclassified
new

	^ super new initialize
new: max

	^ self new capacity: max

^top


- made by Dandelion -