当前位置: 首页>>代码示例>>Python>>正文


Python operator.__lshift__方法代码示例

本文整理汇总了Python中operator.__lshift__方法的典型用法代码示例。如果您正苦于以下问题:Python operator.__lshift__方法的具体用法?Python operator.__lshift__怎么用?Python operator.__lshift__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在operator的用法示例。


在下文中一共展示了operator.__lshift__方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __lshift__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import __lshift__ [as 别名]
def __lshift__( self, n ):                                     
        '''
        Left circular rotation of a BitVector through N positions can be
        carried out by
 
            bitvec  << N 

        This operator overloading is made possible by implementing the
        __lshift__ method defined here.  Note that this operator returns
        the bitvector on which it is invoked.  This allows for a chained
        invocation of the operator

        '''
        if self.size == 0:                                         
            raise ValueError('''Circular shift of an empty vector
                                makes no sense''')                 
        if n < 0:                                                  
            return self >> abs(n)                                  
        for i in range(n):                                         
            self.circular_rotate_left_by_one()                     
        return self 
开发者ID:francozappa,项目名称:knob,代码行数:23,代码来源:BitVector.py

示例2: shift_right_by_one

# 需要导入模块: import operator [as 别名]
# 或者: from operator import __lshift__ [as 别名]
def shift_right_by_one(self):                                    
        '''
        For a one-bit in-place right non-circular shift.  Note that bitvector size
        does not change.  The rightmost bit that moves past the last element of the
        bitvector is discarded and leftmost bit of the returned vector is set to
        zero.
        '''
        size = len(self.vector)                                      
        right_most_bits = list(map( operator.__and__, self.vector, [0x8000]*size ))         
        self.vector = list(map( operator.__and__, self.vector, [~0x8000]*size )) 
        right_most_bits.insert(0, 0)                                 
        right_most_bits.pop()                                        
        self.vector = list(map(operator.__lshift__, self.vector, [1]*size))    
        self.vector = list(map( operator.__or__, self.vector, \
                                   list(map(operator.__rshift__,right_most_bits, [15]*size))))
        self._setbit(0, 0) 
开发者ID:francozappa,项目名称:knob,代码行数:18,代码来源:BitVector.py

示例3: circular_rotate_left_by_one

# 需要导入模块: import operator [as 别名]
# 或者: from operator import __lshift__ [as 别名]
def circular_rotate_left_by_one(self):                         
        'For a one-bit in-place left circular shift'
        size = len(self.vector)                                    
        bitstring_leftmost_bit = self.vector[0] & 1                
        left_most_bits = list(map(operator.__and__, self.vector, [1]*size)) 
        left_most_bits.append(left_most_bits[0])                   
        del(left_most_bits[0])                                     
        self.vector = list(map(operator.__rshift__, self.vector, [1]*size)) 
        self.vector = list(map( operator.__or__, self.vector, \
                              list( map(operator.__lshift__, left_most_bits, [15]*size) )))   
                                                                   
        self._setbit(self.size -1, bitstring_leftmost_bit) 
开发者ID:francozappa,项目名称:knob,代码行数:14,代码来源:BitVector.py

示例4: circular_rotate_right_by_one

# 需要导入模块: import operator [as 别名]
# 或者: from operator import __lshift__ [as 别名]
def circular_rotate_right_by_one(self):                        
        'For a one-bit in-place right circular shift'
        size = len(self.vector)                                    
        bitstring_rightmost_bit = self[self.size - 1]              
        right_most_bits = list(map( operator.__and__,
                               self.vector, [0x8000]*size ))       
        self.vector = list(map( operator.__and__, self.vector, [~0x8000]*size ))
        right_most_bits.insert(0, bitstring_rightmost_bit)         
        right_most_bits.pop()                                      
        self.vector = list(map(operator.__lshift__, self.vector, [1]*size))
        self.vector = list(map( operator.__or__, self.vector, \
                                list(map(operator.__rshift__, right_most_bits, [15]*size))))  
                                                                   
        self._setbit(0, bitstring_rightmost_bit) 
开发者ID:francozappa,项目名称:knob,代码行数:16,代码来源:BitVector.py

示例5: shift_left_by_one

# 需要导入模块: import operator [as 别名]
# 或者: from operator import __lshift__ [as 别名]
def shift_left_by_one(self):                                
        '''
        For a one-bit in-place left non-circular shift.  Note that bitvector size
        does not change.  The leftmost bit that moves past the first element of the
        bitvector is discarded and rightmost bit of the returned vector is set to
        zero.
        '''
        size = len(self.vector)                                 
        left_most_bits = list(map(operator.__and__, self.vector, [1]*size))  
        left_most_bits.append(left_most_bits[0])                    
        del(left_most_bits[0])                                      
        self.vector = list(map(operator.__rshift__, self.vector, [1]*size)) 
        self.vector = list(map( operator.__or__, self.vector, \
                               list(map(operator.__lshift__, left_most_bits, [15]*size))))
        self._setbit(self.size -1, 0) 
开发者ID:francozappa,项目名称:knob,代码行数:17,代码来源:BitVector.py

示例6: __lshift__

# 需要导入模块: import operator [as 别名]
# 或者: from operator import __lshift__ [as 别名]
def __lshift__( self, n ):                                     
        'For an in-place left circular shift by n bit positions'
        if self.size == 0:                                         
            raise ValueError('''Circular shift of an empty vector
                                makes no sense''')                 
        if n < 0:                                                  
            return self >> abs(n)                                  
        for i in range(n):                                         
            self.circular_rotate_left_by_one()                     
        return self 
开发者ID:INK-USC,项目名称:ClusType,代码行数:12,代码来源:BitVector.py


注:本文中的operator.__lshift__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。