Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. import scala.collection._
  2. import mutable.ListBuffer
  3.  
  4. class FixedList[A](max: Int) extends Traversable[A] {
  5.  
  6. val list: ListBuffer[A] = ListBuffer()
  7.  
  8. def append(elem: A) {
  9. if (list.size == max) {
  10. list.trimStart(1)
  11. }
  12. list.append(elem)
  13. }
  14.  
  15. def foreach[U](f: A => U) = list.foreach(f)
  16.  
  17. }
  18.  
  19. def size = writeIndex - readIndex + (if (readIndex > writeIndex) array.size else 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement