Maximum Length for scala queue

后端 未结 4 1488
死守一世寂寞
死守一世寂寞 2020-12-09 04:55

I\'m curious if Scala has some gem hidden in its collection classes that I can use. Basically I\'m looking for something like a FIFO queue, but that has an upper-limit on i

4条回答
  •  不思量自难忘°
    2020-12-09 04:59

    Why don't you just subclass a FIFO queue? Something like this should work: (pseudocode follows...)

    class Limited(limit:Int) extends FIFO {
      override def enqueue() = {
        if (size >= limit) {
          //remove oldest element
        }
        super.enqueue()
      }
    }
    

提交回复
热议问题