示例#1
0
 def __init__(self, seq=None):
     if isinstance(seq, btuple):
         self._blist = seq._blist
     elif seq is not None:
         self._blist = blist(seq)
     else:
         self._blist = blist()
     self._hash = -1
示例#2
0
 def __mul__(self, k):
     if not isinstance(k, int):
         raise TypeError("can't multiply sequence by non-int of type '%s'"
                         % str(type(int)))
     rv = self.__class__()
     rv._key = self._key
     rv._blist = sum((blist([x])*k for x in self._blist), blist())
     return rv
示例#3
0
 def __init__(self, seq=None):
     if isinstance(seq, btuple):
         self._blist = seq._blist
     elif seq is not None:
         self._blist = blist(seq)
     else:
         self._blist = blist()
     self._hash = -1
示例#4
0
 def __init__(self, iterable=(), key=None):
     self._key = key
     if key is not None and not hasattr(key, '__call__'):
         raise TypeError("'%s' object is not callable" % str(type(key)))
     if ((isinstance(iterable,type(self))
          or isinstance(self,type(iterable)))
         and iterable._key is key):
         self._blist = blist(iterable._blist)
     else:
         self._blist = blist()
         for v in iterable:
             self.add(v)
示例#5
0
 def _btuple_or_tuple(self, other, f):
     if isinstance(other, btuple):
         rv = f(self._blist, other._blist)
     elif isinstance(other, tuple):
         rv = f(self._blist, blist(other))
     else:
         return NotImplemented
     if isinstance(rv, blist):
         rv = btuple(rv)
     return rv        
示例#6
0
 def _btuple_or_tuple(self, other, f):
     if isinstance(other, btuple):
         rv = f(self._blist, other._blist)
     elif isinstance(other, tuple):
         rv = f(self._blist, blist(other))
     else:
         return NotImplemented
     if isinstance(rv, blist):
         rv = btuple(rv)
     return rv
示例#7
0
def spinlock(steps, insertions):
    # 'blist' improves the performance of list insertion
    lst = blist([0])

    value = 1
    pos = 0
    for _ in xrange(insertions):
        pos = (pos + steps) % len(lst)
        pos += 1
        lst.insert(pos, value)
        value += 1

    return lst, pos
示例#8
0
 def values(self):
     return blist(self[key] for key in self)
示例#9
0
 def items(self):
     return blist((key, self[key]) for key in self)
示例#10
0
 def items(self):
     return blist((key, self[key]) for key in self)
示例#11
0
 def values(self):
     return blist(self[key] for key in self)