/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/intset.py

  • Committer: Jelmer Vernooij
  • Date: 2017-02-06 00:15:01 UTC
  • mto: (6621.2.2 py3)
  • mto: This revision was merged to the branch mainline in revision 6624.
  • Revision ID: jelmer@jelmer.uk-20170206001501-e44n1mbowv58ohx8
Keep __nonzero__ around for Python2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
# Author: Martin Pool <mbp@canonical.com>
18
20
 
19
21
 
64
66
    """
65
67
    __slots__ = ['_val']
66
68
 
67
 
    def __init__(self, values=None, bitmask=0L):
 
69
    def __init__(self, values=None, bitmask=0):
68
70
        """Create a new intset.
69
71
 
70
72
        values
75
77
            self.update(values)
76
78
 
77
79
 
78
 
    def __nonzero__(self):
 
80
    def __bool__(self):
79
81
        """IntSets are false if empty, otherwise True.
80
82
 
81
83
        >>> bool(IntSet())
86
88
        """
87
89
        return bool(self._val)
88
90
 
 
91
    __nonzero__ = __bool__
 
92
 
89
93
 
90
94
    def __len__(self):
91
95
        """Number of elements in set.
149
153
 
150
154
 
151
155
    def __contains__(self, i):
152
 
        return self._val & (1L << i)
 
156
        return self._val & (1 << i)
153
157
 
154
158
 
155
159
    def __iter__(self):
176
180
            self._val |= to_add._val
177
181
        else:
178
182
            for i in to_add:
179
 
                self._val |= (1L << i)
 
183
                self._val |= (1 << i)
180
184
 
181
185
 
182
186
    def add(self, to_add):
183
 
        self._val |= (1L << to_add)
 
187
        self._val |= (1 << to_add)
184
188
 
185
189
 
186
190
    def remove(self, to_remove):
200
204
        >>> not a
201
205
        True
202
206
        """
203
 
        m = 1L << to_remove
 
207
        m = 1 << to_remove
204
208
        if not self._val & m:
205
209
            raise KeyError(to_remove)
206
210
        self._val ^= m