'@return: self'

def update(self, otherdict):

    assert self._assert_invariants()
    if (len(otherdict) > self._maxsize):
        dict.clear(self)
        self._lru = []
        if (self._maxsize > (len(otherdict) - self._maxsize)):
            dict.update(self, otherdict)
            while (len(self) > self._maxsize):
                dict.popitem(self)
        else:
            for (k, v) in otherdict.iteritems():
                if (len(self) == self._maxsize):
                    break
                dict.__setitem__(self, k, v)
        self._lru = dict.keys(self)
        assert self._assert_invariants()
        return self
    for k in otherdict.iterkeys():
        if dict.has_key(self, k):
            self._lru.remove(k)
    self._lru.extend(otherdict.keys())
    dict.update(self, otherdict)
    over = (len(self) - self._maxsize)
    if (over > 0):
        map(dict.__delitem__, ([self] * over), self._lru[:over])
        del self._lru[:over]
    assert self._assert_invariants()
    return self
