Skip to content

Commit

Permalink
py: temporary set.__eq__ and set.__ne__
Browse files Browse the repository at this point in the history
  • Loading branch information
ncw committed May 15, 2015
1 parent 44242f0 commit 4a7ad17
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions py/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,31 @@ var _ I__bool__ = (*Set)(nil)
var _ I__iter__ = (*Set)(nil)

// var _ richComparison = (*Set)(nil)

func (a *Set) M__eq__(other Object) Object {
b, ok := other.(*Set)
if !ok {
return NotImplemented
}
if len(a.items) != len(b.items) {
return False
}
// FIXME nasty O(n**2) algorithm, waiting for proper hashing!
for i := range a.items {
for j := range b.items {
if Eq(i, j) == True {
goto found
}
}
return False
found:
}
return True
}

func (a *Set) M__ne__(other Object) Object {
if a.M__eq__(other) == True {
return False
}
return True
}

0 comments on commit 4a7ad17

Please sign in to comment.