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
1760c8a0
Kaydet (Commit)
1760c8a0
authored
Kas 08, 2007
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add set.isdisjoint()
üst
004c1c15
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
126 additions
and
2 deletions
+126
-2
stdtypes.rst
Doc/library/stdtypes.rst
+7
-0
test_set.py
Lib/test/test_set.py
+47
-2
NEWS
Misc/NEWS
+2
-0
setobject.c
Objects/setobject.c
+70
-0
No files found.
Doc/library/stdtypes.rst
Dosyayı görüntüle @
1760c8a0
...
...
@@ -1467,6 +1467,13 @@ operations:
Test *x* for non-membership in *s*.
.. method:: set.isdisjoint(other)
Return True if the set has no elements in common with *other*.
Sets are disjoint if and only if their interesection is the empty set.
.. versionadded:: 2.6
.. method:: set.issubset(other)
set <= other
...
...
Lib/test/test_set.py
Dosyayı görüntüle @
1760c8a0
...
...
@@ -102,6 +102,20 @@ class TestJointOps(unittest.TestCase):
self
.
assertEqual
(
self
.
thetype
(
'abcba'
)
.
intersection
(
C
(
'ccb'
)),
set
(
'bc'
))
self
.
assertEqual
(
self
.
thetype
(
'abcba'
)
.
intersection
(
C
(
'ef'
)),
set
(
''
))
def
test_isdisjoint
(
self
):
def
f
(
s1
,
s2
):
'Pure python equivalent of isdisjoint()'
return
not
set
(
s1
)
.
intersection
(
s2
)
for
larg
in
''
,
'a'
,
'ab'
,
'abc'
,
'ababac'
,
'cdc'
,
'cc'
,
'efgfe'
,
'ccb'
,
'ef'
:
s1
=
self
.
thetype
(
larg
)
for
rarg
in
''
,
'a'
,
'ab'
,
'abc'
,
'ababac'
,
'cdc'
,
'cc'
,
'efgfe'
,
'ccb'
,
'ef'
:
for
C
in
set
,
frozenset
,
dict
.
fromkeys
,
str
,
unicode
,
list
,
tuple
:
s2
=
C
(
rarg
)
actual
=
s1
.
isdisjoint
(
s2
)
expected
=
f
(
s1
,
s2
)
self
.
assertEqual
(
actual
,
expected
)
self
.
assert_
(
actual
is
True
or
actual
is
False
)
def
test_and
(
self
):
i
=
self
.
s
.
intersection
(
self
.
otherword
)
self
.
assertEqual
(
self
.
s
&
set
(
self
.
otherword
),
i
)
...
...
@@ -657,6 +671,18 @@ class TestBasicOps(unittest.TestCase):
result
=
empty_set
&
self
.
set
self
.
assertEqual
(
result
,
empty_set
)
def
test_self_isdisjoint
(
self
):
result
=
self
.
set
.
isdisjoint
(
self
.
set
)
self
.
assertEqual
(
result
,
not
self
.
set
)
def
test_empty_isdisjoint
(
self
):
result
=
self
.
set
.
isdisjoint
(
empty_set
)
self
.
assertEqual
(
result
,
True
)
def
test_isdisjoint_empty
(
self
):
result
=
empty_set
.
isdisjoint
(
self
.
set
)
self
.
assertEqual
(
result
,
True
)
def
test_self_symmetric_difference
(
self
):
result
=
self
.
set
^
self
.
set
self
.
assertEqual
(
result
,
empty_set
)
...
...
@@ -835,6 +861,22 @@ class TestBinaryOps(unittest.TestCase):
result
=
self
.
set
&
set
([
8
])
self
.
assertEqual
(
result
,
empty_set
)
def
test_isdisjoint_subset
(
self
):
result
=
self
.
set
.
isdisjoint
(
set
((
2
,
4
)))
self
.
assertEqual
(
result
,
False
)
def
test_isdisjoint_superset
(
self
):
result
=
self
.
set
.
isdisjoint
(
set
([
2
,
4
,
6
,
8
]))
self
.
assertEqual
(
result
,
False
)
def
test_isdisjoint_overlap
(
self
):
result
=
self
.
set
.
isdisjoint
(
set
([
3
,
4
,
5
]))
self
.
assertEqual
(
result
,
False
)
def
test_isdisjoint_non_overlap
(
self
):
result
=
self
.
set
.
isdisjoint
(
set
([
8
]))
self
.
assertEqual
(
result
,
True
)
def
test_sym_difference_subset
(
self
):
result
=
self
.
set
^
set
((
2
,
4
))
self
.
assertEqual
(
result
,
set
([
6
]))
...
...
@@ -1456,11 +1498,14 @@ class TestVariousIteratorArgs(unittest.TestCase):
def
test_inline_methods
(
self
):
s
=
set
(
'november'
)
for
data
in
(
"123"
,
""
,
range
(
1000
),
(
'do'
,
1.2
),
xrange
(
2000
,
2200
,
5
),
'december'
):
for
meth
in
(
s
.
union
,
s
.
intersection
,
s
.
difference
,
s
.
symmetric_difference
):
for
meth
in
(
s
.
union
,
s
.
intersection
,
s
.
difference
,
s
.
symmetric_difference
,
s
.
isdisjoint
):
for
g
in
(
G
,
I
,
Ig
,
L
,
R
):
expected
=
meth
(
data
)
actual
=
meth
(
G
(
data
))
self
.
assertEqual
(
sorted
(
actual
),
sorted
(
expected
))
if
isinstance
(
expected
,
bool
):
self
.
assertEqual
(
actual
,
expected
)
else
:
self
.
assertEqual
(
sorted
(
actual
),
sorted
(
expected
))
self
.
assertRaises
(
TypeError
,
meth
,
X
(
s
))
self
.
assertRaises
(
TypeError
,
meth
,
N
(
s
))
self
.
assertRaises
(
ZeroDivisionError
,
meth
,
E
(
s
))
...
...
Misc/NEWS
Dosyayı görüntüle @
1760c8a0
...
...
@@ -12,6 +12,8 @@ What's New in Python 2.6 alpha 1?
Core and builtins
-----------------
- sets and frozensets now have an isdisjoint() method.
- optimize the performance of builtin.sum().
- Fix warnings found by the new version of the Coverity checker.
...
...
Objects/setobject.c
Dosyayı görüntüle @
1760c8a0
...
...
@@ -1332,6 +1332,72 @@ set_iand(PySetObject *so, PyObject *other)
return
(
PyObject
*
)
so
;
}
static
PyObject
*
set_isdisjoint
(
PySetObject
*
so
,
PyObject
*
other
)
{
PyObject
*
key
,
*
it
,
*
tmp
;
if
((
PyObject
*
)
so
==
other
)
{
if
(
PySet_GET_SIZE
(
so
)
==
0
)
Py_RETURN_TRUE
;
else
Py_RETURN_FALSE
;
}
if
(
PyAnySet_CheckExact
(
other
))
{
Py_ssize_t
pos
=
0
;
setentry
*
entry
;
if
(
PySet_GET_SIZE
(
other
)
>
PySet_GET_SIZE
(
so
))
{
tmp
=
(
PyObject
*
)
so
;
so
=
(
PySetObject
*
)
other
;
other
=
tmp
;
}
while
(
set_next
((
PySetObject
*
)
other
,
&
pos
,
&
entry
))
{
int
rv
=
set_contains_entry
(
so
,
entry
);
if
(
rv
==
-
1
)
return
NULL
;
if
(
rv
)
Py_RETURN_FALSE
;
}
Py_RETURN_TRUE
;
}
it
=
PyObject_GetIter
(
other
);
if
(
it
==
NULL
)
return
NULL
;
while
((
key
=
PyIter_Next
(
it
))
!=
NULL
)
{
int
rv
;
setentry
entry
;
long
hash
=
PyObject_Hash
(
key
);
Py_DECREF
(
key
);
if
(
hash
==
-
1
)
{
Py_DECREF
(
it
);
return
NULL
;
}
entry
.
hash
=
hash
;
entry
.
key
=
key
;
rv
=
set_contains_entry
(
so
,
&
entry
);
if
(
rv
==
-
1
)
{
Py_DECREF
(
it
);
return
NULL
;
}
if
(
rv
)
{
Py_DECREF
(
it
);
Py_RETURN_FALSE
;
}
}
Py_DECREF
(
it
);
if
(
PyErr_Occurred
())
return
NULL
;
Py_RETURN_TRUE
;
}
PyDoc_STRVAR
(
isdisjoint_doc
,
"Return True if two sets have a null intersection."
);
static
int
set_difference_update_internal
(
PySetObject
*
so
,
PyObject
*
other
)
{
...
...
@@ -1861,6 +1927,8 @@ static PyMethodDef set_methods[] = {
intersection_doc
},
{
"intersection_update"
,(
PyCFunction
)
set_intersection_update
,
METH_O
,
intersection_update_doc
},
{
"isdisjoint"
,
(
PyCFunction
)
set_isdisjoint
,
METH_O
,
isdisjoint_doc
},
{
"issubset"
,
(
PyCFunction
)
set_issubset
,
METH_O
,
issubset_doc
},
{
"issuperset"
,
(
PyCFunction
)
set_issuperset
,
METH_O
,
...
...
@@ -1984,6 +2052,8 @@ static PyMethodDef frozenset_methods[] = {
difference_doc
},
{
"intersection"
,(
PyCFunction
)
set_intersection
,
METH_O
,
intersection_doc
},
{
"isdisjoint"
,
(
PyCFunction
)
set_isdisjoint
,
METH_O
,
isdisjoint_doc
},
{
"issubset"
,
(
PyCFunction
)
set_issubset
,
METH_O
,
issubset_doc
},
{
"issuperset"
,
(
PyCFunction
)
set_issuperset
,
METH_O
,
...
...
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