Ticket #12632: sorted-dict.diff

File sorted-dict.diff, 638 bytes (added by Alex Gaynor, 15 years ago)

After benchmarking this is demonstrated to be the most efficient approach, for both large and small N.

  • django/utils/datastructures.py

    diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
    index d6fc9dc..845d082 100644
    a b class SortedDict(dict):  
    7777            self.keyOrder = data.keys()
    7878        else:
    7979            self.keyOrder = []
     80            seen = set()
    8081            for key, value in data:
    81                 if key not in self.keyOrder:
     82                if key not in seen:
    8283                    self.keyOrder.append(key)
     84                    seen.add(key)
    8385
    8486    def __deepcopy__(self, memo):
    8587        return self.__class__([(key, deepcopy(value, memo))
Back to Top