blob: 6d2c032066632229c76011ba9e105b3ecb6db31c [file] [log] [blame]
Guido van Rossumd6cf3af2002-08-19 16:19:15 +00001"""Classes to represent arbitrary sets (including sets of sets).
2
3This module implements sets using dictionaries whose values are
4ignored. The usual operations (union, intersection, deletion, etc.)
5are provided as both methods and operators.
6
Guido van Rossum290f1872002-08-20 20:05:23 +00007Important: sets are not sequences! While they support 'x in s',
8'len(s)', and 'for x in s', none of those operations are unique for
9sequences; for example, mappings support all three as well. The
10characteristic operation for sequences is subscripting with small
11integers: s[i], for i in range(len(s)). Sets don't support
12subscripting at all. Also, sequences allow multiple occurrences and
13their elements have a definite order; sets on the other hand don't
14record multiple occurrences and don't remember the order of element
15insertion (which is why they don't support s[i]).
16
Guido van Rossumd6cf3af2002-08-19 16:19:15 +000017The following classes are provided:
18
19BaseSet -- All the operations common to both mutable and immutable
20 sets. This is an abstract class, not meant to be directly
21 instantiated.
22
23Set -- Mutable sets, subclass of BaseSet; not hashable.
24
25ImmutableSet -- Immutable sets, subclass of BaseSet; hashable.
26 An iterable argument is mandatory to create an ImmutableSet.
27
28_TemporarilyImmutableSet -- Not a subclass of BaseSet: just a wrapper
29 around a Set, hashable, giving the same hash value as the
30 immutable set equivalent would have. Do not use this class
31 directly.
32
33Only hashable objects can be added to a Set. In particular, you cannot
34really add a Set as an element to another Set; if you try, what is
Raymond Hettingerede3a0d2002-08-20 23:34:01 +000035actually added is an ImmutableSet built from it (it compares equal to
Guido van Rossumd6cf3af2002-08-19 16:19:15 +000036the one you tried adding).
37
38When you ask if `x in y' where x is a Set and y is a Set or
39ImmutableSet, x is wrapped into a _TemporarilyImmutableSet z, and
40what's tested is actually `z in y'.
41
42"""
43
44# Code history:
45#
46# - Greg V. Wilson wrote the first version, using a different approach
47# to the mutable/immutable problem, and inheriting from dict.
48#
49# - Alex Martelli modified Greg's version to implement the current
50# Set/ImmutableSet approach, and make the data an attribute.
51#
52# - Guido van Rossum rewrote much of the code, made some API changes,
53# and cleaned up the docstrings.
Guido van Rossum26588222002-08-21 02:44:04 +000054#
Guido van Rossum9f872932002-08-21 03:20:44 +000055# - Raymond Hettinger added a number of speedups and other
Guido van Rossumdc61cdf2002-08-22 17:23:33 +000056# improvements.
Guido van Rossumd6cf3af2002-08-19 16:19:15 +000057
58
59__all__ = ['BaseSet', 'Set', 'ImmutableSet']
60
61
62class BaseSet(object):
63 """Common base class for mutable and immutable sets."""
64
65 __slots__ = ['_data']
66
67 # Constructor
68
Guido van Rossum5033b362002-08-20 21:38:37 +000069 def __init__(self):
70 """This is an abstract class."""
71 # Don't call this from a concrete subclass!
72 if self.__class__ is BaseSet:
Guido van Rossum9f872932002-08-21 03:20:44 +000073 raise TypeError, ("BaseSet is an abstract class. "
74 "Use Set or ImmutableSet.")
Guido van Rossumd6cf3af2002-08-19 16:19:15 +000075
76 # Standard protocols: __len__, __repr__, __str__, __iter__
77
78 def __len__(self):
79 """Return the number of elements of a set."""
80 return len(self._data)
81
82 def __repr__(self):
83 """Return string representation of a set.
84
85 This looks like 'Set([<list of elements>])'.
86 """
87 return self._repr()
88
89 # __str__ is the same as __repr__
90 __str__ = __repr__
91
92 def _repr(self, sorted=False):
93 elements = self._data.keys()
94 if sorted:
95 elements.sort()
96 return '%s(%r)' % (self.__class__.__name__, elements)
97
98 def __iter__(self):
99 """Return an iterator over the elements or a set.
100
101 This is the keys iterator for the underlying dict.
102 """
103 return self._data.iterkeys()
104
Guido van Rossum50e92232003-01-14 16:45:04 +0000105 # Three-way comparison is not supported
106
107 def __cmp__(self, other):
108 raise TypeError, "can't compare sets using cmp()"
109
Raymond Hettingere87ab3f2002-08-24 07:33:06 +0000110 # Equality comparisons using the underlying dicts
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000111
112 def __eq__(self, other):
113 self._binary_sanity_check(other)
114 return self._data == other._data
115
116 def __ne__(self, other):
117 self._binary_sanity_check(other)
118 return self._data != other._data
119
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000120 # Copying operations
121
122 def copy(self):
123 """Return a shallow copy of a set."""
Raymond Hettingerfa1480f2002-08-24 02:35:48 +0000124 result = self.__class__()
Raymond Hettingerd9c91512002-08-21 13:20:51 +0000125 result._data.update(self._data)
126 return result
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000127
128 __copy__ = copy # For the copy module
129
130 def __deepcopy__(self, memo):
131 """Return a deep copy of a set; used by copy module."""
132 # This pre-creates the result and inserts it in the memo
133 # early, in case the deep copy recurses into another reference
134 # to this same set. A set can't be an element of itself, but
135 # it can certainly contain an object that has a reference to
136 # itself.
137 from copy import deepcopy
Raymond Hettingerfa1480f2002-08-24 02:35:48 +0000138 result = self.__class__()
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000139 memo[id(self)] = result
140 data = result._data
141 value = True
142 for elt in self:
143 data[deepcopy(elt, memo)] = value
144 return result
145
Guido van Rossumdc61cdf2002-08-22 17:23:33 +0000146 # Standard set operations: union, intersection, both differences.
147 # Each has an operator version (e.g. __or__, invoked with |) and a
148 # method version (e.g. union).
Tim Peters4924db12002-08-25 17:10:17 +0000149 # Subtle: Each pair requires distinct code so that the outcome is
150 # correct when the type of other isn't suitable. For example, if
151 # we did "union = __or__" instead, then Set().union(3) would return
152 # NotImplemented instead of raising TypeError (albeit that *why* it
153 # raises TypeError as-is is also a bit subtle).
Guido van Rossumdc61cdf2002-08-22 17:23:33 +0000154
155 def __or__(self, other):
156 """Return the union of two sets as a new set.
157
158 (I.e. all elements that are in either set.)
159 """
160 if not isinstance(other, BaseSet):
161 return NotImplemented
Tim Peters37faed22002-08-25 19:21:27 +0000162 result = self.__class__()
163 result._data = self._data.copy()
Guido van Rossumdc61cdf2002-08-22 17:23:33 +0000164 result._data.update(other._data)
165 return result
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000166
167 def union(self, other):
168 """Return the union of two sets as a new set.
169
170 (I.e. all elements that are in either set.)
171 """
Guido van Rossumdc61cdf2002-08-22 17:23:33 +0000172 return self | other
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000173
Guido van Rossumdc61cdf2002-08-22 17:23:33 +0000174 def __and__(self, other):
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000175 """Return the intersection of two sets as a new set.
176
177 (I.e. all elements that are in both sets.)
178 """
Guido van Rossumdc61cdf2002-08-22 17:23:33 +0000179 if not isinstance(other, BaseSet):
180 return NotImplemented
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000181 if len(self) <= len(other):
182 little, big = self, other
183 else:
184 little, big = other, self
Raymond Hettingerbfcdb872002-10-04 20:01:48 +0000185 common = filter(big._data.has_key, little._data)
Tim Petersd33e6be2002-08-25 19:12:45 +0000186 return self.__class__(common)
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000187
Guido van Rossumdc61cdf2002-08-22 17:23:33 +0000188 def intersection(self, other):
189 """Return the intersection of two sets as a new set.
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000190
Guido van Rossumdc61cdf2002-08-22 17:23:33 +0000191 (I.e. all elements that are in both sets.)
192 """
193 return self & other
194
195 def __xor__(self, other):
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000196 """Return the symmetric difference of two sets as a new set.
197
198 (I.e. all elements that are in exactly one of the sets.)
199 """
Guido van Rossumdc61cdf2002-08-22 17:23:33 +0000200 if not isinstance(other, BaseSet):
201 return NotImplemented
Raymond Hettingerfa1480f2002-08-24 02:35:48 +0000202 result = self.__class__()
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000203 data = result._data
204 value = True
Tim Peters334b4a52002-08-25 19:47:54 +0000205 selfdata = self._data
206 otherdata = other._data
207 for elt in selfdata:
208 if elt not in otherdata:
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000209 data[elt] = value
Tim Peters334b4a52002-08-25 19:47:54 +0000210 for elt in otherdata:
211 if elt not in selfdata:
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000212 data[elt] = value
213 return result
214
Guido van Rossumdc61cdf2002-08-22 17:23:33 +0000215 def symmetric_difference(self, other):
216 """Return the symmetric difference of two sets as a new set.
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000217
Guido van Rossumdc61cdf2002-08-22 17:23:33 +0000218 (I.e. all elements that are in exactly one of the sets.)
219 """
220 return self ^ other
221
222 def __sub__(self, other):
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000223 """Return the difference of two sets as a new Set.
224
225 (I.e. all elements that are in this set and not in the other.)
226 """
Guido van Rossumdc61cdf2002-08-22 17:23:33 +0000227 if not isinstance(other, BaseSet):
228 return NotImplemented
Raymond Hettingerfa1480f2002-08-24 02:35:48 +0000229 result = self.__class__()
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000230 data = result._data
Tim Petersb8940392002-08-25 19:50:43 +0000231 otherdata = other._data
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000232 value = True
233 for elt in self:
Tim Petersb8940392002-08-25 19:50:43 +0000234 if elt not in otherdata:
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000235 data[elt] = value
236 return result
237
Guido van Rossumdc61cdf2002-08-22 17:23:33 +0000238 def difference(self, other):
239 """Return the difference of two sets as a new Set.
240
241 (I.e. all elements that are in this set and not in the other.)
242 """
243 return self - other
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000244
245 # Membership test
246
247 def __contains__(self, element):
248 """Report whether an element is a member of a set.
249
250 (Called in response to the expression `element in self'.)
251 """
252 try:
Raymond Hettingerde6d6972002-08-21 01:35:29 +0000253 return element in self._data
254 except TypeError:
Guido van Rossum9f872932002-08-21 03:20:44 +0000255 transform = getattr(element, "_as_temporarily_immutable", None)
Raymond Hettingerde6d6972002-08-21 01:35:29 +0000256 if transform is None:
257 raise # re-raise the TypeError exception we caught
258 return transform() in self._data
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000259
260 # Subset and superset test
261
262 def issubset(self, other):
263 """Report whether another set contains this set."""
264 self._binary_sanity_check(other)
Raymond Hettinger43db0d62002-08-21 02:22:08 +0000265 if len(self) > len(other): # Fast check for obvious cases
266 return False
Tim Peterscd06eeb2002-08-25 20:12:19 +0000267 otherdata = other._data
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000268 for elt in self:
Tim Peterscd06eeb2002-08-25 20:12:19 +0000269 if elt not in otherdata:
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000270 return False
271 return True
272
273 def issuperset(self, other):
274 """Report whether this set contains another set."""
275 self._binary_sanity_check(other)
Raymond Hettinger43db0d62002-08-21 02:22:08 +0000276 if len(self) < len(other): # Fast check for obvious cases
277 return False
Tim Peterscd06eeb2002-08-25 20:12:19 +0000278 selfdata = self._data
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000279 for elt in other:
Tim Peterscd06eeb2002-08-25 20:12:19 +0000280 if elt not in selfdata:
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000281 return False
282 return True
283
Tim Petersea76c982002-08-25 18:43:10 +0000284 # Inequality comparisons using the is-subset relation.
285 __le__ = issubset
286 __ge__ = issuperset
287
288 def __lt__(self, other):
289 self._binary_sanity_check(other)
290 return len(self) < len(other) and self.issubset(other)
291
292 def __gt__(self, other):
293 self._binary_sanity_check(other)
294 return len(self) > len(other) and self.issuperset(other)
295
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000296 # Assorted helpers
297
298 def _binary_sanity_check(self, other):
299 # Check that the other argument to a binary operation is also
300 # a set, raising a TypeError otherwise.
301 if not isinstance(other, BaseSet):
302 raise TypeError, "Binary operation only permitted between sets"
303
304 def _compute_hash(self):
305 # Calculate hash code for a set by xor'ing the hash codes of
Tim Petersd06d0302002-08-23 20:06:42 +0000306 # the elements. This ensures that the hash code does not depend
307 # on the order in which elements are added to the set. This is
308 # not called __hash__ because a BaseSet should not be hashable;
309 # only an ImmutableSet is hashable.
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000310 result = 0
311 for elt in self:
312 result ^= hash(elt)
313 return result
314
Guido van Rossum9f872932002-08-21 03:20:44 +0000315 def _update(self, iterable):
316 # The main loop for update() and the subclass __init__() methods.
Guido van Rossum9f872932002-08-21 03:20:44 +0000317 data = self._data
Raymond Hettinger1a8d1932002-08-29 15:13:50 +0000318
319 # Use the fast update() method when a dictionary is available.
320 if isinstance(iterable, BaseSet):
321 data.update(iterable._data)
322 return
Raymond Hettinger1a8d1932002-08-29 15:13:50 +0000323
Tim Peters0ec1ddc2002-11-08 05:26:52 +0000324 value = True
Guido van Rossum7cd83ca2002-11-08 17:03:36 +0000325
326 if type(iterable) in (list, tuple, xrange):
327 # Optimized: we know that __iter__() and next() can't
328 # raise TypeError, so we can move 'try:' out of the loop.
329 it = iter(iterable)
330 while True:
331 try:
332 for element in it:
333 data[element] = value
334 return
335 except TypeError:
336 transform = getattr(element, "_as_immutable", None)
337 if transform is None:
338 raise # re-raise the TypeError exception we caught
339 data[transform()] = value
340 else:
341 # Safe: only catch TypeError where intended
342 for element in iterable:
343 try:
Raymond Hettinger80d21af2002-08-21 04:12:03 +0000344 data[element] = value
Guido van Rossum7cd83ca2002-11-08 17:03:36 +0000345 except TypeError:
346 transform = getattr(element, "_as_immutable", None)
347 if transform is None:
348 raise # re-raise the TypeError exception we caught
349 data[transform()] = value
Guido van Rossum9f872932002-08-21 03:20:44 +0000350
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000351
352class ImmutableSet(BaseSet):
353 """Immutable set class."""
354
Guido van Rossum0b650d72002-08-19 16:29:58 +0000355 __slots__ = ['_hashcode']
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000356
357 # BaseSet + hashing
358
Guido van Rossum9f872932002-08-21 03:20:44 +0000359 def __init__(self, iterable=None):
360 """Construct an immutable set from an optional iterable."""
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000361 self._hashcode = None
Guido van Rossum9f872932002-08-21 03:20:44 +0000362 self._data = {}
363 if iterable is not None:
364 self._update(iterable)
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000365
366 def __hash__(self):
367 if self._hashcode is None:
368 self._hashcode = self._compute_hash()
369 return self._hashcode
370
Jeremy Hyltoncd58b8f2002-11-13 19:34:26 +0000371 def __getstate__(self):
372 return self._data, self._hashcode
373
374 def __setstate__(self, state):
375 self._data, self._hashcode = state
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000376
377class Set(BaseSet):
378 """ Mutable set class."""
379
380 __slots__ = []
381
382 # BaseSet + operations requiring mutability; no hashing
383
Guido van Rossum9f872932002-08-21 03:20:44 +0000384 def __init__(self, iterable=None):
385 """Construct a set from an optional iterable."""
386 self._data = {}
387 if iterable is not None:
388 self._update(iterable)
389
Jeremy Hyltoncd58b8f2002-11-13 19:34:26 +0000390 def __getstate__(self):
391 # getstate's results are ignored if it is not
392 return self._data,
393
394 def __setstate__(self, data):
395 self._data, = data
396
Guido van Rossum9f872932002-08-21 03:20:44 +0000397 def __hash__(self):
398 """A Set cannot be hashed."""
399 # We inherit object.__hash__, so we must deny this explicitly
400 raise TypeError, "Can't hash a Set, only an ImmutableSet."
Guido van Rossum5033b362002-08-20 21:38:37 +0000401
Tim Peters4a2f91e2002-08-25 18:59:04 +0000402 # In-place union, intersection, differences.
403 # Subtle: The xyz_update() functions deliberately return None,
404 # as do all mutating operations on built-in container types.
405 # The __xyz__ spellings have to return self, though.
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000406
Raymond Hettinger1b9f5d42002-08-24 06:19:02 +0000407 def __ior__(self, other):
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000408 """Update a set with the union of itself and another."""
409 self._binary_sanity_check(other)
410 self._data.update(other._data)
411 return self
412
Raymond Hettinger1b9f5d42002-08-24 06:19:02 +0000413 def union_update(self, other):
414 """Update a set with the union of itself and another."""
415 self |= other
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000416
Raymond Hettinger1b9f5d42002-08-24 06:19:02 +0000417 def __iand__(self, other):
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000418 """Update a set with the intersection of itself and another."""
419 self._binary_sanity_check(other)
Tim Peters454602f2002-08-26 00:44:07 +0000420 self._data = (self & other)._data
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000421 return self
422
Raymond Hettinger1b9f5d42002-08-24 06:19:02 +0000423 def intersection_update(self, other):
424 """Update a set with the intersection of itself and another."""
425 self &= other
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000426
Raymond Hettinger1b9f5d42002-08-24 06:19:02 +0000427 def __ixor__(self, other):
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000428 """Update a set with the symmetric difference of itself and another."""
429 self._binary_sanity_check(other)
430 data = self._data
431 value = True
432 for elt in other:
433 if elt in data:
434 del data[elt]
435 else:
436 data[elt] = value
437 return self
438
Raymond Hettinger1b9f5d42002-08-24 06:19:02 +0000439 def symmetric_difference_update(self, other):
440 """Update a set with the symmetric difference of itself and another."""
441 self ^= other
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000442
Raymond Hettinger1b9f5d42002-08-24 06:19:02 +0000443 def __isub__(self, other):
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000444 """Remove all elements of another set from this set."""
445 self._binary_sanity_check(other)
446 data = self._data
447 for elt in other:
448 if elt in data:
449 del data[elt]
450 return self
451
Raymond Hettinger1b9f5d42002-08-24 06:19:02 +0000452 def difference_update(self, other):
453 """Remove all elements of another set from this set."""
454 self -= other
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000455
456 # Python dict-like mass mutations: update, clear
457
458 def update(self, iterable):
459 """Add all values from an iterable (such as a list or file)."""
Guido van Rossum9f872932002-08-21 03:20:44 +0000460 self._update(iterable)
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000461
462 def clear(self):
463 """Remove all elements from this set."""
464 self._data.clear()
465
466 # Single-element mutations: add, remove, discard
467
468 def add(self, element):
469 """Add an element to a set.
470
471 This has no effect if the element is already present.
472 """
473 try:
Raymond Hettingerde6d6972002-08-21 01:35:29 +0000474 self._data[element] = True
475 except TypeError:
Guido van Rossum9f872932002-08-21 03:20:44 +0000476 transform = getattr(element, "_as_immutable", None)
Raymond Hettingerde6d6972002-08-21 01:35:29 +0000477 if transform is None:
478 raise # re-raise the TypeError exception we caught
479 self._data[transform()] = True
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000480
481 def remove(self, element):
482 """Remove an element from a set; it must be a member.
483
484 If the element is not a member, raise a KeyError.
485 """
486 try:
Raymond Hettingerde6d6972002-08-21 01:35:29 +0000487 del self._data[element]
488 except TypeError:
Guido van Rossum9f872932002-08-21 03:20:44 +0000489 transform = getattr(element, "_as_temporarily_immutable", None)
Raymond Hettingerde6d6972002-08-21 01:35:29 +0000490 if transform is None:
491 raise # re-raise the TypeError exception we caught
492 del self._data[transform()]
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000493
494 def discard(self, element):
495 """Remove an element from a set if it is a member.
496
497 If the element is not a member, do nothing.
498 """
499 try:
Guido van Rossume399d082002-08-23 14:45:02 +0000500 self.remove(element)
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000501 except KeyError:
502 pass
503
Guido van Rossumc9196bc2002-08-20 21:51:59 +0000504 def pop(self):
Tim Peters53506be2002-08-23 20:36:58 +0000505 """Remove and return an arbitrary set element."""
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000506 return self._data.popitem()[0]
507
508 def _as_immutable(self):
509 # Return a copy of self as an immutable set
510 return ImmutableSet(self)
511
512 def _as_temporarily_immutable(self):
513 # Return self wrapped in a temporarily immutable set
514 return _TemporarilyImmutableSet(self)
515
516
Raymond Hettingerfa1480f2002-08-24 02:35:48 +0000517class _TemporarilyImmutableSet(BaseSet):
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000518 # Wrap a mutable set as if it was temporarily immutable.
519 # This only supplies hashing and equality comparisons.
520
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000521 def __init__(self, set):
522 self._set = set
Raymond Hettingerfa1480f2002-08-24 02:35:48 +0000523 self._data = set._data # Needed by ImmutableSet.__eq__()
Guido van Rossumd6cf3af2002-08-19 16:19:15 +0000524
525 def __hash__(self):
Raymond Hettingerd5018512002-08-24 04:47:42 +0000526 return self._set._compute_hash()