Skip to content

Commit

Permalink
cpp: Use better hash map implementation in whole talipot codebase
Browse files Browse the repository at this point in the history
Replace use of std::unordered_map by gtl::flat_hash_map and gtl::node_hash_map
as the implementation is better in terms of performance and memory usage.

gtl is the same library as parallel_hashmap but supports only C++20 and future
development will happen there.
  • Loading branch information
anlambert committed Dec 12, 2024
1 parent bc4a5f2 commit ee272f8
Show file tree
Hide file tree
Showing 155 changed files with 14,437 additions and 14,509 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ SET(VPSCInclude ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/)
SET(VPSCLibrary vpsc)

SET(StbInclude ${PROJECT_SOURCE_DIR}/thirdparty/stb)
SET(ParallelHashmapInclude ${PROJECT_SOURCE_DIR}/thirdparty/)
SET(GtlInclude ${PROJECT_SOURCE_DIR}/thirdparty/)

SET(TalipotCoreInclude ${PROJECT_SOURCE_DIR}/library/talipot-core/include/)
SET(TalipotCoreBuildInclude ${PROJECT_BINARY_DIR}/library/talipot-core/include/)
Expand Down Expand Up @@ -514,7 +514,7 @@ ADD_CUSTOM_TARGET(

ADD_SUBDIRECTORY(thirdparty)

INCLUDE_DIRECTORIES(${ParallelHashmapInclude})
INCLUDE_DIRECTORIES(${GtlInclude})
ADD_SUBDIRECTORY(library)
ADD_SUBDIRECTORY(plugins)
ADD_SUBDIRECTORY(utils/crash_handler)
Expand Down
11 changes: 10 additions & 1 deletion cmake/TalipotUseFile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ MACRO(TALIPOT_SET_COMPILER_OPTIONS_AND_DEFINITIONS)
STRING(FIND "${CMAKE_CXX_COMPILER_ID}" "Clang" CLANG_POS)
STRING(COMPARE NOTEQUAL "${CLANG_POS}" "-1" CLANG)

# Enable C++17 standard
# Enable C++20 standard
SET(CMAKE_CXX_STANDARD 20)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_EXTENSIONS OFF)
Expand All @@ -142,6 +142,15 @@ MACRO(TALIPOT_SET_COMPILER_OPTIONS_AND_DEFINITIONS)
TALIPOT_SET_CXX_FLAGS(
"-Wall -Wextra -Wunused -Wno-long-long -Wold-style-cast")

IF(CMAKE_COMPILER_IS_GNUCXX
AND NOT CLANG
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0.0)
TALIPOT_SET_CXX_FLAGS("-Wno-interference-size")
ENDIF(
CMAKE_COMPILER_IS_GNUCXX
AND NOT CLANG
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0.0)

IF(NOT APPLE)
TALIPOT_SET_CXX_FLAGS("-pedantic")
ENDIF(NOT APPLE)
Expand Down
1 change: 1 addition & 0 deletions library/talipot-core/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ INSTALL(
talipot/MaterialDesignIconsConstants.h
talipot/IndexElement.h
talipot/PropertyProxy.h
talipot/hash.h
DESTINATION ${TalipotIncludeInstallDir}/talipot/)

INSTALL(
Expand Down
6 changes: 3 additions & 3 deletions library/talipot-core/include/talipot/ConnectedTestListener.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2019-2020 The Talipot developers
* Copyright (C) 2019-2024 The Talipot developers
*
* Talipot is a fork of Tulip, created by David Auber
* and the Tulip development Team from LaBRI, University of Bordeaux
Expand All @@ -14,7 +14,7 @@
#ifndef TALIPOT_CONNECTED_TEST_LISTENER_H
#define TALIPOT_CONNECTED_TEST_LISTENER_H

#include <unordered_map>
#include <talipot/hash.h>

#include <talipot/Graph.h>
#include <talipot/Observable.h>
Expand All @@ -29,7 +29,7 @@ class ConnectedTestListener : public Observable {
/**
* @brief Stored results for graphs. When a graph is updated, its entry is removed from the map.
**/
std::unordered_map<const Graph *, bool> resultsBuffer;
flat_hash_map<const Graph *, bool> resultsBuffer;
};

}
Expand Down
8 changes: 4 additions & 4 deletions library/talipot-core/include/talipot/DataSet.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2019-2021 The Talipot developers
* Copyright (C) 2019-2024 The Talipot developers
*
* Talipot is a fork of Tulip, created by David Auber
* and the Tulip development Team from LaBRI, University of Bordeaux
Expand All @@ -21,7 +21,7 @@
#include <string>
#include <sstream>
#include <typeinfo>
#include <unordered_map>
#include <talipot/hash.h>

