Simplified Equality
This commit is contained in:
@@ -47,6 +47,7 @@ type Hash struct {
|
||||
func (h *Hash) Type() ObjectType {
|
||||
return HASH_OBJ
|
||||
}
|
||||
|
||||
func (h *Hash) Inspect() string {
|
||||
var out bytes.Buffer
|
||||
|
||||
@@ -64,28 +65,29 @@ func (h *Hash) Inspect() string {
|
||||
func (h *Hash) String() string {
|
||||
return h.Inspect()
|
||||
}
|
||||
func (h *Hash) Equal(other Object) bool {
|
||||
|
||||
func (h *Hash) Compare(other Object) int {
|
||||
if obj, ok := other.(*Hash); ok {
|
||||
if len(h.Pairs) != len(obj.Pairs) {
|
||||
return false
|
||||
return -1
|
||||
}
|
||||
for _, pair := range h.Pairs {
|
||||
left := pair.Value
|
||||
hashed := left.(Hashable)
|
||||
right, ok := obj.Pairs[hashed.HashKey()]
|
||||
if !ok {
|
||||
return false
|
||||
return -1
|
||||
}
|
||||
cmp, ok := left.(Comparable)
|
||||
if !ok {
|
||||
return false
|
||||
return -1
|
||||
}
|
||||
if !cmp.Equal(right.Value) {
|
||||
return false
|
||||
if cmp.Compare(right.Value) != 0 {
|
||||
return cmp.Compare(right.Value)
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
return 0
|
||||
}
|
||||
return false
|
||||
return -1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user