+ System.out.println(" #GETNEWLOCATION:: start=" + start + " endSet=" + endSet + " dist="
+ + dist + " isShared=" + isShared);
+ // if (dist == -1) {
+ // if (isShared) {
+ // // if the node is a shared one, check if the next node is shared
+ // // if not, need to insert a new shared node
+ // return recur_getNewLocation(lattice, start, endSet, dist + 1, isShared);
+ // } else {
+ // return start;
+ // }
+ //
+ // }
+ return recur_getNewLocation(lattice, start, start, endSet, dist, isShared);
+ }
+
+ private String recur_getNewLocation(SSJavaLattice<String> lattice, String start, String cur,
+ Set<String> endSet, int dist, boolean isShared) {
+
+ System.out.println(" recur_getNewLocation cur=" + cur + " dist=" + dist);
+
+ if (dist == 0) {
+ if (isShared) {
+ // first check if there already exists a non-shared node at distance d
+ if (!isLocalLocation(lattice, cur) && !start.equals(cur)) {
+ // if not, need to insert a new local location at this point
+ System.out.println("if not, need to insert a new local location at this point");
+ String newLocName = "ILOC" + (LocationInference.locSeed++);
+ Set<String> lowerSet = new HashSet<String>();
+ lowerSet.addAll(lattice.get(cur));
+ lattice.insertNewLocationBetween(cur, lowerSet, newLocName);
+ addLocalLocation(lattice, newLocName);
+
+ // assign the new local location to cur
+ cur = newLocName;
+ }
+
+ Set<String> connectedSet = lattice.get(cur);
+ if (connectedSet == null) {
+ connectedSet = new HashSet<String>();
+ }
+ System.out.println("cur=" + cur + " connectedSet=" + connectedSet);
+
+ // check if there already exists a shared node that has distance d + 1 on the chain
+ boolean needToInsertSharedNode = false;
+ if (connectedSet.equals(endSet)) {
+ needToInsertSharedNode = true;
+ } else {
+ // in this case, the current node is in the middle of the chain
+ assert connectedSet.size() == 1;
+ String below = connectedSet.iterator().next();
+ if (lattice.isSharedLoc(below)) {
+ return below;
+ } else {
+ needToInsertSharedNode = true;
+ }
+ }
+
+ if (needToInsertSharedNode) {
+ // no shared local location at d+1, need to insert it!
+ String newSharedLocName = "ILOC" + (LocationInference.locSeed++);
+ Set<String> lowerSet = new HashSet<String>();
+ lowerSet.addAll(connectedSet);
+ lattice.insertNewLocationBetween(cur, lowerSet, newSharedLocName);
+ lattice.addSharedLoc(newSharedLocName);
+ addLocalLocation(lattice, newSharedLocName);
+ System.out.println(" INSERT NEW SHARED LOC=" + newSharedLocName);
+ cur = newSharedLocName;
+ }
+
+ return cur;
+
+ } else {
+
+ return cur;
+ // if the node is not shared, check if a node at distance d is a local or combination node
+ // Set<String> connectedSet = lattice.get(cur);
+ // if (connectedSet == null) {
+ // connectedSet = new HashSet<String>();
+ // }
+ // System.out
+ // .println("if the node is not shared, check if a node at distance d is a local or combination node connectedSet="
+ // + connectedSet);
+ // // if (!start.equals(cur) && (cur.equals(lattice.getTopItem()) ||
+ // connectedSet.equals(endSet))) {
+ // // if not, need to insert a new local location at this point
+ // System.out.println("NEED TO INSERT A NEW LOCAL LOC connectedSet=" + connectedSet);
+ // String newLocName = "ILOC" + (LocationInference.locSeed++);
+ // Set<String> lowerSet = new HashSet<String>();
+ // lowerSet.addAll(connectedSet);
+ // lattice.insertNewLocationBetween(cur, lowerSet, newLocName);
+ // addLocalLocation(lattice, newLocName);
+ // return newLocName;
+ // } else {
+ // return cur;
+ // }
+ }
+ }
+
+ Set<String> connectedSet = lattice.get(cur);
+ if (connectedSet == null) {
+ connectedSet = new HashSet<String>();
+ }
+
+ System.out.println("cur=" + cur + " connected set=" + connectedSet);
+ if (cur.equals(lattice.getTopItem()) || connectedSet.equals(endSet)) {
+ // if not, need to insert a new local location at this point
+ System.out.println("NEED TO INSERT A NEW LOCAL LOC FOR NEXT connectedSet=" + connectedSet);
+ String newLocName = "ILOC" + (LocationInference.locSeed++);
+ Set<String> lowerSet = new HashSet<String>();
+ lowerSet.addAll(connectedSet);
+ lattice.insertNewLocationBetween(cur, lowerSet, newLocName);
+ addLocalLocation(lattice, newLocName);
+ cur = newLocName;
+ } else {
+ // in this case, the current node is in the middle of the chain
+ assert connectedSet.size() == 1;
+ cur = connectedSet.iterator().next();
+ }
+
+ if (!lattice.isSharedLoc(cur)) {
+ dist--;
+ }
+ return recur_getNewLocation(lattice, start, cur, endSet, dist, isShared);
+
+ }
+
+ public String getNewLocation2(SSJavaLattice<String> lattice, String start, Set<String> endSet,
+ int dist, boolean isShared) {
+ System.out.println(" #GETNEWLOCATION:: start=" + start + " endSet=" + endSet + " dist="