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

package nova.monadic_sfx.util
class MutHistory[T](initValue: T) {
private var _values = Vector(initValue)
def values = _values
private var _sp = 0
def sp = _sp
// def current = if (ints.isEmpty) None else Some(ints(sp))
def current = _values(_sp)
def push(v: T) = {
if (_sp < _values.length - 1) {
_values = _values.splitAt(_sp)._1
_values = _values :+ v
} else {
_values = _values :+ v
_sp = _values.length - 1
}
}
def forward() = {
if (!_values.isEmpty && _sp < _values.length - 1) _sp += 1
}
def backward() = {
if (_sp > 0) {
_sp -= 1
}
}
}