GSoC-2011 project:: Containers
KennyTM~
kennytm at gmail.com
Wed Mar 30 11:28:49 PDT 2011
On Mar 30, 11 23:01, Steven Schveighoffer wrote:
> And yes, you can, if you have a pointer to the element right before the
> insertion/removal point.
That what I've said in the previous post. The point is linearRemove's
interface does not take that pointer.
/// Removes a range from the list in linear time.
Range linearRemove(Range r);
Perhaps SList could provide an O(1) .removeAfter method, like:
/// Remove elements in the range [r.front+1 .. $)
Range removeAfter(Range r) {
// add checking yourself.
r._head._next = null;
return Range(null);
}
or an O(1) .removeOneAfter which may be more useful than chopping the
whole tail:
/// Remove one element in at r.front+1
/// and return the range [r.front+2 .. $)
Range removeOneAfter(Range r) {
// add checking yourself.
r._head._next = r._head._next._next;
r.popFront();
return r;
}
More information about the Digitalmars-d
mailing list