llvm.org GIT mirror llvm / 3a0a1f6
Simplify PBQP graph removeAdjEdgeId implementation. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204857 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 6 years ago
1 changed file(s) with 10 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
6666 return Idx;
6767 }
6868
69 // If a swap is performed, returns the new EdgeId that must be
70 // updated, otherwise returns invalidEdgeId().
71 EdgeId removeAdjEdgeId(AdjEdgeIdx Idx) {
72 EdgeId EIdToUpdate = Graph::invalidEdgeId();
73 if (Idx < AdjEdgeIds.size() - 1) {
74 std::swap(AdjEdgeIds[Idx], AdjEdgeIds.back());
75 EIdToUpdate = AdjEdgeIds[Idx];
76 }
69 void removeAdjEdgeId(Graph &G, NodeId ThisNId, AdjEdgeIdx Idx) {
70 // Swap-and-pop for fast removal.
71 // 1) Update the adj index of the edge currently at back().
72 // 2) Swap Edge at Idx with back().
73 // 3) pop_back()
74 // If Idx == size() - 1 then the updateAdjEdgeIdx and swap are
75 // redundant, but both operations are cheap.
76 G.getEdge(AdjEdgeIds.back()).updateAdjEdgeIdx(ThisNId, Idx);
77 std::swap(AdjEdgeIds[Idx], AdjEdgeIds.back());
7778 AdjEdgeIds.pop_back();
78 return EIdToUpdate;
7979 }
8080
8181 const AdjEdgeList& getAdjEdgeIds() const { return AdjEdgeIds; }
137137 assert(ThisEdgeAdjIdxs[NIdx] != NodeEntry::getInvalidAdjEdgeIdx() &&
138138 "Edge not connected to NIds[NIdx].");
139139 NodeEntry &N = G.getNode(NIds[NIdx]);
140 EdgeId EIdToUpdate = N.removeAdjEdgeId(ThisEdgeAdjIdxs[NIdx]);
141 if (EIdToUpdate != Graph::invalidEdgeId())
142 G.getEdge(EIdToUpdate).updateAdjEdgeIdx(NIds[NIdx], ThisEdgeAdjIdxs[NIdx]);
140 N.removeAdjEdgeId(G, NIds[NIdx], ThisEdgeAdjIdxs[NIdx]);
143141 ThisEdgeAdjIdxs[NIdx] = NodeEntry::getInvalidAdjEdgeIdx();
144142 }
145143