Skip to content

Commit d659754

Browse files
committed
replace std::unordered_set with robin_hood in find path executor
1 parent 7111c57 commit d659754

11 files changed

+47
-38
lines changed

src/graph/executor/algo/BFSShortestPathExecutor.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ folly::Future<Status> BFSShortestPathExecutor::execute() {
1717
allRightEdges_.emplace_back();
1818
auto& currentEdges = allRightEdges_.back();
1919
auto rIter = ectx_->getResult(pathNode_->rightVidVar()).iter();
20-
std::unordered_set<Value> rightVids;
20+
HashSet rightVids;
2121
for (; rIter->valid(); rIter->next()) {
2222
auto& vid = rIter->getColumn(0);
2323
if (rightVids.emplace(vid).second) {
@@ -61,7 +61,7 @@ Status BFSShortestPathExecutor::buildPath(bool reverse) {
6161
auto iterSize = iter->size();
6262
visitedVids.reserve(visitedVids.size() + iterSize);
6363

64-
std::unordered_set<Value> uniqueDst;
64+
HashSet uniqueDst;
6565
uniqueDst.reserve(iterSize);
6666
DataSet nextStepVids;
6767
nextStepVids.colNames = {nebula::kVid};
@@ -108,7 +108,7 @@ Status BFSShortestPathExecutor::buildPath(bool reverse) {
108108
folly::Future<Status> BFSShortestPathExecutor::conjunctPath() {
109109
const auto& leftEdges = allLeftEdges_.back();
110110
const auto& preRightEdges = allRightEdges_[step_ - 1];
111-
std::unordered_set<Value> meetVids;
111+
HashSet meetVids;
112112
bool oddStep = true;
113113
for (const auto& edge : leftEdges) {
114114
if (preRightEdges.find(edge.first) != preRightEdges.end()) {

src/graph/executor/algo/BFSShortestPathExecutor.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#ifndef GRAPH_EXECUTOR_ALGO_BFSSHORTESTPATHEXECUTOR_H_
66
#define GRAPH_EXECUTOR_ALGO_BFSSHORTESTPATHEXECUTOR_H_
7+
#include <robin_hood.h>
8+
79
#include "graph/executor/Executor.h"
810

911
// BFSShortestPath has two inputs. GetNeighbors(From) & GetNeighbors(To)
@@ -42,6 +44,7 @@ namespace graph {
4244
class BFSShortestPath;
4345
class BFSShortestPathExecutor final : public Executor {
4446
public:
47+
using HashSet = robin_hood::unordered_flat_set<Value, std::hash<Value>>;
4548
BFSShortestPathExecutor(const PlanNode* node, QueryContext* qctx)
4649
: Executor("BFSShortestPath", node, qctx) {}
4750

@@ -61,8 +64,8 @@ class BFSShortestPathExecutor final : public Executor {
6164
private:
6265
const BFSShortestPath* pathNode_{nullptr};
6366
size_t step_{1};
64-
std::unordered_set<Value> leftVisitedVids_;
65-
std::unordered_set<Value> rightVisitedVids_;
67+
HashSet leftVisitedVids_;
68+
HashSet rightVisitedVids_;
6669
std::vector<std::unordered_multimap<Value, Edge>> allLeftEdges_;
6770
std::vector<std::unordered_multimap<Value, Edge>> allRightEdges_;
6871
DataSet currentDs_;

src/graph/executor/algo/BatchShortestPath.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ using nebula::storage::StorageClient;
1212
DECLARE_uint32(num_path_thread);
1313
namespace nebula {
1414
namespace graph {
15-
folly::Future<Status> BatchShortestPath::execute(const std::unordered_set<Value>& startVids,
16-
const std::unordered_set<Value>& endVids,
15+
folly::Future<Status> BatchShortestPath::execute(const HashSet& startVids,
16+
const HashSet& endVids,
1717
DataSet* result) {
1818
size_t rowSize = init(startVids, endVids);
1919
std::vector<folly::Future<Status>> futures;
@@ -36,8 +36,7 @@ folly::Future<Status> BatchShortestPath::execute(const std::unordered_set<Value>
3636
});
3737
}
3838

39-
size_t BatchShortestPath::init(const std::unordered_set<Value>& startVids,
40-
const std::unordered_set<Value>& endVids) {
39+
size_t BatchShortestPath::init(const HashSet& startVids, const HashSet& endVids) {
4140
size_t rowSize = splitTask(startVids, endVids);
4241

4342
leftVids_.reserve(rowSize);
@@ -473,8 +472,7 @@ void BatchShortestPath::setNextStepVid(const PathMap& paths, size_t rowNum, bool
473472
}
474473
}
475474

476-
size_t BatchShortestPath::splitTask(const std::unordered_set<Value>& startVids,
477-
const std::unordered_set<Value>& endVids) {
475+
size_t BatchShortestPath::splitTask(const HashSet& startVids, const HashSet& endVids) {
478476
size_t threadNum = FLAGS_num_path_thread;
479477
size_t startVidsSize = startVids.size();
480478
size_t endVidsSize = endVids.size();

src/graph/executor/algo/BatchShortestPath.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@ class BatchShortestPath final : public ShortestPathBase {
1616
std::unordered_map<std::string, std::string>* stats)
1717
: ShortestPathBase(node, qctx, stats) {}
1818

19-
folly::Future<Status> execute(const std::unordered_set<Value>& startVids,
20-
const std::unordered_set<Value>& endVids,
19+
folly::Future<Status> execute(const HashSet& startVids,
20+
const HashSet& endVids,
2121
DataSet* result) override;
2222

2323
using CustomPath = Row;
2424
using PathMap = std::unordered_map<DstVid, std::unordered_map<StartVid, std::vector<CustomPath>>>;
2525

2626
private:
27-
size_t splitTask(const std::unordered_set<Value>& startVids,
28-
const std::unordered_set<Value>& endVids);
27+
size_t splitTask(const HashSet& startVids, const HashSet& endVids);
2928

30-
size_t init(const std::unordered_set<Value>& startVids, const std::unordered_set<Value>& endVids);
29+
size_t init(const HashSet& startVids, const HashSet& endVids);
3130

3231
folly::Future<Status> getNeighbors(size_t rowNum, size_t stepNum, bool reverse);
3332

src/graph/executor/algo/ProduceAllPathsExecutor.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
// This source code is licensed under Apache 2.0 License.
44
#include "graph/executor/algo/ProduceAllPathsExecutor.h"
55

6+
#include <robin_hood.h>
7+
68
#include "graph/planner/plan/Algo.h"
9+
710
DECLARE_int32(num_operator_threads);
811
namespace nebula {
912
namespace graph {
@@ -14,7 +17,8 @@ folly::Future<Status> ProduceAllPathsExecutor::execute() {
1417

1518
if (step_ == 1) {
1619
auto rIter = ectx_->getResult(pathNode_->rightVidVar()).iter();
17-
std::unordered_set<Value> rightVids;
20+
using HashSet = robin_hood::unordered_flat_set<Value, std::hash<Value>>;
21+
HashSet rightVids;
1822
for (; rIter->valid(); rIter->next()) {
1923
auto& vid = rIter->getColumn(0);
2024
if (rightVids.emplace(vid).second) {

src/graph/executor/algo/ShortestPathBase.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#ifndef GRAPH_EXECUTOR_ALGO_SHORTESTPATHBASE_H_
55
#define GRAPH_EXECUTOR_ALGO_SHORTESTPATHBASE_H_
66

7+
#include <robin_hood.h>
8+
79
#include "graph/planner/plan/Algo.h"
810

911
using nebula::storage::StorageRpcResponse;
@@ -14,6 +16,7 @@ namespace nebula {
1416
namespace graph {
1517
class ShortestPathBase {
1618
public:
19+
using HashSet = robin_hood::unordered_flat_set<Value, std::hash<Value>>;
1720
ShortestPathBase(const ShortestPath* node,
1821
QueryContext* qctx,
1922
std::unordered_map<std::string, std::string>* stats)
@@ -24,8 +27,8 @@ class ShortestPathBase {
2427

2528
virtual ~ShortestPathBase() {}
2629

27-
virtual folly::Future<Status> execute(const std::unordered_set<Value>& startVids,
28-
const std::unordered_set<Value>& endVids,
30+
virtual folly::Future<Status> execute(const HashSet& startVids,
31+
const HashSet& endVids,
2932
DataSet* result) = 0;
3033

3134
using DstVid = Value;

src/graph/executor/algo/ShortestPathExecutor.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ folly::Future<Status> ShortestPathExecutor::execute() {
2222
DataSet result;
2323
result.colNames = pathNode_->colNames();
2424

25-
std::unordered_set<Value> startVids;
26-
std::unordered_set<Value> endVids;
25+
HashSet startVids;
26+
HashSet endVids;
2727
size_t rowSize = checkInput(startVids, endVids);
2828
std::unique_ptr<ShortestPathBase> pathPtr = nullptr;
2929
if (rowSize <= FLAGS_num_path_thread) {
@@ -36,8 +36,7 @@ folly::Future<Status> ShortestPathExecutor::execute() {
3636
return finish(ResultBuilder().value(Value(std::move(result))).build());
3737
}
3838

39-
size_t ShortestPathExecutor::checkInput(std::unordered_set<Value>& startVids,
40-
std::unordered_set<Value>& endVids) {
39+
size_t ShortestPathExecutor::checkInput(HashSet& startVids, HashSet& endVids) {
4140
auto iter = ectx_->getResult(pathNode_->inputVar()).iter();
4241
const auto& vidType = *(qctx()->rctx()->session()->space().spaceDesc.vid_type_ref());
4342
for (; iter->valid(); iter->next()) {

src/graph/executor/algo/ShortestPathExecutor.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@
44
#ifndef GRAPH_EXECUTOR_ALGO_SHORTESTPATHEXECUTOR_H_
55
#define GRAPH_EXECUTOR_ALGO_SHORTESTPATHEXECUTOR_H_
66

7+
#include <robin_hood.h>
8+
79
#include "graph/executor/Executor.h"
810
#include "graph/planner/plan/Algo.h"
11+
912
namespace nebula {
1013
namespace graph {
1114
class ShortestPathExecutor final : public Executor {
1215
public:
16+
using HashSet = robin_hood::unordered_flat_set<Value, std::hash<Value>>;
1317
ShortestPathExecutor(const PlanNode* node, QueryContext* qctx)
1418
: Executor("ShortestPath", node, qctx) {
1519
pathNode_ = asNode<ShortestPath>(node);
1620
}
1721

1822
folly::Future<Status> execute() override;
1923

20-
size_t checkInput(std::unordered_set<Value>& startVids, std::unordered_set<Value>& endVids);
24+
size_t checkInput(HashSet& startVids, HashSet& endVids);
2125

2226
private:
2327
const ShortestPath* pathNode_{nullptr};

src/graph/executor/algo/SingleShortestPath.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ using nebula::storage::StorageClient;
1010

1111
namespace nebula {
1212
namespace graph {
13-
folly::Future<Status> SingleShortestPath::execute(const std::unordered_set<Value>& startVids,
14-
const std::unordered_set<Value>& endVids,
13+
folly::Future<Status> SingleShortestPath::execute(const HashSet& startVids,
14+
const HashSet& endVids,
1515
DataSet* result) {
1616
size_t rowSize = startVids.size() * endVids.size();
1717
init(startVids, endVids, rowSize);
@@ -35,9 +35,7 @@ folly::Future<Status> SingleShortestPath::execute(const std::unordered_set<Value
3535
});
3636
}
3737

38-
void SingleShortestPath::init(const std::unordered_set<Value>& startVids,
39-
const std::unordered_set<Value>& endVids,
40-
size_t rowSize) {
38+
void SingleShortestPath::init(const HashSet& startVids, const HashSet& endVids, size_t rowSize) {
4139
leftVids_.reserve(rowSize);
4240
rightVids_.reserve(rowSize);
4341

@@ -139,7 +137,7 @@ Status SingleShortestPath::doBuildPath(size_t rowNum, GetNeighborsIter* iter, bo
139137
allSteps.emplace_back();
140138
auto& currentStep = allSteps.back();
141139

142-
std::unordered_set<Value> uniqueDst;
140+
HashSet uniqueDst;
143141
uniqueDst.reserve(iterSize);
144142
std::vector<Row> nextStepVids;
145143
nextStepVids.reserve(iterSize);

src/graph/executor/algo/SingleShortestPath.h

+6-7
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,20 @@ namespace nebula {
1111
namespace graph {
1212
class SingleShortestPath final : public ShortestPathBase {
1313
public:
14+
using HashSet = robin_hood::unordered_flat_set<Value, std::hash<Value>>;
1415
SingleShortestPath(const ShortestPath* node,
1516
QueryContext* qctx,
1617
std::unordered_map<std::string, std::string>* stats)
1718
: ShortestPathBase(node, qctx, stats) {}
1819

19-
folly::Future<Status> execute(const std::unordered_set<Value>& startVids,
20-
const std::unordered_set<Value>& endVids,
20+
folly::Future<Status> execute(const HashSet& startVids,
21+
const HashSet& endVids,
2122
DataSet* result) override;
2223

2324
using HalfPath = std::vector<std::unordered_map<DstVid, std::vector<CustomStep>>>;
2425

2526
private:
26-
void init(const std::unordered_set<Value>& startVids,
27-
const std::unordered_set<Value>& endVids,
28-
size_t rowSize);
27+
void init(const HashSet& startVids, const HashSet& endVids, size_t rowSize);
2928

3029
folly::Future<Status> shortestPath(size_t rowNum, size_t stepNum);
3130

@@ -48,8 +47,8 @@ class SingleShortestPath final : public ShortestPathBase {
4847
std::vector<Row> createLeftPath(size_t rowNum, const Value& meetVid);
4948

5049
private:
51-
std::vector<std::unordered_set<Value>> leftVisitedVids_;
52-
std::vector<std::unordered_set<Value>> rightVisitedVids_;
50+
std::vector<HashSet> leftVisitedVids_;
51+
std::vector<HashSet> rightVisitedVids_;
5352
std::vector<HalfPath> allLeftPaths_;
5453
std::vector<HalfPath> allRightPaths_;
5554
};

src/graph/executor/query/MinusExecutor.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "graph/executor/query/MinusExecutor.h"
66

7+
#include <robin_hood.h>
8+
79
#include "graph/planner/plan/Query.h"
810

911
namespace nebula {
@@ -17,7 +19,7 @@ folly::Future<Status> MinusExecutor::execute() {
1719
auto left = getLeftInputData();
1820
auto right = getRightInputData();
1921

20-
std::unordered_set<const Row*> hashSet;
22+
robin_hood::unordered_flat_set<const Row*, std::hash<const Row*>> hashSet;
2123
hashSet.reserve(right.iterRef()->size());
2224
for (; right.iterRef()->valid(); right.iterRef()->next()) {
2325
hashSet.insert(right.iterRef()->row());

0 commit comments

Comments
 (0)