예제 #1
0
 def _resize(self, tosize):
     curlength = len(self.bits)
     newlength = bytes_for_bits(tosize)
     if newlength > curlength:
         self.bits.extend((0,) * (newlength - curlength))
     elif newlength < curlength:
         del self.bits[newlength + 1:]
예제 #2
0
 def _resize(self, tosize):
     curlength = len(self.bits)
     newlength = bytes_for_bits(tosize)
     if newlength > curlength:
         self.bits.extend((0, ) * (newlength - curlength))
     elif newlength < curlength:
         del self.bits[newlength + 1:]
예제 #3
0
    def __init__(self, source=None, size=0):
        """
        :param maxsize: the maximum size of the bit array.
        :param source: an iterable of positive integers to add to this set.
        :param bits: an array of unsigned bytes ("B") to use as the underlying
            bit array. This is used by some of the object's methods.
        """

        # If the source is a list, tuple, or set, we can guess the size
        if not size and isinstance(source, (list, tuple, set, frozenset)):
            size = max(source)
        bytecount = bytes_for_bits(size)
        self.bits = array("B", (0 for _ in xrange(bytecount)))

        if source:
            add = self.add
            for num in source:
                add(num)
예제 #4
0
    def __init__(self, source=None, size=0):
        """
        :param maxsize: the maximum size of the bit array.
        :param source: an iterable of positive integers to add to this set.
        :param bits: an array of unsigned bytes ("B") to use as the underlying
            bit array. This is used by some of the object's methods.
        """

        # If the source is a list, tuple, or set, we can guess the size
        if not size and isinstance(source, (list, tuple, set, frozenset)):
            size = max(source)
        bytecount = bytes_for_bits(size)
        self.bits = array("B", (0 for _ in range(bytecount)))

        if source:
            add = self.add
            for num in source:
                add(num)