Comments
Patch
@@ -2320,31 +2320,48 @@ class baseset(abstractsmartset):
True (or False) the baseset will assume the data are ascending (or
descending, respectively) and be optimised accordingly.
BEWARE that the value provided in `isasc` MUST match the order of the data
otherwise, buggy behavior will be upon you!
+
+ If the provided data are a set, we clearly do not care about ordering in
+ the data. So the set is directly reused and the baseset will be considered
+ ascending.
"""
def __init__(self, data=(), isasc=None):
- if not isinstance(data, list):
- data = list(data)
- self._list = data
- if isasc is not None:
- isasc = bool(isasc)
- if not isasc:
- data = data[::-1]
- self._asclist = data
- self._ascending = isasc
+ if isinstance(data, set):
+ self._set = data
+ assert isasc is None
+ self._ascending = True
+ else:
+ if not isinstance(data, list):
+ data = list(data)
+ self._list = data
+ if isasc is not None:
+ isasc = bool(isasc)
+ if not isasc:
+ data = data[::-1]
+ self._asclist = data
+ self._ascending = isasc
+
+ # we have cyclic dependency here so the __init__ MUST set one of theses.
@util.propertycache
def _set(self):
return set(self._list)
@util.propertycache
+ def _list(self):
+ return self._asclist
+
+ @util.propertycache
def _asclist(self):
- asclist = self._list[:]
- asclist.sort()
- return asclist
+ if '_list' in vars(self):
+ data = self._list
+ else:
+ data = self._set
+ return sorted(data)
def __iter__(self):
if self._ascending is None:
return iter(self._list)
elif self._ascending: