Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions src/analysis/typepal/Solver.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -1024,18 +1024,47 @@ Solver newSolver(map[str,Tree] namedTrees, TModel tm){
}
newPaths = { tup | tup:<loc u, PathRole _, loc d> <- newPaths, u != d };
tm.referPaths = referPaths;
newPathFound = !isEmpty(newPaths);
if( newPathFound // we found new paths
|| (!isEmpty(tm.paths) && isEmpty(pathsByPathRole)) // pathsByPathRole not yet initialized
){
tm.paths += newPaths;
pathsByPathRole = ();
for(<loc u, PathRole r, loc d> <- tm.paths){
pathsByPathRole[r] ? {} += {<u, d>};
}
tm.paths += newPaths;

initPathsByPathRole();
updatePathsByPathRole(newPaths);
return !isEmpty(newPaths);
}

void initPathsByPathRole() {
if (!isEmpty(pathsByPathRole)) { // Already initialized
return;
}

return newPathFound;
paths = tm.paths;
if (isEmpty(paths)) { // Nothing to initialize
return;
}

pathsByPathRole = (r: {} | <_, PathRole r, _> <- paths);
for (PathRole r <- pathsByPathRole) {
pathsByPathRole[r] = {<u, d> | <loc u, r, loc d> <- paths};
}
// That is, first compute the keys, and second compute the total
// values. It seems to be significantly faster than computing keys
// and total values together:
// ```
// pathsByPathRole = (r: {<u, d> | <loc u, r, loc d> <- paths} | <_, PathRole r, _> <- paths);
// ```
// It also seems to be significantly faster than computing keys
// and partial values iteratively:
// ```
// pathsByPathRole = ();
// for (<loc u, PathRole r, loc d> <- tm.paths) {
// pathsByPathRole[r] ? {} += {<u, d>};
// }
// ```
}

void updatePathsByPathRole(Paths newPaths) {
for(<loc u, PathRole r, loc d> <- newPaths){
pathsByPathRole[r] ? {} += {<u, d>};
}
}

// ---- "equal" and "requireEqual" ----------------------------------------
Expand Down
Loading