/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: Marius Kruger
  • Date: 2010-07-10 21:28:56 UTC
  • mto: (5384.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5385.
  • Revision ID: marius.kruger@enerweb.co.za-20100710212856-uq4ji3go0u5se7hx
* Update documentation
* add NEWS

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