Simplified Equality
Some checks failed
Build / build (push) Successful in 10m48s
Test / build (push) Failing after 17m11s

This commit is contained in:
Chuck Smith
2024-03-24 17:11:48 -04:00
parent fea9fb9f64
commit 1c99d2198b
11 changed files with 109 additions and 133 deletions

View File

@@ -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
}