/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 breezy/intset.py

  • Committer: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

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
74
76
        if values is not None:
75
77
            self.update(values)
76
78
 
77
 
 
78
 
    def __nonzero__(self):
 
79
    def __bool__(self):
79
80
        """IntSets are false if empty, otherwise True.
80
81
 
81
82
        >>> bool(IntSet())
86
87
        """
87
88
        return bool(self._val)
88
89
 
 
90
    __nonzero__ = __bool__
89
91
 
90
92
    def __len__(self):
91
93
        """Number of elements in set.
101
103
            v = v >> 1
102
104
        return c
103
105
 
104
 
 
105
106
    def __and__(self, other):
106
107
        """Set intersection.
107
108
 
119
120
            raise NotImplementedError(type(other))
120
121
        return IntSet(bitmask=(self._val & other._val))
121
122
 
122
 
 
123
123
    def __or__(self, other):
124
124
        """Set union.
125
125
 
131
131
            raise NotImplementedError(type(other))
132
132
        return IntSet(bitmask=(self._val | other._val))
133
133
 
134
 
 
135
134
    def __eq__(self, other):
136
135
        """Comparison.
137
136
 
143
142
        else:
144
143
            return False
145
144
 
146
 
 
147
145
    def __ne__(self, other):
148
146
        return not self.__eq__(other)
149
147
 
150
 
 
151
148
    def __contains__(self, i):
152
 
        return self._val & (1L << i)
153
 
 
 
149
        return self._val & (1 << i)
154
150
 
155
151
    def __iter__(self):
156
152
        """Return contents of set.
169
165
            v = v >> 1
170
166
            o = o + 1
171
167
 
172
 
 
173
168
    def update(self, to_add):
174
169
        """Add all the values from the sequence or intset to_add"""
175
170
        if isinstance(to_add, IntSet):
176
171
            self._val |= to_add._val
177
172
        else:
178
173
            for i in to_add:
179
 
                self._val |= (1L << i)
180
 
 
 
174
                self._val |= (1 << i)
181
175
 
182
176
    def add(self, to_add):
183
 
        self._val |= (1L << to_add)
184
 
 
 
177
        self._val |= (1 << to_add)
185
178
 
186
179
    def remove(self, to_remove):
187
180
        """Remove one value from the set.
200
193
        >>> not a
201
194
        True
202
195
        """
203
 
        m = 1L << to_remove
 
196
        m = 1 << to_remove
204
197
        if not self._val & m:
205
198
            raise KeyError(to_remove)
206
199
        self._val ^= m
222
215
            return
223
216
        intersect = self._val & to_remove._val
224
217
        self._val ^= intersect
225