Created
June 10, 2018 22:04
-
-
Save PeteGabriel/c131ce122a167bbf5034c6116e868bbd to your computer and use it in GitHub Desktop.
Insert operation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def insert(key: UUID, value : Int) = { | |
if (this.byKey.contains(key)){ | |
throw new Exception("Key already exists") | |
} | |
val freqNode = this.frequencyHead.next | |
if (freqNode.value != 1){ | |
this.frequencyHead.next = LfuCache.getNewNode(this.frequencyHead, freqNode) | |
this.byKey(key) = LfuItem(this.frequencyHead.next, value, key) | |
this.frequencyHead.next.items += this.byKey(key) | |
}else{ | |
this.byKey(key) = LfuItem(freqNode, value, key) | |
freqNode.items += this.byKey(key) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment