~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/intset.py

  • Committer: Vincent Ladeuil
  • Date: 2012-02-14 17:22:37 UTC
  • mfrom: (6466 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120214172237-7dv7er3n4uy8d5m4
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
from __future__ import absolute_import
16
18
 
17
19
# Author: Martin Pool <mbp@canonical.com>
18
20
 
60
62
    True
61
63
    >>> list(a)
62
64
    [10]
63
 
    
 
65
 
64
66
    """
65
67
    __slots__ = ['_val']
66
68
 
80
82
 
81
83
        >>> bool(IntSet())
82
84
        False
83
 
        
 
85
 
84
86
        >>> bool(IntSet([0]))
85
87
        True
86
88
        """
129
131
        """
130
132
        if not isinstance(other, IntSet):
131
133
            raise NotImplementedError(type(other))
132
 
        return IntSet(bitmask=(self._val | other._val))        
 
134
        return IntSet(bitmask=(self._val | other._val))
133
135
 
134
136
 
135
137
    def __eq__(self, other):
149
151
 
150
152
 
151
153
    def __contains__(self, i):
152
 
        assert i >= 0
153
154
        return self._val & (1L << i)
154
155
 
155
156
 
170
171
            v = v >> 1
171
172
            o = o + 1
172
173
 
173
 
        
 
174
 
174
175
    def update(self, to_add):
175
176
        """Add all the values from the sequence or intset to_add"""
176
177
        if isinstance(to_add, IntSet):
177
178
            self._val |= to_add._val
178
179
        else:
179
180
            for i in to_add:
180
 
                assert i >= 0
181
181
                self._val |= (1L << i)
182
182
 
183
183
 
184
184
    def add(self, to_add):
185
 
        assert 0 <= to_add
186
185
        self._val |= (1L << to_add)
187
186
 
188
187
 
203
202
        >>> not a
204
203
        True
205
204
        """
206
 
        assert 0 <= to_remove
207
205
        m = 1L << to_remove
208
206
        if not self._val & m:
209
207
            raise KeyError(to_remove)