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‎

Lines changed: 28 additions & 0 deletions
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__(otherObject) Object{
115+
b, ok:=other.(*Set)
116+
if!ok{
117+
returnNotImplemented
118+
}
119+
iflen(a.items) !=len(b.items){
120+
returnFalse
121+
}
122+
// FIXME nasty O(n**2) algorithm, waiting for proper hashing!
123+
fori:=rangea.items{
124+
forj:=rangeb.items{
125+
ifEq(i, j) ==True{
126+
goto found
127+
}
128+
}
129+
returnFalse
130+
found:
131+
}
132+
returnTrue
133+
}
134+
135+
func (a*Set) M__ne__(otherObject) Object{
136+
ifa.M__eq__(other) ==True{
137+
returnFalse
138+
}
139+
returnTrue
140+
}

0 commit comments

Comments
(0)