Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
c646743d
Kaydet (Commit)
c646743d
authored
Nis 24, 2011
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Remove unused branch in the clear() method. Minor comment edits.
üst
536999c6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
18 deletions
+15
-18
collections.py
Lib/collections.py
+15
-18
No files found.
Lib/collections.py
Dosyayı görüntüle @
c646743d
...
@@ -27,9 +27,9 @@ class OrderedDict(dict):
...
@@ -27,9 +27,9 @@ class OrderedDict(dict):
# An inherited dict maps keys to values.
# An inherited dict maps keys to values.
# The inherited dict provides __getitem__, __len__, __contains__, and get.
# The inherited dict provides __getitem__, __len__, __contains__, and get.
# The remaining methods are order-aware.
# 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 regular dictionaries.
# The internal self.__map dict
ionary
maps keys to links in a doubly linked list.
# The internal self.__map dict maps keys to links in a doubly linked list.
# The circular doubly linked list starts and ends with a sentinel element.
# The circular doubly linked list starts and ends with a sentinel element.
# The sentinel element never gets deleted (this simplifies the algorithm).
# The sentinel element never gets deleted (this simplifies the algorithm).
# Each link is stored as a list of length three: [PREV, NEXT, KEY].
# Each link is stored as a list of length three: [PREV, NEXT, KEY].
...
@@ -52,8 +52,8 @@ class OrderedDict(dict):
...
@@ -52,8 +52,8 @@ class OrderedDict(dict):
def
__setitem__
(
self
,
key
,
value
,
PREV
=
0
,
NEXT
=
1
,
dict_setitem
=
dict
.
__setitem__
):
def
__setitem__
(
self
,
key
,
value
,
PREV
=
0
,
NEXT
=
1
,
dict_setitem
=
dict
.
__setitem__
):
'od.__setitem__(i, y) <==> od[i]=y'
'od.__setitem__(i, y) <==> od[i]=y'
# Setting a new item creates a new link
which goes at the end of the linked
# Setting a new item creates a new link
at the end of the linked list,
#
list,
and the inherited dictionary is updated with the new key/value pair.
# and the inherited dictionary is updated with the new key/value pair.
if
key
not
in
self
:
if
key
not
in
self
:
root
=
self
.
__root
root
=
self
.
__root
last
=
root
[
PREV
]
last
=
root
[
PREV
]
...
@@ -62,8 +62,8 @@ class OrderedDict(dict):
...
@@ -62,8 +62,8 @@ class OrderedDict(dict):
def
__delitem__
(
self
,
key
,
PREV
=
0
,
NEXT
=
1
,
dict_delitem
=
dict
.
__delitem__
):
def
__delitem__
(
self
,
key
,
PREV
=
0
,
NEXT
=
1
,
dict_delitem
=
dict
.
__delitem__
):
'od.__delitem__(y) <==> del od[y]'
'od.__delitem__(y) <==> del od[y]'
# Deleting an existing item uses self.__map to find the link which
i
s
# Deleting an existing item uses self.__map to find the link which
get
s
#
then
removed by updating the links in the predecessor and successor nodes.
# removed by updating the links in the predecessor and successor nodes.
dict_delitem
(
self
,
key
)
dict_delitem
(
self
,
key
)
link_prev
,
link_next
,
key
=
self
.
__map
.
pop
(
key
)
link_prev
,
link_next
,
key
=
self
.
__map
.
pop
(
key
)
link_prev
[
NEXT
]
=
link_next
link_prev
[
NEXT
]
=
link_next
...
@@ -89,14 +89,11 @@ class OrderedDict(dict):
...
@@ -89,14 +89,11 @@ class OrderedDict(dict):
def
clear
(
self
):
def
clear
(
self
):
'od.clear() -> None. Remove all items from od.'
'od.clear() -> None. Remove all items from od.'
try
:
for
node
in
self
.
__map
.
itervalues
():
for
node
in
self
.
__map
.
itervalues
():
del
node
[:]
del
node
[:]
root
=
self
.
__root
root
=
self
.
__root
root
[:]
=
[
root
,
root
,
None
]
root
[:]
=
[
root
,
root
,
None
]
self
.
__map
.
clear
()
self
.
__map
.
clear
()
except
AttributeError
:
pass
dict
.
clear
(
self
)
dict
.
clear
(
self
)
# -- the following methods do not depend on the internal structure --
# -- the following methods do not depend on the internal structure --
...
@@ -129,7 +126,7 @@ class OrderedDict(dict):
...
@@ -129,7 +126,7 @@ class OrderedDict(dict):
update
=
MutableMapping
.
update
update
=
MutableMapping
.
update
__update
=
update
# let subclasses override update without breaking __init__
__update
=
update
# let subclasses override update without breaking __init__
__marker
=
object
()
__marker
=
object
()
...
@@ -193,10 +190,10 @@ class OrderedDict(dict):
...
@@ -193,10 +190,10 @@ class OrderedDict(dict):
and values equal to v (which defaults to None).
and values equal to v (which defaults to None).
'''
'''
d
=
cls
()
self
=
cls
()
for
key
in
iterable
:
for
key
in
iterable
:
d
[
key
]
=
value
self
[
key
]
=
value
return
d
return
self
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
'''od.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive
'''od.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive
...
...
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