Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
4a08067c
Commit
4a08067c
authored
Jan 12, 2014
by
John R. Lenton
Browse files
Implemented set.isdisjoint
parent
f1ae6b48
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/objset.c
View file @
4a08067c
...
...
@@ -212,6 +212,21 @@ static mp_obj_t set_intersect_update(mp_obj_t self_in, mp_obj_t other) {
}
static
MP_DEFINE_CONST_FUN_OBJ_2
(
set_intersect_update_obj
,
set_intersect_update
);
static
mp_obj_t
set_isdisjoint
(
mp_obj_t
self_in
,
mp_obj_t
other
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
set_type
));
mp_obj_set_t
*
self
=
self_in
;
mp_obj_t
iter
=
rt_getiter
(
other
);
mp_obj_t
next
;
while
((
next
=
rt_iternext
(
iter
))
!=
mp_const_stop_iteration
)
{
if
(
mp_set_lookup
(
&
self
->
set
,
next
,
MP_MAP_LOOKUP
))
{
return
mp_const_false
;
}
}
return
mp_const_true
;
}
static
MP_DEFINE_CONST_FUN_OBJ_2
(
set_isdisjoint_obj
,
set_isdisjoint
);
/******************************************************************************/
/* set constructors & public C API */
...
...
@@ -226,6 +241,7 @@ static const mp_method_t set_type_methods[] = {
{
"difference_update"
,
&
set_diff_update_obj
},
{
"intersection"
,
&
set_intersect_obj
},
{
"intersection_update"
,
&
set_intersect_update_obj
},
{
"isdisjoint"
,
&
set_isdisjoint_obj
},
{
NULL
,
NULL
},
// end-of-list sentinel
};
...
...
tests/basics/tests/set_isdisjoint.py
0 → 100644
View file @
4a08067c
s
=
{
1
,
2
,
3
,
4
}
print
(
s
.
isdisjoint
({
1
}))
print
(
s
.
isdisjoint
([
2
]))
print
(
s
.
isdisjoint
([]))
print
(
s
.
isdisjoint
({
7
,
8
,
9
,
10
}))
print
(
s
.
isdisjoint
([
7
,
8
,
9
,
1
]))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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