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

Method tryAddSingleParentWithWeight

src/function/gds/bfs_graph.cpp:119–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117}
118
119bool DenseBFSGraph::tryAddSingleParentWithWeight(nodeID_t boundNodeID, relID_t edgeID,
120 nodeID_t nbrNodeID, bool fwdEdge, double weight, ObjectBlock<ParentList>* block) {
121 ParentList* expected = getParentListHead(nbrNodeID.offset);
122 auto parent = reserveParent(boundNodeID, edgeID, fwdEdge, block);
123 parent->setCost(getParentListHead(boundNodeID)->getCost() + weight);
124 while (parent->getCost() < getCost(expected)) {
125 if (curData[nbrNodeID.offset].compare_exchange_strong(expected, parent)) {
126 // Since each node can have one parent, set next ptr to nullptr.
127 parent->setNextPtr(nullptr);
128 return true;
129 }
130 }
131 // Other thread has added the parent. Do NOT add parent and revert reserved slot.
132 block->revertLast();
133 return false;
134}
135
136ParentList* DenseBFSGraph::getParentListHead(offset_t offset) {
137 DASSERT(curData);

Callers 1

edgeComputeMethod · 0.80

Calls 9

reserveParentFunction · 0.85
setNextPtrMethod · 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