156 class baseset(abstractsmartset): |
156 class baseset(abstractsmartset): |
157 """Basic data structure that represents a revset and contains the basic |
157 """Basic data structure that represents a revset and contains the basic |
158 operation that it should be able to perform. |
158 operation that it should be able to perform. |
159 |
159 |
160 Every method in this class should be implemented by any smartset class. |
160 Every method in this class should be implemented by any smartset class. |
|
161 |
|
162 This class could be constructed by an (unordered) set, or an (ordered) |
|
163 list-like object. If a set is provided, it'll be sorted lazily. |
|
164 |
|
165 >>> x = [4, 0, 7, 6] |
|
166 >>> y = [5, 6, 7, 3] |
|
167 |
|
168 Construct by a set: |
|
169 >>> xs = baseset(set(x)) |
|
170 >>> ys = baseset(set(y)) |
|
171 >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]] |
|
172 [[0, 4, 6, 7, 3, 5], [6, 7], [0, 4]] |
|
173 >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]] |
|
174 ['addset', 'filteredset', 'filteredset'] |
|
175 |
|
176 Construct by a list-like: |
|
177 >>> xs = baseset(x) |
|
178 >>> ys = baseset(i for i in y) |
|
179 >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]] |
|
180 [[4, 0, 7, 6, 5, 3], [7, 6], [4, 0]] |
|
181 >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]] |
|
182 ['addset', 'filteredset', 'filteredset'] |
|
183 |
|
184 Populate "_set" fields in the lists so set optimization may be used: |
|
185 >>> [1 in xs, 3 in ys] |
|
186 [False, True] |
|
187 |
|
188 Without sort(), results won't be changed: |
|
189 >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]] |
|
190 [[4, 0, 7, 6, 5, 3], [7, 6], [4, 0]] |
|
191 >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]] |
|
192 ['addset', 'filteredset', 'filteredset'] |
|
193 |
|
194 With sort(): |
|
195 >>> xs.sort(reverse=True) |
|
196 >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]] |
|
197 [[7, 6, 4, 0, 5, 3], [7, 6], [4, 0]] |
|
198 >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]] |
|
199 ['addset', 'filteredset', 'filteredset'] |
|
200 |
|
201 >>> ys.sort() |
|
202 >>> [list(i) for i in [xs + ys, xs & ys, xs - ys]] |
|
203 [[7, 6, 4, 0, 3, 5], [7, 6], [4, 0]] |
|
204 >>> [type(i).__name__ for i in [xs + ys, xs & ys, xs - ys]] |
|
205 ['addset', 'filteredset', 'filteredset'] |
161 """ |
206 """ |
162 def __init__(self, data=(), datarepr=None, istopo=False): |
207 def __init__(self, data=(), datarepr=None, istopo=False): |
163 """ |
208 """ |
164 datarepr: a tuple of (format, obj, ...), a function or an object that |
209 datarepr: a tuple of (format, obj, ...), a function or an object that |
165 provides a printable representation of the given data. |
210 provides a printable representation of the given data. |