You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
627 B

  1. package nova.monadic_sfx.util
  2. class MutHistory[T](initValue: T) {
  3. private var _values = Vector(initValue)
  4. def values = _values
  5. private var _sp = 0
  6. def sp = _sp
  7. // def current = if (ints.isEmpty) None else Some(ints(sp))
  8. def current = _values(_sp)
  9. def push(v: T) = {
  10. if (_sp < _values.length - 1) {
  11. _values = _values.splitAt(_sp)._1
  12. _values = _values :+ v
  13. } else {
  14. _values = _values :+ v
  15. _sp = _values.length - 1
  16. }
  17. }
  18. def forward() = {
  19. if (!_values.isEmpty && _sp < _values.length - 1) _sp += 1
  20. }
  21. def backward() = {
  22. if (_sp > 0) {
  23. _sp -= 1
  24. }
  25. }
  26. }