Show More
@@ -2171,23 +2171,40 b' def funcsused(tree):' | |||||
2171 | class baseset(list): |
|
2171 | class baseset(list): | |
2172 | """Basic data structure that represents a revset and contains the basic |
|
2172 | """Basic data structure that represents a revset and contains the basic | |
2173 | operation that it should be able to perform. |
|
2173 | operation that it should be able to perform. | |
|
2174 | ||||
|
2175 | Every method in this class should be implemented by any smartset class. | |||
2174 | """ |
|
2176 | """ | |
2175 | def __init__(self, data): |
|
2177 | def __init__(self, data): | |
2176 | super(baseset, self).__init__(data) |
|
2178 | super(baseset, self).__init__(data) | |
2177 | self._set = None |
|
2179 | self._set = None | |
2178 |
|
2180 | |||
2179 | def ascending(self): |
|
2181 | def ascending(self): | |
|
2182 | """Sorts the set in ascending order (in place). | |||
|
2183 | ||||
|
2184 | This is part of the mandatory API for smartset.""" | |||
2180 | self.sort() |
|
2185 | self.sort() | |
2181 |
|
2186 | |||
2182 | def descending(self): |
|
2187 | def descending(self): | |
|
2188 | """Sorts the set in descending order (in place). | |||
|
2189 | ||||
|
2190 | This is part of the mandatory API for smartset.""" | |||
2183 | self.sort(reverse=True) |
|
2191 | self.sort(reverse=True) | |
2184 |
|
2192 | |||
2185 | def set(self): |
|
2193 | def set(self): | |
|
2194 | """Returns a set or a smartset containing all the elements. | |||
|
2195 | ||||
|
2196 | The returned structure should be the fastest option for membership | |||
|
2197 | testing. | |||
|
2198 | ||||
|
2199 | This is part of the mandatory API for smartset.""" | |||
2186 | if not self._set: |
|
2200 | if not self._set: | |
2187 | self._set = set(self) |
|
2201 | self._set = set(self) | |
2188 | return self._set |
|
2202 | return self._set | |
2189 |
|
2203 | |||
2190 | def __sub__(self, other): |
|
2204 | def __sub__(self, other): | |
|
2205 | """Returns a new object with the substraction of the two collections. | |||
|
2206 | ||||
|
2207 | This is part of the mandatory API for smartset.""" | |||
2191 | if isinstance(other, baseset): |
|
2208 | if isinstance(other, baseset): | |
2192 | s = other.set() |
|
2209 | s = other.set() | |
2193 | else: |
|
2210 | else: | |
@@ -2195,22 +2212,40 b' class baseset(list):' | |||||
2195 | return baseset(self.set() - s) |
|
2212 | return baseset(self.set() - s) | |
2196 |
|
2213 | |||
2197 | def __and__(self, other): |
|
2214 | def __and__(self, other): | |
|
2215 | """Returns a new object with the intersection of the two collections. | |||
2198 |
|
|
2216 | ||
|
2217 | This is part of the mandatory API for smartset.""" | |||
2199 | if isinstance(other, baseset): |
|
2218 | if isinstance(other, baseset): | |
2200 | other = other.set() |
|
2219 | other = other.set() | |
2201 | return baseset([y for y in self if y in other]) |
|
2220 | return baseset([y for y in self if y in other]) | |
|
2221 | ||||
2202 | def __add__(self, other): |
|
2222 | def __add__(self, other): | |
|
2223 | """Returns a new object with the union of the two collections. | |||
|
2224 | ||||
|
2225 | This is part of the mandatory API for smartset.""" | |||
2203 | s = self.set() |
|
2226 | s = self.set() | |
2204 | l = [r for r in other if r not in s] |
|
2227 | l = [r for r in other if r not in s] | |
2205 | return baseset(list(self) + l) |
|
2228 | return baseset(list(self) + l) | |
2206 |
|
2229 | |||
2207 | def isascending(self): |
|
2230 | def isascending(self): | |
|
2231 | """Returns True if the collection is ascending order, False if not. | |||
|
2232 | ||||
|
2233 | This is part of the mandatory API for smartset.""" | |||
2208 | return False |
|
2234 | return False | |
2209 |
|
2235 | |||
2210 | def isdescending(self): |
|
2236 | def isdescending(self): | |
|
2237 | """Returns True if the collection is descending order, False if not. | |||
|
2238 | ||||
|
2239 | This is part of the mandatory API for smartset.""" | |||
2211 | return False |
|
2240 | return False | |
2212 |
|
2241 | |||
2213 | def filter(self, condition): |
|
2242 | def filter(self, condition): | |
|
2243 | """Returns this smartset filtered by condition as a new smartset. | |||
|
2244 | ||||
|
2245 | `condition` is a callable which takes a revision number and returns a | |||
|
2246 | boolean. | |||
|
2247 | ||||
|
2248 | This is part of the mandatory API for smartset.""" | |||
2214 | return lazyset(self, condition) |
|
2249 | return lazyset(self, condition) | |
2215 |
|
2250 | |||
2216 | class lazyset(object): |
|
2251 | class lazyset(object): |
General Comments 0
You need to be logged in to leave comments.
Login now