瀏覽代碼

Change how path hashes are generated

Baglio Tabifata 4 年之前
父節點
當前提交
2d20b8b164
共有 2 個文件被更改,包括 7 次插入6 次删除
  1. 3 5
      src/net/hkzlab/dupal/boardio/DuPALAnalyzer.java
  2. 4 1
      src/net/hkzlab/palanalisys/MacroState.java

+ 3 - 5
src/net/hkzlab/dupal/boardio/DuPALAnalyzer.java

@@ -232,11 +232,9 @@ public class DuPALAnalyzer {
         // Search for a state that still has unexplored links
         for(int ms_idx = 0; ms_idx < mStates.length; ms_idx++) {
             if((mStates[ms_idx] != null) && (mStates[ms_idx] != start_ms)) {
-                for(int sl_idx = 0; sl_idx < mStates[ms_idx].links.length; sl_idx++) {
-                    if(mStates[ms_idx].links[sl_idx] == null) { // Found an unexplored link, we need to search a path to it
-                        
+                if(mStates[ms_idx].link_count != mStates[ms_idx].links.length) {
                         logger.info("Found unexplored link in ["+mStates[ms_idx]+"]");
-                        int path_hash = (start_ms.hashCode() - mStates[ms_idx].hashCode()) ^ start_ms.hashCode();
+                        int path_hash = ((start_ms.hashCode() * 31) + mStates[ms_idx].hashCode());
                         StateLink[] sll = pathMap.get(Integer.valueOf(path_hash));
 
                         if(sll == null) {
@@ -245,7 +243,6 @@ public class DuPALAnalyzer {
                         }
 
                         if(sll != null) return sll; // Ok, we found a path
-                    }
                 }
             }
         }
@@ -346,6 +343,7 @@ public class DuPALAnalyzer {
                 }
                 sl = new StateLink(ms.tag, idx, nms);
                 ms.links[links_counter] = sl;
+                ms.link_count++;
 
                 logger.info("Connected MS '"+ms+"' with MS '"+nms+"' by SL '"+sl+"'");
 

+ 4 - 1
src/net/hkzlab/palanalisys/MacroState.java

@@ -4,7 +4,7 @@ import java.io.Serializable;
 import java.util.HashMap;
 
 public class MacroState implements Serializable { 
-    private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 2L;
 
     public static final String MS_PRE_TAG = "MS_";
 
@@ -16,6 +16,7 @@ public class MacroState implements Serializable {
 
     public final SubState[] substates;
     public final StateLink[] links;
+    public int link_count;
     public final HashMap<Integer, SubState> ssMap;
 
     public MacroState(final String tag, final int rpin_status, final int rpins, final int inPins) {
@@ -27,6 +28,8 @@ public class MacroState implements Serializable {
         substates = new SubState[1 << inPins]; // Create space for substates (each output pin is 3-state, but as they're triggered via input changes, we can have at most 2^inPins)
         ssMap = new HashMap<>(); // Prepare the hashmap we'll use to avoid substate duplicates
 
+        this.link_count = 0;
+
         ss_ready = false;
     }