I have a Scala application which explores a HUGE state space of a particular graph transition function. I’m currently using a Map[String,Int] to detect whether I’m visiting the same space twice. Each key of the Map is a String of exactly 24 characters, and each value is a small integer representing the shortest path length to a given graph node (this integer is always less than 11 as far as I can tell, although the goal of the experiment is to find the maximum such shortest path length). However, there are only 6 possible characters. Thus I can represent the string as an integer between 0 and 6^24-1.
Thus my maximum integer is 555,555,555,555,555,555 (base 6), which I calculate to be 4,738,381,338,321,616,895 (base 10).
Question: Which data type should I use for the integer?
Question: Is there some sort of compressed-string object I can use rather than Integer?
Question: Assuming to use Integer, what is the best (fastest) way to convert back and forth between such Integer and String?
The way I know is to use a fold/reduce to convert the String to Integer and accumulate the integer by successive add and multiply by 6. And to convert from Integer to String, by divide/remainder 24 times, computing 24 characters, then concatenating them into a string.
And as a related question, Can I ask the Scala Integer arithmetic to give me an exception on integer overflow rather than just giving me the wrong answer?