remove method
Removes value; returns false (and changes nothing) if it was absent.
Audited: 2026-06-12 11:26 EDT
Implementation
bool remove(T value) {
final List<_SkipNode<T>?> update = List<_SkipNode<T>?>.filled(_maxLevel, null);
final _SkipNode<T>? candidate = _findPredecessors(value, update);
if (candidate == null || _compare(candidate.value, value) != 0) {
return false;
}
// Unlink at every level the node participates in; stop at the first level
// where the node is no longer the immediate successor (it was never linked
// above its own height).
for (int i = 0; i <= _level; i++) {
final _SkipNode<T>? pred = update[i];
if (pred == null || pred.forward[i] != candidate) break;
pred.forward[i] = candidate.forward[i];
}
// Shrink the active level past now-empty top levels.
while (_level > 0 && _head.forward[_level] == null) {
_level--;
}
_length--;
return true;
}