namespace tlp {

Expand Down Expand Up @@ -161,8 +161,8 @@ class DataTypeSerializerContainer {
}
}

std::unordered_map<std::string, DataTypeSerializer *> tnTodts;
std::unordered_map<std::string, DataTypeSerializer *> otnTodts;
flat_hash_map<std::string, DataTypeSerializer *> tnTodts;
flat_hash_map<std::string, DataTypeSerializer *> otnTodts;
};

/**
Expand Down
10 changes: 5 additions & 5 deletions library/talipot-core/include/talipot/Delaunay.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2019-2021 The Talipot developers
* Copyright (C) 2019-2024 The Talipot developers
*
* Talipot is a fork of Tulip, created by David Auber
* and the Tulip development Team from LaBRI, University of Bordeaux
Expand All @@ -16,7 +16,7 @@

#include <vector>
#include <set>
#include <unordered_map>
#include <talipot/hash.h>

#include <talipot/Coord.h>

Expand Down Expand Up @@ -118,9 +118,9 @@ class TLP_SCOPE VoronoiDiagram {
std::vector<Vertex> vertices;
std::vector<Edge> edges;
std::vector<Cell> cells;
std::unordered_map<uint, std::vector<uint>> siteToCellEdges;
std::unordered_map<uint, uint> siteToCell;
std::unordered_map<uint, uint> verticesDegree;
node_hash_map<uint, std::vector<uint>> siteToCellEdges;
node_hash_map<uint, uint> siteToCell;
node_hash_map<uint, uint> verticesDegree;
};

/**
Expand Down
6 changes: 3 additions & 3 deletions library/talipot-core/include/talipot/Dijkstra.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2019-2022 The Talipot developers
* Copyright (C) 2019-2024 The Talipot developers
*
* Talipot is a fork of Tulip, created by David Auber
* and the Tulip development Team from LaBRI, University of Bordeaux
Expand All @@ -17,7 +17,7 @@
#include <vector>
#include <stack>
#include <list>
#include <unordered_map>
#include <talipot/hash.h>
#include <climits>
#include <functional>
#include <talipot/Graph.h>
Expand All @@ -39,7 +39,7 @@ class Dijkstra {
//=========================================================
bool searchPath(node n, BooleanProperty *result);
//=============================================================
bool ancestors(std::unordered_map<node, std::list<node>> &result);
bool ancestors(flat_hash_map<node, std::list<node>> &result);

private:
void internalSearchPaths(node n, BooleanProperty *result);
Expand Down
6 changes: 3 additions & 3 deletions library/talipot-core/include/talipot/Graph.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2019-2023 The Talipot developers
* Copyright (C) 2019-2024 The Talipot developers
*
* Talipot is a fork of Tulip, created by David Auber
* and the Tulip development Team from LaBRI, University of Bordeaux
Expand All @@ -19,7 +19,7 @@
#include <set>
#include <string>
#include <vector>
#include <unordered_map>
#include <talipot/hash.h>

#include <climits>
#include <talipot/config.h>
Expand Down Expand Up @@ -2087,7 +2087,7 @@ class TLP_SCOPE Graph : public Observable {
}

uint id;
std::unordered_map<std::string, tlp::PropertyInterface *> circularCalls;
flat_hash_map<std::string, tlp::PropertyInterface *> circularCalls;
};

enum class GraphEventType {
Expand Down
4 changes: 2 additions & 2 deletions library/talipot-core/include/talipot/GraphProperty.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2019-2021 The Talipot developers
* Copyright (C) 2019-2024 The Talipot developers
*
* Talipot is a fork of Tulip, created by David Auber
* and the Tulip development Team from LaBRI, University of Bordeaux
Expand Down Expand Up @@ -80,7 +80,7 @@ class TLP_SCOPE GraphProperty : public AbstractGraphProperty {
}

private:
std::unordered_map<Graph *, std::set<node>> referencedGraph;
flat_hash_map<Graph *, std::set<node>> referencedGraph;
const std::set<edge> &getReferencedEdges(const edge) const;
};
}
Expand Down
6 changes: 3 additions & 3 deletions library/talipot-core/include/talipot/GraphTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
#include <talipot/hash.h>
#include <talipot/config.h>
#include <talipot/Node.h>
#include <talipot/Edge.h>
Expand Down Expand Up @@ -82,7 +82,7 @@ TLP_SCOPE node graphCenterHeuristic(Graph *graph, PluginProgress *pluginProgress
TLP_SCOPE node makeSimpleSource(Graph *graph);

TLP_SCOPE void makeProperDag(Graph *graph, std::list<node> &addedNodes,
std::unordered_map<edge, edge> &replacedEdges,
flat_hash_map<edge, edge> &replacedEdges,
IntegerProperty *edgeLength = nullptr);

/**
Expand Down Expand Up @@ -265,7 +265,7 @@ TLP_SCOPE std::set<node> reachableNodes(const Graph *graph, const node startNode
TLP_SCOPE void computeDijkstra(const Graph *const graph, node src,
const EdgeVectorProperty<double> &weights,
NodeVectorProperty<double> &nodeDistance, EdgeType direction,
std::unordered_map<node, std::list<node>> &ancestors,
flat_hash_map<node, std::list<node>> &ancestors,
std::stack<node> *queueNodes = nullptr,
MutableContainer<int> *numberOfPaths = nullptr);
}
Expand Down
56 changes: 28 additions & 28 deletions library/talipot-core/include/talipot/GraphUpdatesRecorder.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2019-2021 The Talipot developers
* Copyright (C) 2019-2024 The Talipot developers
*
* Talipot is a fork of Tulip, created by David Auber
* and the Tulip development Team from LaBRI, University of Bordeaux
Expand All @@ -16,7 +16,7 @@

#include <string>
#include <set>
#include <unordered_map>
#include <talipot/hash.h>
#include <unordered_set>
#include <vector>

Expand Down Expand Up @@ -51,29 +51,29 @@ class GraphUpdatesRecorder : public Observable {
const bool oldIdsStateRecorded;

// one 'set' of added nodes per graph
std::unordered_map<Graph *, std::unordered_set<node>> graphAddedNodes;
flat_hash_map<Graph *, std::unordered_set<node>> graphAddedNodes;
// the whole 'set' of added nodes
std::unordered_set<node> addedNodes;
// one 'set' of deleted nodes per graph
std::unordered_map<Graph *, std::unordered_set<node>> graphDeletedNodes;
flat_hash_map<Graph *, std::unordered_set<node>> graphDeletedNodes;
// one 'set' of added edges per graph
std::map<Graph *, std::unordered_set<edge>> graphAddedEdges;
// ends of all added edges
std::unordered_map<edge, std::pair<node, node>> addedEdgesEnds;
flat_hash_map<edge, std::pair<node, node>> addedEdgesEnds;
// one 'set' of deleted edges per graph
std::map<Graph *, std::unordered_set<edge>> graphDeletedEdges;
// ends of all deleted edges
std::unordered_map<edge, std::pair<node, node>> deletedEdgesEnds;
flat_hash_map<edge, std::pair<node, node>> deletedEdgesEnds;
// one set of reverted edges
std::unordered_set<edge> revertedEdges;
// source + target per updated edge
std::unordered_map<edge, std::pair<node, node>> oldEdgesEnds;
flat_hash_map<edge, std::pair<node, node>> oldEdgesEnds;
// source + target per updated edge
std::unordered_map<edge, std::pair<node, node>> newEdgesEnds;
flat_hash_map<edge, std::pair<node, node>> newEdgesEnds;
// one 'set' for old incidences
std::unordered_map<node, std::vector<edge>> oldIncidences;
flat_hash_map<node, std::vector<edge>> oldIncidences;
// one 'set' for new incidences
std::unordered_map<node, std::vector<edge>> newIncidences;
flat_hash_map<node, std::vector<edge>> newIncidences;

// copy of nodes/edges id manager state at start time
const GraphStorageIdsMemento *oldIdsState;
Expand All @@ -86,30 +86,30 @@ class GraphUpdatesRecorder : public Observable {
std::list<std::pair<Graph *, Graph *>> deletedSubGraphs;

// one set of added properties per graph
std::unordered_map<Graph *, std::set<PropertyInterface *>> addedProperties;
flat_hash_map<Graph *, std::set<PropertyInterface *>> addedProperties;
// one set of deleted properties per graph
std::unordered_map<Graph *, std::set<PropertyInterface *>> deletedProperties;
flat_hash_map<Graph *, std::set<PropertyInterface *>> deletedProperties;
// one set of old attribute values per graph
std::unordered_map<Graph *, DataSet> oldAttributeValues;
flat_hash_map<Graph *, DataSet> oldAttributeValues;
// one set of new attribute values per graph
std::unordered_map<Graph *, DataSet> newAttributeValues;
flat_hash_map<Graph *, DataSet> newAttributeValues;

// one set of updated addNodes per property
std::unordered_map<PropertyInterface *, std::set<node>> updatedPropsAddedNodes;
flat_hash_map<PropertyInterface *, std::set<node>> updatedPropsAddedNodes;

// one set of updated addEdges per property
std::unordered_map<PropertyInterface *, std::set<edge>> updatedPropsAddedEdges;
flat_hash_map<PropertyInterface *, std::set<edge>> updatedPropsAddedEdges;

// the old default node value for each updated property
std::unordered_map<PropertyInterface *, DataMem *> oldNodeDefaultValues;
flat_hash_map<PropertyInterface *, DataMem *> oldNodeDefaultValues;
// the new default node value for each updated property
std::unordered_map<PropertyInterface *, DataMem *> newNodeDefaultValues;
flat_hash_map<PropertyInterface *, DataMem *> newNodeDefaultValues;
// the old default edge value for each updated property
std::unordered_map<PropertyInterface *, DataMem *> oldEdgeDefaultValues;
flat_hash_map<PropertyInterface *, DataMem *> oldEdgeDefaultValues;
// the new default edge value for each updated property
std::unordered_map<PropertyInterface *, DataMem *> newEdgeDefaultValues;
flat_hash_map<PropertyInterface *, DataMem *> newEdgeDefaultValues;
// the old name for each renamed property
std::unordered_map<PropertyInterface *, std::string> renamedProperties;
flat_hash_map<PropertyInterface *, std::string> renamedProperties;

struct RecordedValues {
PropertyInterface *values;
Expand All @@ -122,25 +122,25 @@ class GraphUpdatesRecorder : public Observable {
};

// the old nodes/edges values for each updated property
std::unordered_map<PropertyInterface *, RecordedValues> oldValues;
flat_hash_map<PropertyInterface *, RecordedValues> oldValues;
// the new node value for each updated property
std::unordered_map<PropertyInterface *, RecordedValues> newValues;
flat_hash_map<PropertyInterface *, RecordedValues> newValues;

// real deletion of deleted objects (properties, sub graphs)
// during the recording of updates these objects are removed from graph
// structures but not really 'deleted'
void deleteDeletedObjects();
// deletion of recorded values
void deleteValues(std::unordered_map<PropertyInterface *, RecordedValues> &values);
void deleteValues(flat_hash_map<PropertyInterface *, RecordedValues> &values);
// deletion of DataMem default values
void deleteDefaultValues(std::unordered_map<PropertyInterface *, DataMem *> &values);
void deleteDefaultValues(flat_hash_map<PropertyInterface *, DataMem *> &values);
// record of a node's edges container before/after modification
void recordIncidence(std::unordered_map<node, std::vector<edge>> &, GraphImpl *, node,
void recordIncidence(flat_hash_map<node, std::vector<edge>> &, GraphImpl *, node,
edge e = edge());
void recordIncidence(std::unordered_map<node, std::vector<edge>> &, GraphImpl *, node,
void recordIncidence(flat_hash_map<node, std::vector<edge>> &, GraphImpl *, node,
const std::vector<edge> &, uint);
// remove an edge from a node's edges container
void removeFromIncidence(std::unordered_map<node, std::vector<edge>> &, edge, node);
void removeFromIncidence(flat_hash_map<node, std::vector<edge>> &, edge, node);

void removeGraphData(Graph *);

Expand Down
6 changes: 3 additions & 3 deletions library/talipot-core/include/talipot/IdManager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright (C) 2019-2023 The Talipot developers
* Copyright (C) 2019-2024 The Talipot developers
*
* Talipot is a fork of Tulip, created by David Auber
* and the Tulip development Team from LaBRI, University of Bordeaux
Expand All @@ -25,7 +25,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
#include <parallel_hashmap/phmap.h>
#include <talipot/hash.h>
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
Expand Down Expand Up @@ -260,7 +260,7 @@ class TLP_SCOPE IdContainer : public std::vector<ID_TYPE> {
template <typename ID_TYPE>
class SGraphIdContainer : public std::vector<ID_TYPE> {
// used to store the elts positions in the vector
phmap::flat_hash_map<ID_TYPE, uint> pos;
flat_hash_map<ID_TYPE, uint> pos;

public:
SGraphIdContainer() = default;
Expand Down
Loading

0 comments on commit ee272f8

Please sign in to comment.