
Untitled
By: a guest on
Aug 19th, 2012 | syntax:
None | size: 0.59 KB | hits: 6 | expires: Never
//Type Definition
trait IntQueue {
def get(): Int
def put(x: Int)
def size(): Int
}
//ArrayBuffer implementation
class IntQueueImpl extends IntQueue {
private[this] val buf = new collection.mutable.ArrayBuffer[Int]
def get = buf remove 0
def put(x: Int) { buf += x }
def size = buf.length
}
trait Doubling extends IntQueue {
abstract override def put(x: Int) { super.put(2 * x) }
}
trait Incrementing extends IntQueue {
abstract override def put(x: Int) { super.put(x + 1) }
}
trait Filtering extends IntQueue {
abstract override def put(x: Int) { if (x > 0) super.put(x) }
}