add method
Add an entry to the tree, and return the index it will occupy.
If the tree contains next elements, an new subtree will be created,
otherwise, it will be added to the head of the current subtree.
If the tree was not initialized, it will be with entry as the root.
Implementation
int add(E entry) {
final i = _length++;
// if the undo tree is empty, set the current, the head and the tail.
if (tail == null) {
_headerList.add(_current = _head = _tail = UndoHeader(entry, i));
assert(_headerList[i] == current);
return i;
}
// otherwise, set only the current and the head.
_headerList.add(_head = _current = current!.add(entry, i));
assert(_headerList[i] == current);
return i;
}