SubState.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package info.hkzlab.dupal.analyzer.palanalisys;
  2. import java.io.Serializable;
  3. import java.util.Arrays;
  4. public class SubState implements Serializable {
  5. private static final long serialVersionUID = 1L;
  6. public static final String SS_PRE_TAG = "SS_";
  7. public final String tag;
  8. public final MacroState macroState;
  9. public final Byte[] IOpin_status;
  10. public final Byte[] Opin_status;
  11. public SubState(final String tag, final MacroState macroState, final Byte[] IOpin_status, final Byte[] Opin_status) {
  12. this.tag = tag;
  13. this.macroState = macroState;
  14. this.IOpin_status = IOpin_status;
  15. this.Opin_status = Opin_status;
  16. }
  17. @Override
  18. public String toString() {
  19. StringBuffer strBuf = new StringBuffer();
  20. strBuf.append(SS_PRE_TAG+tag+"-");
  21. if(IOpin_status.length > 0) {
  22. for(byte pin : IOpin_status) {
  23. if(pin < 0) strBuf.append('x');
  24. else if (pin == 0) strBuf.append(0);
  25. else strBuf.append(1);
  26. }
  27. } else strBuf.append("noIO");
  28. strBuf.append("_");
  29. if(Opin_status.length > 0) {
  30. for(byte pin : Opin_status) {
  31. if(pin < 0) strBuf.append('x');
  32. else if (pin == 0) strBuf.append(0);
  33. else strBuf.append(1);
  34. }
  35. } else strBuf.append("noO");
  36. return strBuf.toString();
  37. }
  38. @Override
  39. public int hashCode() {
  40. return calculateHashFromArrays(new Byte[][] {IOpin_status, Opin_status});
  41. }
  42. static public int calculateHashFromArrays(Byte[][] arrays) {
  43. int hash = 7;
  44. for(Byte[] arr : arrays) {
  45. for(int idx = 0; idx < arr.length; idx++) {
  46. hash = hash*31 + arr[idx];
  47. }
  48. }
  49. return hash;
  50. }
  51. @Override
  52. public boolean equals(Object o) {
  53. if(this == o) return true;
  54. if(o == null) return false;
  55. if(this.getClass() != o.getClass()) return false;
  56. SubState ops = (SubState)o;
  57. if(!ops.tag.equals(this.tag)) return false;
  58. if(!Arrays.equals(ops.IOpin_status, this.IOpin_status)) return false;
  59. if(!Arrays.equals(ops.Opin_status, this.Opin_status)) return false;
  60. return true;
  61. }
  62. public static int calculateSubStateIndex(final boolean[] inputs) {
  63. int index = 0;
  64. for(int idx = 0; idx < inputs.length; idx++) {
  65. index += ((inputs[idx] ? 1 : 0) << idx);
  66. }
  67. return index;
  68. }
  69. }