@@ -212,6 +212,21 @@ static mp_obj_t set_intersect_update(mp_obj_t self_in, mp_obj_t other) {
212212}
213213static MP_DEFINE_CONST_FUN_OBJ_2 (set_intersect_update_obj , set_intersect_update ) ;
214214
215+ static mp_obj_t set_isdisjoint (mp_obj_t self_in , mp_obj_t other ) {
216+ assert (MP_OBJ_IS_TYPE (self_in , & set_type ));
217+ mp_obj_set_t * self = self_in ;
218+
219+ mp_obj_t iter = rt_getiter (other );
220+ mp_obj_t next ;
221+ while ((next = rt_iternext (iter )) != mp_const_stop_iteration ) {
222+ if (mp_set_lookup (& self -> set , next , MP_MAP_LOOKUP )) {
223+ return mp_const_false ;
224+ }
225+ }
226+ return mp_const_true ;
227+ }
228+ static MP_DEFINE_CONST_FUN_OBJ_2 (set_isdisjoint_obj , set_isdisjoint ) ;
229+
215230
216231/******************************************************************************/
217232/* set constructors & public C API */
@@ -226,6 +241,7 @@ static const mp_method_t set_type_methods[] = {
226241 { "difference_update" , & set_diff_update_obj },
227242 { "intersection" , & set_intersect_obj },
228243 { "intersection_update" , & set_intersect_update_obj },
244+ { "isdisjoint" , & set_isdisjoint_obj },
229245 { NULL , NULL }, // end-of-list sentinel
230246};
231247
0 commit comments