MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / tryAddParentWithWeight

Method tryAddParentWithWeight

src/function/gds/bfs_graph.cpp:93–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91}
92
93bool DenseBFSGraph::tryAddParentWithWeight(nodeID_t boundNodeID, relID_t edgeID, nodeID_t nbrNodeID,
94 bool fwdEdge, double weight, ObjectBlock<ParentList>* block) {
95 ParentList* expected = getParentListHead(nbrNodeID.offset);
96 auto parent = reserveParent(boundNodeID, edgeID, fwdEdge, block);
97 parent->setCost(getParentListHead(boundNodeID)->getCost() + weight);
98 while (true) {
99 if (parent->getCost() < getCost(expected)) {
100 // New parent has smaller cost, erase all existing parents and add new parent.
101 if (curData[nbrNodeID.offset].compare_exchange_strong(expected, parent)) {
102 parent->setNextPtr(nullptr);
103 return true;
104 }
105 } else if (parent->getCost() == getCost(expected) && expected->getEdgeID() != edgeID) {
106 // New parent has the same cost and comes from different edge,
107 // append new parent as after existing parents.
108 if (curData[nbrNodeID.offset].compare_exchange_strong(expected, parent)) {
109 parent->setNextPtr(expected);
110 return true;
111 }
112 } else {
113 block->revertLast();
114 return false;
115 }
116 }
117}
118
119bool DenseBFSGraph::tryAddSingleParentWithWeight(nodeID_t boundNodeID, relID_t edgeID,
120 nodeID_t nbrNodeID, bool fwdEdge, double weight, ObjectBlock<ParentList>* block) {

Callers 1

edgeComputeMethod · 0.80

Calls 10

reserveParentFunction · 0.85
setNextPtrMethod · 0.80
getEdgeIDMethod · 0.80
revertLastMethod · 0.80
eraseMethod · 0.80
getCostFunction · 0.70
setCostMethod · 0.45
getCostMethod · 0.45
insertMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected