Skip to content

Commit 4c262c1

Browse files
authored
Merge branch 'master' into add-new-system-tests-for-next-and-call
2 parents a855338 + 10b7439 commit 4c262c1

File tree

2 files changed

+10
-55
lines changed

2 files changed

+10
-55
lines changed

Team20/Code20/source/DispatcherGraph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void DispatcherGraph::addDispatcher(ClauseDispatcher *dispatcher) {
2323
}
2424
for (const auto &associatedDispatcher :
2525
symbolsToClauseDispatchersMap[symbol]) {
26-
int weight = countCommonSymbols(dispatcher, associatedDispatcher) * 2;
26+
int weight = countCommonSymbols(dispatcher, associatedDispatcher) * -2;
2727
adjacencyList.at(dispatcher)
2828
.insert(Edge{
2929
associatedDispatcher,

Team20/Code20/source/PKB.cpp

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,7 +2365,6 @@ LINE_SET Pkb::getTransitiveNextStatements(LINE_NO lineNo,
23652365
LINE_SET transitiveStatements =
23662366
getTransitiveNextStatements(next, lineNosVisited);
23672367
result.merge(transitiveStatements);
2368-
lineNosVisited.merge(transitiveStatements);
23692368
}
23702369
}
23712370
}
@@ -2392,7 +2391,6 @@ LINE_SET Pkb::getTransitivePrevStatements(LINE_NO lineNo,
23922391
LINE_SET transitiveStatements =
23932392
getTransitivePrevStatements(prev, lineNosVisited);
23942393
result.merge(transitiveStatements);
2395-
lineNosVisited.merge(transitiveStatements);
23962394
}
23972395
}
23982396
}
@@ -2404,12 +2402,6 @@ LINE_SET Pkb::getTransitivePrevStatements(LINE_NO lineNo,
24042402

24052403
bool Pkb::affects(LineNumber line1, LineNumber line2) {
24062404
LINE_SET affectedStatements = getAffectedStatements(line1.number);
2407-
2408-
// add to cache if it's not in cache
2409-
if (affectsTableCache.map.find(line1.number) == affectsTableCache.map.end()) {
2410-
affectsTableCache.insert(std::pair(line1.number, affectedStatements));
2411-
}
2412-
24132405
return affectedStatements.find(line2.number) != affectedStatements.end();
24142406
}
24152407

@@ -2418,24 +2410,12 @@ LINE_SET Pkb::affects(LineNumber line, Statement statement) {
24182410
if (!statement.type.has_value() ||
24192411
statement.type.value() == StatementType::Assign) {
24202412
result = getAffectedStatements(line.number);
2421-
2422-
// add to cache if it's not in cache
2423-
if (affectsTableCache.map.find(line.number) ==
2424-
affectsTableCache.map.end()) {
2425-
affectsTableCache.insert(std::pair(line.number, result));
2426-
}
24272413
}
24282414
return result;
24292415
}
24302416

24312417
bool Pkb::affects(LineNumber line, Underscore underscore) {
24322418
LINE_SET affectedStatements = getAffectedStatements(line.number);
2433-
2434-
// add to cache if it's not in cache
2435-
if (affectsTableCache.map.find(line.number) == affectsTableCache.map.end()) {
2436-
affectsTableCache.insert(std::pair(line.number, affectedStatements));
2437-
}
2438-
24392419
return !affectedStatements.empty();
24402420
}
24412421

@@ -2444,12 +2424,6 @@ LINE_SET Pkb::affects(Statement statement, LineNumber line) {
24442424
if (!statement.type.has_value() ||
24452425
statement.type.value() == StatementType::Assign) {
24462426
result = getAffectorStatements(line.number);
2447-
2448-
// add to cache if it's not in cache
2449-
if (invertAffectsTableCache.map.find(line.number) ==
2450-
invertAffectsTableCache.map.end()) {
2451-
invertAffectsTableCache.insert(std::pair(line.number, result));
2452-
}
24532427
}
24542428
return result;
24552429
}
@@ -2472,8 +2446,9 @@ LINE_LINE_PAIRS Pkb::affects(Statement statement1, Statement statement2) {
24722446
// only need to compute and cache entry if its not already inside
24732447
// cache table.
24742448
if (affectsTableCache.map.find(line) == affectsTableCache.map.end()) {
2475-
LINE_SET affectedStatements = getAffectedStatements(line);
2476-
affectsTableCache.insert(std::pair(line, affectedStatements));
2449+
// adding to cache is done within the called function. So we only
2450+
// have to call the function to get it cached.
2451+
getAffectedStatements(line);
24772452
}
24782453
}
24792454

@@ -2515,11 +2490,6 @@ LINE_SET Pkb::affects(Statement statement, Underscore underscore) {
25152490
if (!affectedStatements.empty()) {
25162491
result.insert(line);
25172492
}
2518-
2519-
// add into cache if its not in cache
2520-
if (affectsTableCache.map.find(line) == affectsTableCache.map.end()) {
2521-
affectsTableCache.insert(std::pair(line, affectedStatements));
2522-
}
25232493
}
25242494
}
25252495
}
@@ -2528,13 +2498,6 @@ LINE_SET Pkb::affects(Statement statement, Underscore underscore) {
25282498

25292499
bool Pkb::affects(Underscore underscore, LineNumber line) {
25302500
LINE_SET affectorStatements = getAffectorStatements(line.number);
2531-
2532-
// add into cache if its not in cache
2533-
if (invertAffectsTableCache.map.find(line.number) ==
2534-
invertAffectsTableCache.map.end()) {
2535-
invertAffectsTableCache.insert(std::pair(line.number, affectorStatements));
2536-
}
2537-
25382501
return !affectorStatements.empty();
25392502
}
25402503

@@ -2554,12 +2517,6 @@ LINE_SET Pkb::affects(Underscore underscore, Statement statement) {
25542517
if (!affectorStatements.empty()) {
25552518
result.insert(line);
25562519
}
2557-
2558-
// add into cache if its not in cache
2559-
if (invertAffectsTableCache.map.find(line) ==
2560-
invertAffectsTableCache.map.end()) {
2561-
invertAffectsTableCache.insert(std::pair(line, affectorStatements));
2562-
}
25632520
}
25642521
}
25652522
}
@@ -2573,12 +2530,6 @@ bool Pkb::affects(Underscore underscore1, Underscore underscore2) {
25732530

25742531
for (LINE_NO line : assignments) {
25752532
LINE_SET affectedStatements = getAffectedStatements(line);
2576-
2577-
// add into cache if its not in cache
2578-
if (affectsTableCache.map.find(line) == affectsTableCache.map.end()) {
2579-
affectsTableCache.insert(std::pair(line, affectedStatements));
2580-
}
2581-
25822533
if (!affectedStatements.empty()) {
25832534
return true;
25842535
}
@@ -2604,6 +2555,9 @@ LINE_SET Pkb::getAffectedStatements(LINE_NO lineNo) {
26042555
for (NEXT next : nexts) {
26052556
result.merge(getAffectedAux(modifiedVar, next, {}));
26062557
}
2558+
2559+
// add to cache before returning result.
2560+
affectsTableCache.insert(std::pair(lineNo, result));
26072561
}
26082562
}
26092563
}
@@ -2711,6 +2665,9 @@ LINE_SET Pkb::getAffectorStatements(LINE_NO lineNo) {
27112665
result.merge(getAffectorAux(var, prev, {}));
27122666
}
27132667
}
2668+
2669+
// add to cache before returning result.
2670+
invertAffectsTableCache.insert(std::pair(lineNo, result));
27142671
}
27152672
}
27162673
}
@@ -2920,7 +2877,6 @@ LINE_SET Pkb::getTransitiveAffectedStatements(LINE_NO lineNo,
29202877
LINE_SET transitiveStatements =
29212878
getTransitiveAffectedStatements(assignment, lineNosVisited);
29222879
result.merge(transitiveStatements);
2923-
lineNosVisited.merge(transitiveStatements);
29242880
}
29252881
}
29262882
}
@@ -2945,7 +2901,6 @@ LINE_SET Pkb::getTransitiveAffectorStatements(LINE_NO lineNo,
29452901
LINE_SET transitiveStatements =
29462902
getTransitiveAffectorStatements(assignment, lineNosVisited);
29472903
result.merge(transitiveStatements);
2948-
lineNosVisited.merge(transitiveStatements);
29492904
}
29502905
}
29512906
}

0 commit comments

Comments
 (0)