Skip to content

Instantly share code, notes, and snippets.

@Aidanie
Created August 1, 2013 04:31
Show Gist options
  • Save Aidanie/6128420 to your computer and use it in GitHub Desktop.
Save Aidanie/6128420 to your computer and use it in GitHub Desktop.
Simple Circular Buffer
/**
* Simple Scala Circular Buffer.
*
* @author Aidan Church (aidanchurch@gmail.com)
* @url http://www.achurch.me
*
*/
class circularBuffer(size:Int){
val maxSize = size;
val buffer = new ArrayBuffer[String]
def +=(item : String){
if(buffer.size == size)
buffer.trimStart(1)
buffer.append(item)
}
def remove(n:Int) = {buffer.trimStart(n)}
def print(){
for(string <- buffer){
println(string)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment