Where _sortedkeys is a sortedset and _map is a dict. In the case where key is already in the sorteddict and you are merely changing its value, an operation that could be performed in constant time takes O(log n) time. Code like
if key in self._map:
self._sortedkeys.add(key)
self._map[key] = value
should improve the asymptotic performance in this case.
sorteddict.__setitem__
works byWhere
_sortedkeys
is asortedset
and_map
is adict
. In the case where key is already in the sorteddict and you are merely changing its value, an operation that could be performed in constant time takes O(log n) time. Code likeshould improve the asymptotic performance in this case.