Skip to content

Commit 4a7ad17

Browse files
committed
py: temporary set.__eq__ and set.__ne__
1 parent 44242f0 commit 4a7ad17

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

py/set.go

+28
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,31 @@ var _ I__bool__ = (*Set)(nil)
110110
var _ I__iter__ = (*Set)(nil)
111111

112112
// var _ richComparison = (*Set)(nil)
113+
114+
func (a *Set) M__eq__(other Object) Object {
115+
b, ok := other.(*Set)
116+
if !ok {
117+
return NotImplemented
118+
}
119+
if len(a.items) != len(b.items) {
120+
return False
121+
}
122+
// FIXME nasty O(n**2) algorithm, waiting for proper hashing!
123+
for i := range a.items {
124+
for j := range b.items {
125+
if Eq(i, j) == True {
126+
goto found
127+
}
128+
}
129+
return False
130+
found:
131+
}
132+
return True
133+
}
134+
135+
func (a *Set) M__ne__(other Object) Object {
136+
if a.M__eq__(other) == True {
137+
return False
138+
}
139+
return True
140+
}

0 commit comments

Comments
 (0)