Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data Structure for Storing Multi-key and Value Pairs in Java

Good evening,

I am searching for an elegant solution to implement a transition table (Specifically, for a universal pushdown automaton) that uses several discrete values for a given transition. They say a picture is worth a thousand words so here is part of my table:

State    InputSymbol    StackSymbol   Move(NewState, Action)
------------------------------------------------------------
  0           a              Z0           (0, push)
  0           a              a            (0, push)
  0           a              b            (0, pop)
  0           b              Z0           (1, push)
  ...

Now, I have considered multi-dimensional arrays, ArrayLists of ArrayLists, and other solutions of the sort but all seem rather brutish. This is further complicated by the fact that every possible combination of my three symbols (a, b, and Z0) is not represented in the table.

I have been contemplating using a HashMap, but I am not entirely sure how to make this work with multiple key values. I was considering concatenating all three symbols together and using the resultant string as my key but that, too, seems less than elegant.

And, for the record, this is homework but actually giving an elegant solution is not strictly required. I just enjoy good code.

Thank you in advance for your assistance.

like image 552
MysteryMoose Avatar asked Sep 06 '26 06:09

MysteryMoose


1 Answers

Make a class like this:

 class Key{
    int state;
    char inputSysmbol;
    String StackSymbol;
    }

Then use the map Map<Key,Move>.

Make a class for Move just like above and don't forget to override hashcode and equals method in both classes.

like image 93
Emil Avatar answered Sep 07 '26 18:09

Emil