Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
dd2fedcd
Commit
dd2fedcd
authored
Apr 03, 2010
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor-out constant expressions
parent
6b96ecb0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
14 deletions
+6
-14
Lib/collections.py
Lib/collections.py
+6
-14
No files found.
Lib/collections.py
View file @
dd2fedcd
...
...
@@ -47,47 +47,39 @@ class OrderedDict(dict, MutableMapping):
self
.
__map
=
{}
self
.
update
(
*
args
,
**
kwds
)
def
__setitem__
(
self
,
key
,
value
):
def
__setitem__
(
self
,
key
,
value
,
PREV
=
0
,
NEXT
=
1
,
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.
if
key
not
in
self
:
PREV
=
0
NEXT
=
1
root
=
self
.
__root
last
=
root
[
PREV
]
last
[
NEXT
]
=
root
[
PREV
]
=
self
.
__map
[
key
]
=
[
last
,
root
,
key
]
dict
.
__setitem__
(
self
,
key
,
value
)
dict
_setitem
(
self
,
key
,
value
)
def
__delitem__
(
self
,
key
):
def
__delitem__
(
self
,
key
,
PREV
=
0
,
NEXT
=
1
,
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.
dict
.
__delitem__
(
self
,
key
)
PREV
=
0
NEXT
=
1
dict_delitem
(
self
,
key
)
link
=
self
.
__map
.
pop
(
key
)
link_prev
=
link
[
PREV
]
link_next
=
link
[
NEXT
]
link_prev
[
NEXT
]
=
link_next
link_next
[
PREV
]
=
link_prev
def
__iter__
(
self
):
def
__iter__
(
self
,
NEXT
=
1
,
KEY
=
2
):
'od.__iter__() <==> iter(od)'
# Traverse the linked list in order.
NEXT
=
1
KEY
=
2
root
=
self
.
__root
curr
=
root
[
NEXT
]
while
curr
is
not
root
:
yield
curr
[
KEY
]
curr
=
curr
[
NEXT
]
def
__reversed__
(
self
):
def
__reversed__
(
self
,
PREV
=
0
,
KEY
=
2
):
'od.__reversed__() <==> reversed(od)'
# Traverse the linked list in reverse order.
PREV
=
0
KEY
=
2
root
=
self
.
__root
curr
=
root
[
PREV
]
while
curr
is
not
root
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment