Exemplo n.º 1
0
    def __setitem__(self, item, val):
        if len(self) > self._max * 2:
            print("Purging")
            to_delete = self.most_common()[self._max:]
            for ii in to_delete:
                del self[ii]

        Counter.__setitem__(self, item, val)
Exemplo n.º 2
0
 def __setitem__(self, key, value):
     if value < 0:
         raise ValueError("negative count forbidden")
     elif value == 0:
         if key in self:
             del self[key]
     else:
         Counter.__setitem__(self, key, value)
Exemplo n.º 3
0
    def __setitem__(self, k, v):
        if k in self:
            assert self[k] == v
            return
        if self._worst is not None:  # the beam is full
            if v <= self._worst[1]:
                return
            else:
                del self[self._worst[0]]

        Counter.__setitem__(self, k, v)
        assert self._size >= len(self)
        if self._size == len(self):
            self._worst = min(self.items(), key=lambda (k1, v1): v1)
Exemplo n.º 4
0
 def __setitem__(self, k, v):
     if k in self:
         assert self[k]==v
         return
     if self._worst is not None: # the beam is full
         if v<=self._worst[1]:
             return
         else:
             del self[self._worst[0]]
             
     Counter.__setitem__(self, k, v)
     assert self._size>=len(self)
     if self._size==len(self):
         self._worst = min(self.items(), key=lambda (k1,v1): v1)
Exemplo n.º 5
0
 def __setitem__(x, i, y):
     """x.__setitem__(i, y) <==> x[i]=y"""
     if y == 0:
         del x[i]
     else:
         Counter.__setitem__(x, i, y)
 def __setitem__(self, key, value):
     Counter.__setitem__(self, key, value)
     self.__changed.add(key)
Exemplo n.º 7
0
 def __setitem__(self, *args, **kwargs):
     if self.__finishedinit:
         raise AttributeError("Can't change a frozen counter!")
     Counter.__setitem__(self, *args, **kwargs)
Exemplo n.º 8
0
 def __setitem__(x, i, y):
     """x.__setitem__(i, y) <==> x[i]=y"""
     if y == 0:
         del x[i]
     else:
         Counter.__setitem__(x, i, y)