(self)
Allocates the bit range depending on the required bit count
Allocates the bit range depending on the required bit count
Allocates the bit range depending on the required bit count
def __allocateBits(self):
        """Allocates the bit range depending on the required bit count
        """
        if self._bit_count < 0:
            raise Exception("A margin cannot request negative number of bits")
        if self._bit_count == 0:
            return

        # Build a list of occupied ranges
        margins = [self._editor._line_number_margin]

        occupiedRanges = []
        for margin in margins:
            bitRange = margin.getBitRange()
            if bitRange is not None:
                # pick the right position
                added = False
                for index, r in enumerate(occupiedRanges):
                    r = occupiedRanges[index]
                    if bitRange[1] < r[0]:
                        occupiedRanges.insert(index, bitRange)
                        added = True
                        break
                if not added:
                    occupiedRanges.append(bitRange)

        vacant = 0
        for r in occupiedRanges:
            if r[0] - vacant >= self._bit_count:
                self._bitRange = (vacant, vacant + self._bit_count - 1)
                return
            vacant = r[1] + 1
        # Not allocated, i.e. grab the tail bits
        self._bitRange = (vacant, vacant + self._bit_count - 1)
def __allocateBits ( self ) : if self . _bit_count < 0 : raise Exception ( "A margin cannot request negative number of bits" ) if self . _bit_count == 0 : return # Build a list of occupied ranges margins = [ self . _editor . _line_number_margin ] occupiedRanges = [ ] for margin in margins : bitRange = margin . getBitRange ( ) if bitRange is not None : # pick the right position added = False for index , r in enumerate ( occupiedRanges ) : r = occupiedRanges [ index ] if bitRange [ 1 ] < r [ 0 ] : occupiedRanges . insert ( index , bitRange ) added = True break if not added : occupiedRanges . append ( bitRange ) vacant = 0 for r in occupiedRanges : if r [ 0 ] - vacant >= self . _bit_count : self . _bitRange = ( vacant , vacant + self . _bit_count - 1 ) return vacant = r [ 1 ] + 1 # Not allocated, i.e. grab the tail bits self . _bitRange = ( vacant , vacant + self . _bit_count - 1 )