-
Notifications
You must be signed in to change notification settings - Fork 425
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
can't create a set of sets #19156
Comments
In case it's not clear, the fix to this would be to add a Just to demonstrate, the following compiles: use Set;
// demonstrative purposes only, don't use at home
proc set.hash() {
return 1;
}
var foo: set(set(string)); |
One challenge with supporting a hash on a set is that they are mutable, so modifying a set would change its hash (unless you're using a trivial hash function) and that messes with the parent set's invariant. (Sidebar: I've never come across a hashtable impl that handles a value whose hash changes, has anyone else?) We might be able to at least issue a better error message if we do a reflection and check if the key type has a hash method and issue a compilerError if not |
In general when we're hashing things, we make a copy of the value being hashed, don't we? (and then don't give away refs to it easily?). I.e., if I do: var x = 45;
mySet.add(x);
x = 33; it's not as though I'm changing the integer value stored in |
My brain was not in Chapel mode, this must be a worry I've brought from other languages. I see now that |
That's a good point. At first, I was thinking "our set only has one implementation, so should always see keys in a specific order", but that failed to take into account what can happen with collisions, deletions and insertions in different orders, etc. Spitballing: We could sort the keys and then hash, but that would be $$ for large sets. We could take some sort of fingerprint of the set like the min, max, and number of values as a poor hash and then rely on |
Summary of Problem
I tried to create a set of sets of strings and got the following error. The type of the elements in the inner sets doesn't appear to matter.
Steps to Reproduce
Source Code:
Compile command:
chpl --no-devel foo.chpl
Execution command:
NA
Associated Future Test(s):
Configuration Information
chpl --version
:$CHPL_HOME/util/printchplenv --anonymize
:gcc --version
orclang --version
:module list
:The text was updated successfully, but these errors were encountered: