MCPcopy Index your code
hub / github.com/RustPython/RustPython / compare

Method compare

crates/vm/src/builtins/set.rs:225–244  ·  view source on GitHub ↗
(&self, other: &Self, op: PyComparisonOp, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

223 }
224
225 fn compare(&self, other: &Self, op: PyComparisonOp, vm: &VirtualMachine) -> PyResult<bool> {
226 if op == PyComparisonOp::Ne {
227 return self.compare(other, PyComparisonOp::Eq, vm).map(|eq| !eq);
228 }
229 if !op.eval_ord(self.len().cmp(&other.len())) {
230 return Ok(false);
231 }
232
233 let (superset, subset) = match op {
234 PyComparisonOp::Lt | PyComparisonOp::Le => (other, self),
235 _ => (self, other),
236 };
237
238 for key in subset.elements() {
239 if !superset.contains(&key, vm)? {
240 return Ok(false);
241 }
242 }
243 Ok(true)
244 }
245
246 pub(super) fn union(&self, other: ArgIterable, vm: &VirtualMachine) -> PyResult<Self> {
247 let set = self.clone();

Callers 2

issubsetMethod · 0.45
cmpMethod · 0.45

Calls 6

eval_ordMethod · 0.80
mapMethod · 0.45
cmpMethod · 0.45
lenMethod · 0.45
elementsMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected