Skip to content

Commit

Permalink
Added allocator at important points
Browse files Browse the repository at this point in the history
  • Loading branch information
JoBuRo committed Oct 2, 2024
1 parent dcc5925 commit 54d40a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/engine/PathSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ Result PathSearch::computeResult([[maybe_unused]] bool requestLaziness) {
auto sideTime = timer.msecs();
timer.start();

std::vector<Path> paths;
PathsLimited paths{allocator()};
if (sources.empty()) {
paths = allPaths(binSearch.getSources(), targets, binSearch, config_.cartesian_);
} else {
Expand Down Expand Up @@ -313,13 +313,13 @@ PathSearch::handleSearchSides() const {
}

// _____________________________________________________________________________
std::vector<Path> PathSearch::findPaths(
PathsLimited PathSearch::findPaths(
const Id& source, const std::unordered_set<uint64_t>& targets,
const BinSearchWrapper& binSearch) const {
std::vector<Edge> edgeStack;
Path currentPath;
Path currentPath{EdgesLimited(allocator())};
std::unordered_map<uint64_t, std::vector<Path>> pathCache;
std::vector<Path> result;
PathsLimited result{allocator()};
std::unordered_set<uint64_t> visited;

visited.insert(source.getBits());
Expand Down Expand Up @@ -355,12 +355,12 @@ std::vector<Path> PathSearch::findPaths(
}

// _____________________________________________________________________________
std::vector<Path> PathSearch::allPaths(std::span<const Id> sources,
PathsLimited PathSearch::allPaths(std::span<const Id> sources,
std::span<const Id> targets,
const BinSearchWrapper& binSearch,
bool cartesian) const {
std::vector<Path> paths;
Path path;
PathsLimited paths{allocator()};
Path path{EdgesLimited(allocator())};

if (cartesian || sources.size() != targets.size()) {
std::unordered_set<uint64_t> targetSet;
Expand All @@ -386,7 +386,7 @@ std::vector<Path> PathSearch::allPaths(std::span<const Id> sources,
// _____________________________________________________________________________
template <size_t WIDTH>
void PathSearch::pathsToResultTable(IdTable& tableDyn,
std::vector<Path>& paths) const {
PathsLimited& paths) const {
IdTableStatic<WIDTH> table = std::move(tableDyn).toStatic<WIDTH>();

std::vector<size_t> edgePropertyCols;
Expand Down
13 changes: 9 additions & 4 deletions src/engine/PathSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "engine/Operation.h"
#include "global/Id.h"
#include "util/AllocatorWithLimit.h"

enum class PathSearchAlgorithm { ALL_PATHS };

Expand All @@ -30,8 +31,10 @@ struct Edge {
std::vector<Id> edgeProperties_;
};

using EdgesLimited = std::vector<Edge, ad_utility::AllocatorWithLimit<Edge>>;

struct Path {
std::vector<Edge> edges_;
EdgesLimited edges_;

bool empty() const { return edges_.empty(); }

Expand All @@ -44,6 +47,8 @@ struct Path {
const Id& end() { return edges_.back().end_; }
};

using PathsLimited = std::vector<Path, ad_utility::AllocatorWithLimit<Path>>;

/**
* @class BinSearchWrapper
* @brief Encapsulates logic for binary search of edges in
Expand Down Expand Up @@ -251,15 +256,15 @@ class PathSearch : public Operation {
* @brief Finds paths based on the configured algorithm.
* @return A vector of paths.
*/
std::vector<pathSearch::Path> findPaths(const Id& source,
pathSearch::PathsLimited findPaths(const Id& source,
const std::unordered_set<uint64_t>& targets,
const pathSearch::BinSearchWrapper& binSearch) const;

/**
* @brief Finds all paths in the graph.
* @return A vector of all paths.
*/
std::vector<pathSearch::Path> allPaths(std::span<const Id> sources,
pathSearch::PathsLimited allPaths(std::span<const Id> sources,
std::span<const Id> targets,
const pathSearch::BinSearchWrapper& binSearch, bool cartesian) const;

Expand All @@ -270,5 +275,5 @@ class PathSearch : public Operation {
* @param paths The vector of paths to convert.
*/
template <size_t WIDTH>
void pathsToResultTable(IdTable& tableDyn, std::vector<pathSearch::Path>& paths) const;
void pathsToResultTable(IdTable& tableDyn, pathSearch::PathsLimited& paths) const;
};

0 comments on commit 54d40a9

Please sign in to comment.