Skip to content

Instantly share code, notes, and snippets.

@zzzfree
Created March 7, 2013 07:27
Show Gist options
  • Save zzzfree/5106203 to your computer and use it in GitHub Desktop.
Save zzzfree/5106203 to your computer and use it in GitHub Desktop.
MapQueue
class MapQueue {
def max=0
def last=0
def c = [:]
def q = []
def MapQueue(m){
max=m
}
def put(k,v){
if(c.size()<max){
q << k
}
else{
c.remove(q[last])
q[last] = k
last++
if(last>max-1){
last=0
}
}
c.put(k, v)
println c
}
def get(k){
return c.get(k)
}
static main(args) {
def m = new MapQueue(3)
6.times{
m.put(it, it)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment