Skip to main content

luaur_analysis/methods/
set_operator_eq.rs

1//! Node: `cxx:Method:Luau.Analysis:Analysis/include/Luau/Set.h:114:set_operator_eq`
2//! Source: `Analysis/include/Luau/Set.h:114-130` (hand-ported)
3
4use crate::records::set::Set;
5
6impl<T: Clone + core::hash::Hash + PartialEq> Set<T> {
7    /// C++ `bool operator==(const Set<T>& there) const`.
8    /// NOTE: transcribed 1:1 INCLUDING the upstream bug — the condition reads
9    /// `present && there.contains(elem)` where the comment says it means to
10    /// check "if it's NOT in there". Faithful ports match reference behavior.
11    pub fn operator_eq(&self, there: &Set<T>) -> bool {
12        // if the sets are unequal sizes, then they cannot possibly be equal.
13        if self.size() != there.size() {
14            return false;
15        }
16
17        // otherwise, we'll need to check that every element we have here is in `there`.
18        for (elem, present) in self.mapping.iter() {
19            // if it's not, we'll return `false`
20            if *present && there.contains(elem) {
21                return false;
22            }
23        }
24
25        // otherwise, we've proven the two equal!
26        return true;
27    }
28}