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
e5fdedbe
Kaydet (Commit)
e5fdedbe
authored
Ara 10, 2009
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add a reverse() method to collections.deque().
üst
3e761a98
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
0 deletions
+63
-0
collections.rst
Doc/library/collections.rst
+5
-0
test_deque.py
Lib/test/test_deque.py
+12
-0
NEWS
Misc/NEWS
+2
-0
_collectionsmodule.c
Modules/_collectionsmodule.c
+44
-0
No files found.
Doc/library/collections.rst
Dosyayı görüntüle @
e5fdedbe
...
...
@@ -357,6 +357,11 @@ counts, but the output will exclude results with counts of zero or less.
Removed the first occurrence of *value*. If not found, raises a
:exc:`ValueError`.
.. method:: reverse()
Reverse the elements of the deque in-place and then return ``None``.
.. versionadded:: 3.2
.. method:: rotate(n)
...
...
Lib/test/test_deque.py
Dosyayı görüntüle @
e5fdedbe
...
...
@@ -193,6 +193,18 @@ class TestBasic(unittest.TestCase):
self
.
assertTrue
(
val
not
in
d
)
self
.
assertEqual
(
len
(
d
),
0
)
def
test_reverse
(
self
):
n
=
500
# O(n**2) test, don't make this too big
data
=
[
random
.
random
()
for
i
in
range
(
n
)]
for
i
in
range
(
n
):
d
=
deque
(
data
[:
i
])
r
=
d
.
reverse
()
self
.
assertEqual
(
list
(
d
),
list
(
reversed
(
data
[:
i
])))
self
.
assert_
(
r
is
None
)
d
.
reverse
()
self
.
assertEqual
(
list
(
d
),
data
[:
i
])
self
.
assertRaises
(
TypeError
,
d
.
reverse
,
1
)
# Arity is zero
def
test_rotate
(
self
):
s
=
tuple
(
'abcde'
)
n
=
len
(
s
)
...
...
Misc/NEWS
Dosyayı görüntüle @
e5fdedbe
...
...
@@ -154,6 +154,8 @@ C-API
Library
-------
- Add a reverse() method to collections.deque().
- Issue #6986: Fix crash in the JSON C accelerator when called with the
wrong parameter types. Patch by Victor Stinner.
...
...
Modules/_collectionsmodule.c
Dosyayı görüntüle @
e5fdedbe
...
...
@@ -427,6 +427,48 @@ deque_rotate(dequeobject *deque, PyObject *args)
PyDoc_STRVAR
(
rotate_doc
,
"Rotate the deque n steps to the right (default n=1). If n is negative, rotates left."
);
static
PyObject
*
deque_reverse
(
dequeobject
*
deque
,
PyObject
*
unused
)
{
block
*
leftblock
=
deque
->
leftblock
;
block
*
rightblock
=
deque
->
rightblock
;
Py_ssize_t
leftindex
=
deque
->
leftindex
;
Py_ssize_t
rightindex
=
deque
->
rightindex
;
Py_ssize_t
n
=
(
deque
->
len
)
/
2
;
Py_ssize_t
i
;
PyObject
*
tmp
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
/* Validate that pointers haven't met in the middle */
assert
(
leftblock
!=
rightblock
||
leftindex
<
rightindex
);
/* Swap */
tmp
=
leftblock
->
data
[
leftindex
];
leftblock
->
data
[
leftindex
]
=
rightblock
->
data
[
rightindex
];
rightblock
->
data
[
rightindex
]
=
tmp
;
/* Advance left block/index pair */
leftindex
++
;
if
(
leftindex
==
BLOCKLEN
)
{
assert
(
leftblock
->
rightlink
!=
NULL
);
leftblock
=
leftblock
->
rightlink
;
leftindex
=
0
;
}
/* Step backwards with the right block/index pair */
rightindex
--
;
if
(
rightindex
==
-
1
)
{
assert
(
rightblock
->
leftlink
!=
NULL
);
rightblock
=
rightblock
->
leftlink
;
rightindex
=
BLOCKLEN
-
1
;
}
}
Py_RETURN_NONE
;
}
PyDoc_STRVAR
(
reverse_doc
,
"D.reverse() -- reverse *IN PLACE*"
);
static
Py_ssize_t
deque_len
(
dequeobject
*
deque
)
{
...
...
@@ -865,6 +907,8 @@ static PyMethodDef deque_methods[] = {
METH_O
,
remove_doc
},
{
"__reversed__"
,
(
PyCFunction
)
deque_reviter
,
METH_NOARGS
,
reversed_doc
},
{
"reverse"
,
(
PyCFunction
)
deque_reverse
,
METH_NOARGS
,
reverse_doc
},
{
"rotate"
,
(
PyCFunction
)
deque_rotate
,
METH_VARARGS
,
rotate_doc
},
{
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