Part of bzrlib.intset View In Hierarchy
Despite the name this stores long integers happily, but negative values are not allowed.
>>> a = IntSet([0, 2, 5]) >>> bool(a) True >>> 2 in a True >>> 4 in a False >>> a.add(4) >>> 4 in a True
>>> b = IntSet() >>> not b True >>> b.add(10) >>> 10 in a False >>> a.update(b) >>> 10 in a True >>> a.update(range(5)) >>> 3 in a True
Being a set, duplicates are ignored: >>> a = IntSet() >>> a.add(10) >>> a.add(10) >>> 10 in a True >>> list(a) [10]
Method | __init__ | Create a new intset. |
Method | __nonzero__ | IntSets are false if empty, otherwise True. |
Method | __len__ | Number of elements in set. |
Method | __and__ | Set intersection. |
Method | __or__ | Set union. |
Method | __eq__ | Comparison. |
Method | __ne__ | Undocumented |
Method | __contains__ | Undocumented |
Method | __iter__ | Return contents of set. |
Method | update | Add all the values from the sequence or intset to_add |
Method | add | Undocumented |
Method | remove | Remove one value from the set. |
Method | set_remove | Remove all values that exist in to_remove. |
Create a new intset.
IntSets are false if empty, otherwise True.
>>> bool(IntSet()) False
>>> bool(IntSet([0])) True
Set intersection.
>>> a = IntSet(range(10)) >>> len(a) 10 >>> b = a & a >>> b == a True >>> a = a & IntSet([5, 7, 11, 13]) >>> list(a) [5, 7]
Return contents of set.
>>> list(IntSet()) [] >>> list(IntSet([0, 1, 5, 7])) [0, 1, 5, 7]
Remove one value from the set.
Raises KeyError if the value is not present.
>>> a = IntSet([10]) >>> a.remove(9) Traceback (most recent call last): File "/usr/lib/python2.4/doctest.py", line 1243, in __run compileflags, 1) in test.globs File "<doctest __main__.IntSet.remove[1]>", line 1, in ? a.remove(9) KeyError: 9 >>> a.remove(10) >>> not a True