-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
equality and hash for terms and schemas #241
base: master
Are you sure you want to change the base?
Conversation
Co-Authored-By: Dave Kleinschmidt <[email protected]>
length(first.schema) != length(second.schema) && return false | ||
for key in keys(first) | ||
!haskey(second, key) && return false | ||
second[key] != first[key] && return false | ||
end | ||
true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this identical to first == second
? If not, maybe worth a comment. (Note that this throws if the dict contains missing
, maybe that's OK though.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm I think you're right. Probably fine to just check first.schema == second.schema
since that's really what this check is about
first === second && return true | ||
first.schema === second.schema && return true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this will be wrong if the dict contains missing
(recursively). Can this happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a key or a value? Not possible either way at the moment (unless it's a pathological manuallly constructed instance)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a value I think, as for keys dicts use isequal
. Note that this also applies if the value contains an object which contains a missing value (whatever the number of recursions).
true | ||
end | ||
|
||
Base.hash(schema::Schema, h::UInt) = hash(schema.schema, h) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes (e.g. for arrays and tuples) we add an arbitrary constant to h
(type-specific) to ensure that hash(schema) != hash(schema.schema)
. Not sure whether it's worth it here though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wondered about that too. Easy to do here, a bit tricker in the case of the terms (where the types might not be the asme for things that we want to be ==
, e.g. different instances of a function term whre the anonymous function is different but the underlying expression is the same).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And that can "corrupt" the type of containers because of the ahem zealous use of type parameters in this codebase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't necessarily need to hash the type: you can just define a constant and use it for all types which compare ==
.
based on #174 (upstream user/repo seems to have been deleted) with a few tweaks