Search code examples
hashcoderascal

Is it possible to get a hashcode or any unique representation of a value?


In Java, the Object class has a hashCode() function, which is useful to be able to get an (as much as possible) unique representation of an object. Does Rascal have something similar for value?

Purpose: I have a large list[value] (in which contents of a source code line are captures, eg str, node, int, etc.) and want to use it as a key in a lookup table (map).


Solution

  • In rascal you can use any value as a key in a map, if you only want certain fields to be important, I think the best way would be to create a new tuple with the fields that make up the key, and use that. But ik most cases, use the whole value, or perform a small simplification on the value.