baseset: explicitly track order of the baseset

A baseset starts without an explicit order. But as soon as a sort is requested,
we simply register that the baseset has an order and use the ordered version of
the list to behave accordingly.

We will want to properly record the order at creation time in the future. This
would unlock more optimisation and avoid some sorting.
This commit is contained in:
Pierre-Yves David 2014-10-03 03:29:55 -05:00
parent cf7077b249
commit eb55591aca

View File

@ -2372,10 +2372,13 @@ class baseset(abstractsmartset):
return bool(self._list)
def sort(self, reverse=False):
self._list.sort(reverse=reverse)
self._ascending = not bool(reverse)
def reverse(self):
self._list.reverse()
if self._ascending is None:
self._list.reverse()
else:
self._ascending = not self._ascending
def __len__(self):
return len(self._list)
@ -2421,12 +2424,22 @@ class baseset(abstractsmartset):
def first(self):
if self:
return self._list[0]
if self._ascending is None:
return self._list[0]
elif self._ascending:
return self._asclist[0]
else:
return self._asclist[-1]
return None
def last(self):
if self:
return self._list[-1]
if self._ascending is None:
return self._list[-1]
elif self._ascending:
return self._asclist[-1]
else:
return self._asclist[0]
return None
class filteredset(abstractsmartset):