@@ -222,6 +222,16 @@ impl PySetInner {
222
222
Ok ( new_inner)
223
223
}
224
224
225
+ fn isdisjoint ( & self , other : PyIterable , vm : & VirtualMachine ) -> PyResult < bool > {
226
+ for item in other. iter ( vm) ? {
227
+ let obj = item?;
228
+ if self . contains ( obj. clone ( ) , vm) ? {
229
+ return Ok ( false ) ;
230
+ }
231
+ }
232
+ Ok ( true )
233
+ }
234
+
225
235
fn iter ( & self , vm : & VirtualMachine ) -> PyListIterator {
226
236
let items = self . elements . values ( ) . cloned ( ) . collect ( ) ;
227
237
let set_list = vm. ctx . new_list ( items) ;
@@ -426,6 +436,10 @@ impl PySetRef {
426
436
) )
427
437
}
428
438
439
+ fn isdisjoint ( self , other : PyIterable , vm : & VirtualMachine ) -> PyResult < bool > {
440
+ self . inner . borrow ( ) . isdisjoint ( other, vm)
441
+ }
442
+
429
443
fn or ( self , other : SetIterable , vm : & VirtualMachine ) -> PyResult {
430
444
self . union ( other. iterable , vm)
431
445
}
@@ -633,6 +647,10 @@ impl PyFrozenSetRef {
633
647
) )
634
648
}
635
649
650
+ fn isdisjoint ( self , other : PyIterable , vm : & VirtualMachine ) -> PyResult < bool > {
651
+ self . inner . isdisjoint ( other, vm)
652
+ }
653
+
636
654
fn or ( self , other : SetIterable , vm : & VirtualMachine ) -> PyResult {
637
655
self . union ( other. iterable , vm)
638
656
}
@@ -788,7 +806,8 @@ pub fn init(context: &PyContext) {
788
806
"__isub__" => context. new_rustfunc( PySetRef :: isub) ,
789
807
"symmetric_difference_update" => context. new_rustfunc( PySetRef :: symmetric_difference_update) ,
790
808
"__ixor__" => context. new_rustfunc( PySetRef :: ixor) ,
791
- "__iter__" => context. new_rustfunc( PySetRef :: iter)
809
+ "__iter__" => context. new_rustfunc( PySetRef :: iter) ,
810
+ "isdisjoint" => context. new_rustfunc( PySetRef :: isdisjoint) ,
792
811
} ) ;
793
812
794
813
let frozenset_type = & context. frozenset_type ;
@@ -819,6 +838,7 @@ pub fn init(context: &PyContext) {
819
838
"__doc__" => context. new_str( frozenset_doc. to_string( ) ) ,
820
839
"__repr__" => context. new_rustfunc( PyFrozenSetRef :: repr) ,
821
840
"copy" => context. new_rustfunc( PyFrozenSetRef :: copy) ,
822
- "__iter__" => context. new_rustfunc( PyFrozenSetRef :: iter)
841
+ "__iter__" => context. new_rustfunc( PyFrozenSetRef :: iter) ,
842
+ "isdisjoint" => context. new_rustfunc( PyFrozenSetRef :: isdisjoint) ,
823
843
} ) ;
824
844
}
0 commit comments