I have the numbers 0-8 so I can represent a state as
This gives me 40320 ways to represent a state so I have a HashMap of size 40320 and I need a good way to make sure each state only corresponds to 1 key 1-40320

I'm not really sure how to even come close to making sure there are no possible collisions. Any help would be greatly appreciated

first of all determine the value of the first state you want to represent. in this case
the first state becomes index 0 and next index 1 and so on. now write a function that
takes a value and compute it index or better still find a constant such that when
you divid or subtract the content from the valued u will get it index

I suspect you may be making a mistake about 40320. It looks like you have to account for every permutation of 9 digits, which means 362880 permutations, not 40320, and of course it is hopeless to try to number every state distinctly with 40320 numbers if there are 362880 states. 40320 states are what you would have if your digits were 0-7.