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
ba6ab84e
Kaydet (Commit)
ba6ab84e
authored
Ara 12, 2000
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add popitem() -- SF patch #102733.
üst
968c36d8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
dictobject.c
Objects/dictobject.c
+53
-0
No files found.
Objects/dictobject.c
Dosyayı görüntüle @
ba6ab84e
...
@@ -1132,6 +1132,58 @@ dict_clear(register dictobject *mp, PyObject *args)
...
@@ -1132,6 +1132,58 @@ dict_clear(register dictobject *mp, PyObject *args)
return
Py_None
;
return
Py_None
;
}
}
static
PyObject
*
dict_popitem
(
dictobject
*
mp
,
PyObject
*
args
)
{
int
i
=
0
;
dictentry
*
ep
;
PyObject
*
res
;
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
if
(
mp
->
ma_used
==
0
)
{
PyErr_SetString
(
PyExc_KeyError
,
"popitem(): dictionary is empty"
);
return
NULL
;
}
/* Set ep to "the first" dict entry with a value. We abuse the hash
* field of slot 0 to hold a search finger:
* If slot 0 has a value, use slot 0.
* Else slot 0 is being used to hold a search finger,
* and we use its hash value as the first index to look.
*/
ep
=
&
mp
->
ma_table
[
0
];
if
(
ep
->
me_value
==
NULL
)
{
i
=
(
int
)
ep
->
me_hash
;
/* The hash field may be uninitialized trash, or it
* may be a real hash value, or it may be a legit
* search finger, or it may be a once-legit search
* finger that's out of bounds now because it
* wrapped around or the table shrunk -- simply
* make sure it's in bounds now.
*/
if
(
i
>=
mp
->
ma_size
||
i
<
1
)
i
=
1
;
/* skip slot 0 */
while
((
ep
=
&
mp
->
ma_table
[
i
])
->
me_value
==
NULL
)
{
i
++
;
if
(
i
>=
mp
->
ma_size
)
i
=
1
;
}
}
res
=
PyTuple_New
(
2
);
if
(
res
!=
NULL
)
{
PyTuple_SET_ITEM
(
res
,
0
,
ep
->
me_key
);
PyTuple_SET_ITEM
(
res
,
1
,
ep
->
me_value
);
Py_INCREF
(
dummy
);
ep
->
me_key
=
dummy
;
ep
->
me_value
=
NULL
;
mp
->
ma_used
--
;
assert
(
mp
->
ma_table
[
0
].
me_value
==
NULL
);
mp
->
ma_table
[
0
].
me_hash
=
i
+
1
;
/* next place to start */
}
return
res
;
}
static
int
static
int
dict_traverse
(
PyObject
*
op
,
visitproc
visit
,
void
*
arg
)
dict_traverse
(
PyObject
*
op
,
visitproc
visit
,
void
*
arg
)
{
{
...
@@ -1167,6 +1219,7 @@ static PyMethodDef mapp_methods[] = {
...
@@ -1167,6 +1219,7 @@ static PyMethodDef mapp_methods[] = {
{
"copy"
,
(
PyCFunction
)
dict_copy
},
{
"copy"
,
(
PyCFunction
)
dict_copy
},
{
"get"
,
(
PyCFunction
)
dict_get
,
METH_VARARGS
},
{
"get"
,
(
PyCFunction
)
dict_get
,
METH_VARARGS
},
{
"setdefault"
,
(
PyCFunction
)
dict_setdefault
,
METH_VARARGS
},
{
"setdefault"
,
(
PyCFunction
)
dict_setdefault
,
METH_VARARGS
},
{
"popitem"
,
(
PyCFunction
)
dict_popitem
},
{
NULL
,
NULL
}
/* sentinel */
{
NULL
,
NULL
}
/* sentinel */
};
};
...
...
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