- Fixed some variable naming with graph and it's PrettyPrinter
- Added boost-atomic and boost-thread as dependencies for concurrency support
This commit is contained in:
@@ -1,22 +0,0 @@
|
||||
// =====================================================================================================================
|
||||
// fennec, a free and open source game engine
|
||||
// Copyright © 2025 Medusa Slockbower
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
#ifndef FENNEC_CONCURRENCY_ATOMIC_H
|
||||
#define FENNEC_CONCURRENCY_ATOMIC_H
|
||||
|
||||
#endif // FENNEC_CONCURRENCY_ATOMIC_H
|
||||
@@ -1,22 +0,0 @@
|
||||
// =====================================================================================================================
|
||||
// fennec, a free and open source game engine
|
||||
// Copyright © 2025 Medusa Slockbower
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
#ifndef FENNEC_CONCURRENCY_MUTEX_H
|
||||
#define FENNEC_CONCURRENCY_MUTEX_H
|
||||
|
||||
#endif // FENNEC_CONCURRENCY_MUTEX_H
|
||||
@@ -1,22 +0,0 @@
|
||||
// =====================================================================================================================
|
||||
// fennec, a free and open source game engine
|
||||
// Copyright © 2025 Medusa Slockbower
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
// =====================================================================================================================
|
||||
|
||||
#ifndef FENNEC_CONCURRENCY_THREAD_H
|
||||
#define FENNEC_CONCURRENCY_THREAD_H
|
||||
|
||||
#endif // FENNEC_CONCURRENCY_THREAD_H
|
||||
@@ -149,7 +149,7 @@ public:
|
||||
///
|
||||
/// \returns The number of edges in the graph
|
||||
constexpr size_t num_edges() const {
|
||||
return _conn_pool.size();
|
||||
return _edge_pool.size();
|
||||
}
|
||||
|
||||
///
|
||||
@@ -170,7 +170,7 @@ public:
|
||||
/// \param b The second vertex
|
||||
/// \returns `true` if the edge exists, `false` otherwise
|
||||
constexpr bool exists(size_t a, size_t b) const {
|
||||
return _conn_map[a][b] != nullptr;
|
||||
return _edge_map[a][b] != nullptr;
|
||||
}
|
||||
|
||||
///
|
||||
@@ -189,8 +189,8 @@ public:
|
||||
/// \param b The second vertex
|
||||
/// \returns `true` if both edges exist, `false` otherwise
|
||||
constexpr bool is_undirected(size_t a, size_t b) const {
|
||||
const auto* e0 = _conn_map[a][b];
|
||||
const auto* e1 = _conn_map[b][a];
|
||||
const auto* e0 = _edge_map[a][b];
|
||||
const auto* e1 = _edge_map[b][a];
|
||||
if (not (e0 != nullptr && e1 != nullptr)) {
|
||||
return false;
|
||||
}
|
||||
@@ -232,9 +232,9 @@ public:
|
||||
if (empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
edge_t* it = _conn_map[a][b];
|
||||
edge_t* it = _edge_map[a][b];
|
||||
if (it) {
|
||||
return _conn_pool[*it];
|
||||
return _edge_pool[*it];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -248,9 +248,9 @@ public:
|
||||
if (empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
const edge_t* it = _conn_map[a][b];
|
||||
const edge_t* it = _edge_map[a][b];
|
||||
if (it) {
|
||||
return _conn_pool[*it];
|
||||
return _edge_pool[*it];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -261,10 +261,10 @@ public:
|
||||
/// \returns A list containing all vertices `x` with edges from `vertex` to `x...`
|
||||
list<size_t> outgoing(size_t vertex) {
|
||||
list<size_t> res;
|
||||
if (empty() || vertex >= _conn_map.size()) {
|
||||
if (empty() || vertex >= _edge_map.size()) {
|
||||
return res;
|
||||
}
|
||||
for (const auto& it : _conn_map[vertex]) {
|
||||
for (const auto& it : _edge_map[vertex]) {
|
||||
res.push_back(it.first);
|
||||
}
|
||||
return res;
|
||||
@@ -276,11 +276,11 @@ public:
|
||||
/// \returns A list containing all vertices `x` with edges from `x...` to `vertex`
|
||||
list<size_t> incoming(size_t vertex) {
|
||||
list<size_t> res;
|
||||
if (empty() || vertex >= _conn_map.size()) {
|
||||
if (empty() || vertex >= _edge_map.size()) {
|
||||
return res;
|
||||
}
|
||||
for (size_t n = 0; n < _conn_map.size(); ++n) {
|
||||
if (_conn_map[n][vertex]) {
|
||||
for (size_t n = 0; n < _edge_map.size(); ++n) {
|
||||
if (_edge_map[n][vertex]) {
|
||||
res.push_back(n);
|
||||
}
|
||||
}
|
||||
@@ -293,11 +293,11 @@ public:
|
||||
/// \returns A list containing all vertices `x` that have symmetric edges with `vertex`
|
||||
list<size_t> symmetric(size_t vertex) {
|
||||
list<size_t> res;
|
||||
if (empty() || vertex >= _conn_map.size()) {
|
||||
if (empty() || vertex >= _edge_map.size()) {
|
||||
return res;
|
||||
}
|
||||
for (const auto& it : _conn_map[vertex]) {
|
||||
if (_conn_map[it.first][vertex]) {
|
||||
for (const auto& it : _edge_map[vertex]) {
|
||||
if (_edge_map[it.first][vertex]) {
|
||||
res.push_back(it.first);
|
||||
}
|
||||
}
|
||||
@@ -314,11 +314,11 @@ public:
|
||||
/// \returns A list containing all vertices `x` that have symmetric edges with `vertex`
|
||||
list<size_t> undirected(size_t vertex) {
|
||||
list<size_t> res;
|
||||
if (empty() || vertex >= _conn_map.size()) {
|
||||
if (empty() || vertex >= _edge_map.size()) {
|
||||
return res;
|
||||
}
|
||||
for (const auto& it : _conn_map[vertex]) {
|
||||
const auto* at = _conn_map[it.first][vertex];
|
||||
for (const auto& it : _edge_map[vertex]) {
|
||||
const auto* at = _edge_map[it.first][vertex];
|
||||
if (at != nullptr && *at == it.second) {
|
||||
res.push_back(it.first);
|
||||
}
|
||||
@@ -332,10 +332,10 @@ public:
|
||||
/// \param vertex The id of the vertex
|
||||
/// \returns A pointer to a map containing edges mapped from this vertex
|
||||
const auto* edges(size_t vertex) {
|
||||
if (empty() || vertex >= _conn_map.size()) {
|
||||
if (empty() || vertex >= _edge_map.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
return &_conn_map[vertex];
|
||||
return &_edge_map[vertex];
|
||||
}
|
||||
|
||||
/// @}
|
||||
@@ -392,19 +392,19 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
if (_conn_map.size() < _vertex_pool.capacity()) {
|
||||
_conn_map.resize(_vertex_pool.capacity());
|
||||
if (_edge_map.size() < _vertex_pool.capacity()) {
|
||||
_edge_map.resize(_vertex_pool.capacity());
|
||||
}
|
||||
|
||||
auto it = _conn_map[a][b];
|
||||
auto it = _edge_map[a][b];
|
||||
size_t conn;
|
||||
if (it != nullptr) {
|
||||
conn = *it;
|
||||
_conn_pool[conn] = vertex_t(fennec::forward<ArgsT>(args)...);
|
||||
_edge_pool[conn] = vertex_t(fennec::forward<ArgsT>(args)...);
|
||||
} else {
|
||||
conn = _conn_pool.emplace(fennec::forward<ArgsT>(args)...);
|
||||
conn = _edge_pool.emplace(fennec::forward<ArgsT>(args)...);
|
||||
}
|
||||
_conn_map[a].emplace(b, conn);
|
||||
_edge_map[a].emplace(b, conn);
|
||||
}
|
||||
|
||||
///
|
||||
@@ -419,21 +419,21 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
if (_conn_map.size() < _vertex_pool.capacity()) {
|
||||
_conn_map.resize(_vertex_pool.capacity());
|
||||
if (_edge_map.size() < _vertex_pool.capacity()) {
|
||||
_edge_map.resize(_vertex_pool.capacity());
|
||||
}
|
||||
|
||||
auto it = _conn_map[a][b];
|
||||
auto it = _edge_map[a][b];
|
||||
size_t conn;
|
||||
if (it != nullptr) {
|
||||
conn = *it;
|
||||
_conn_pool[conn] = vertex_t(fennec::forward<ArgsT>(args)...);
|
||||
_edge_pool[conn] = vertex_t(fennec::forward<ArgsT>(args)...);
|
||||
} else {
|
||||
conn = _conn_pool.emplace(fennec::forward<ArgsT>(args)...);
|
||||
conn = _edge_pool.emplace(fennec::forward<ArgsT>(args)...);
|
||||
}
|
||||
|
||||
_conn_map[a].emplace(b, conn);
|
||||
_conn_map[b].emplace(a, conn);
|
||||
_edge_map[a].emplace(b, conn);
|
||||
_edge_map[b].emplace(a, conn);
|
||||
}
|
||||
|
||||
///
|
||||
@@ -443,20 +443,20 @@ public:
|
||||
constexpr void cut_edge(size_t a, size_t b) {
|
||||
|
||||
// Find the edge object
|
||||
const auto* it = _conn_map[a][b];
|
||||
const auto* it = _edge_map[a][b];
|
||||
if (not it) {
|
||||
return;
|
||||
}
|
||||
size_t c = *it;
|
||||
|
||||
// Check if undirected
|
||||
const auto* at = _conn_map[b][a];
|
||||
const auto* at = _edge_map[b][a];
|
||||
if (not at || *at != c) {
|
||||
_conn_pool.erase(c);
|
||||
_edge_pool.erase(c);
|
||||
}
|
||||
|
||||
// Erase the edge mapping
|
||||
_conn_map[a].erase(b);
|
||||
_edge_map[a].erase(b);
|
||||
}
|
||||
|
||||
///
|
||||
@@ -464,15 +464,15 @@ public:
|
||||
/// \param a The first vertex id
|
||||
/// \param b The second vertex id
|
||||
constexpr void cut_edge2(size_t a, size_t b) {
|
||||
const auto* ita = _conn_map[a][b];
|
||||
const auto* itb = _conn_map[a][b];
|
||||
const auto* ita = _edge_map[a][b];
|
||||
const auto* itb = _edge_map[a][b];
|
||||
if (not (ita || itb)) {
|
||||
return;
|
||||
}
|
||||
if (ita) _conn_pool.erase(*ita);
|
||||
if (itb) _conn_pool.erase(*itb);
|
||||
_conn_map[a].erase(b);
|
||||
_conn_map[b].erase(a);
|
||||
if (ita) _edge_pool.erase(*ita);
|
||||
if (itb) _edge_pool.erase(*itb);
|
||||
_edge_map[a].erase(b);
|
||||
_edge_map[b].erase(a);
|
||||
}
|
||||
|
||||
///
|
||||
@@ -491,8 +491,8 @@ public:
|
||||
/// \brief Clear the graph, destructing all vertices and edges.
|
||||
void clear() {
|
||||
_vertex_pool.clear();
|
||||
_conn_pool.clear();
|
||||
_conn_map.clear();
|
||||
_edge_pool.clear();
|
||||
_edge_map.clear();
|
||||
}
|
||||
|
||||
/// @}
|
||||
@@ -503,8 +503,8 @@ public:
|
||||
|
||||
private:
|
||||
vertex_pool_t _vertex_pool;
|
||||
edge_pool_t _conn_pool;
|
||||
edge_map_t _conn_map;
|
||||
edge_pool_t _edge_pool;
|
||||
edge_map_t _edge_map;
|
||||
|
||||
template<typename...ArgsT>
|
||||
size_t _insert(ArgsT&&...args) {
|
||||
|
||||
Reference in New Issue
Block a user