|
@@ -22,8 +22,8 @@ These utilities can all be deleted when dulwich decides it wants to stop
|
|
|
support for python <2.7.
|
|
|
"""
|
|
|
|
|
|
-# Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 and pypy.
|
|
|
-# Passes Python2.7's test suite and incorporates all the latest updates.
|
|
|
+# Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 and
|
|
|
+# pypy. Passes Python2.7's test suite and incorporates all the latest updates.
|
|
|
# Copyright (C) Raymond Hettinger, MIT license
|
|
|
|
|
|
try:
|
|
@@ -41,12 +41,14 @@ class OrderedDict(dict):
|
|
|
# An inherited dict maps keys to values.
|
|
|
# The inherited dict provides __getitem__, __len__, __contains__, and get.
|
|
|
# The remaining methods are order-aware.
|
|
|
- # Big-O running times for all methods are the same as for regular dictionaries.
|
|
|
+ # Big-O running times for all methods are the same as for regular
|
|
|
+ # dictionaries.
|
|
|
|
|
|
- # The internal self.__map dictionary maps keys to links in a doubly linked list.
|
|
|
- # The circular doubly linked list starts and ends with a sentinel element.
|
|
|
- # The sentinel element never gets deleted (this simplifies the algorithm).
|
|
|
- # Each link is stored as a list of length three: [PREV, NEXT, KEY].
|
|
|
+ # The internal self.__map dictionary maps keys to links in a doubly linked
|
|
|
+ # list. The circular doubly linked list starts and ends with a sentinel
|
|
|
+ # element. The sentinel element never gets deleted (this simplifies the
|
|
|
+ # algorithm). Each link is stored as a list of length three: [PREV, NEXT,
|
|
|
+ # KEY].
|
|
|
|
|
|
def __init__(self, *args, **kwds):
|
|
|
'''Initialize an ordered dictionary. Signature is the same as for
|
|
@@ -66,8 +68,9 @@ class OrderedDict(dict):
|
|
|
|
|
|
def __setitem__(self, key, value, dict_setitem=dict.__setitem__):
|
|
|
'od.__setitem__(i, y) <==> od[i]=y'
|
|
|
- # Setting a new item creates a new link which goes at the end of the linked
|
|
|
- # list, and the inherited dictionary is updated with the new key/value pair.
|
|
|
+ # Setting a new item creates a new link which goes at the end of the
|
|
|
+ # linked list, and the inherited dictionary is updated with the new
|
|
|
+ # key/value pair.
|
|
|
if key not in self:
|
|
|
root = self.__root
|
|
|
last = root[0]
|
|
@@ -77,7 +80,8 @@ class OrderedDict(dict):
|
|
|
def __delitem__(self, key, dict_delitem=dict.__delitem__):
|
|
|
'od.__delitem__(y) <==> del od[y]'
|
|
|
# Deleting an existing item uses self.__map to find the link which is
|
|
|
- # then removed by updating the links in the predecessor and successor nodes.
|
|
|
+ # then removed by updating the links in the predecessor and successor
|
|
|
+ # nodes.
|
|
|
dict_delitem(self, key)
|
|
|
link_prev, link_next, key = self.__map.pop(key)
|
|
|
link_prev[1] = link_next
|
|
@@ -192,7 +196,8 @@ class OrderedDict(dict):
|
|
|
for key, value in kwds.items():
|
|
|
self[key] = value
|
|
|
|
|
|
- __update = update # let subclasses override update without breaking __init__
|
|
|
+ __update = update # let subclasses override update without breaking
|
|
|
+ # __init__
|
|
|
|
|
|
__marker = object()
|
|
|
|