b.i.IntSet(Exception) : class documentation

Part of bzrlib.intset View In Hierarchy

Faster set-like class storing only whole numbers.

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.
def __init__(self, values=None, bitmask=0L):

Create a new intset.

values
If specified, an initial collection of values.
def __nonzero__(self):

IntSets are false if empty, otherwise True.

>>> bool(IntSet())
False
>>> bool(IntSet([0]))
True
def __len__(self):

Number of elements in set.

>>> len(IntSet(xrange(20000)))
20000
def __and__(self, other):

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]
def __or__(self, other):

Set union.

>>> a = IntSet(range(10)) | IntSet([5, 15, 25])
>>> len(a)
12
def __eq__(self, other):

Comparison.

>>> IntSet(range(3)) == IntSet([2, 0, 1])
True
def __ne__(self, other):
Undocumented
def __contains__(self, i):
Undocumented
def __iter__(self):

Return contents of set.

>>> list(IntSet())
[]
>>> list(IntSet([0, 1, 5, 7]))
[0, 1, 5, 7]
def update(self, to_add):
Add all the values from the sequence or intset to_add
def add(self, to_add):
Undocumented
def remove(self, to_remove):

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
def set_remove(self, to_remove):

Remove all values that exist in to_remove.

>>> a = IntSet(range(10))
>>> b = IntSet([2,3,4,7,12])
>>> a.set_remove(b)
>>> list(a)
[0, 1, 5, 6, 8, 9]
>>> a.set_remove([1,2,5])
>>> list(a)
[0, 6, 8, 9]
API Documentation for Bazaar, generated by pydoctor at 2020-09-30 01:08:52.