Add core graph member functions
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -23,4 +23,7 @@ x86/
|
|||||||
|
|
||||||
*.vcxproj
|
*.vcxproj
|
||||||
*.vcxproj.user
|
*.vcxproj.user
|
||||||
*.vcxproj.filters
|
*.vcxproj.filters
|
||||||
|
|
||||||
|
*.pdf
|
||||||
|
*.pptx
|
||||||
Binary file not shown.
@@ -1,11 +1,9 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 16
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 16.0.32407.337
|
VisualStudioVersion = 17.1.32421.90
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "decremental-maintenance-scc", "decremental-maintenance-scc\decremental-maintenance-scc.vcxproj", "{15B26719-56E0-412A-9CDB-B74D7B23E1BA}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dynamic-reachability-algorithms", "dynamic-reachability-algorithms.vcxproj", "{1CB6022E-575B-4DA3-9AB6-0EE7090A56C8}"
|
||||||
EndProject
|
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "decremental-maintenance-tc", "decremental-maintenance-tc\decremental-maintenance-tc.vcxproj", "{B26C07ED-1749-4C40-A9F2-F9486B133F2F}"
|
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -15,27 +13,19 @@ Global
|
|||||||
Release|x86 = Release|x86
|
Release|x86 = Release|x86
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{15B26719-56E0-412A-9CDB-B74D7B23E1BA}.Debug|x64.ActiveCfg = Debug|x64
|
{1CB6022E-575B-4DA3-9AB6-0EE7090A56C8}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
{15B26719-56E0-412A-9CDB-B74D7B23E1BA}.Debug|x64.Build.0 = Debug|x64
|
{1CB6022E-575B-4DA3-9AB6-0EE7090A56C8}.Debug|x64.Build.0 = Debug|x64
|
||||||
{15B26719-56E0-412A-9CDB-B74D7B23E1BA}.Debug|x86.ActiveCfg = Debug|Win32
|
{1CB6022E-575B-4DA3-9AB6-0EE7090A56C8}.Debug|x86.ActiveCfg = Debug|Win32
|
||||||
{15B26719-56E0-412A-9CDB-B74D7B23E1BA}.Debug|x86.Build.0 = Debug|Win32
|
{1CB6022E-575B-4DA3-9AB6-0EE7090A56C8}.Debug|x86.Build.0 = Debug|Win32
|
||||||
{15B26719-56E0-412A-9CDB-B74D7B23E1BA}.Release|x64.ActiveCfg = Release|x64
|
{1CB6022E-575B-4DA3-9AB6-0EE7090A56C8}.Release|x64.ActiveCfg = Release|x64
|
||||||
{15B26719-56E0-412A-9CDB-B74D7B23E1BA}.Release|x64.Build.0 = Release|x64
|
{1CB6022E-575B-4DA3-9AB6-0EE7090A56C8}.Release|x64.Build.0 = Release|x64
|
||||||
{15B26719-56E0-412A-9CDB-B74D7B23E1BA}.Release|x86.ActiveCfg = Release|Win32
|
{1CB6022E-575B-4DA3-9AB6-0EE7090A56C8}.Release|x86.ActiveCfg = Release|Win32
|
||||||
{15B26719-56E0-412A-9CDB-B74D7B23E1BA}.Release|x86.Build.0 = Release|Win32
|
{1CB6022E-575B-4DA3-9AB6-0EE7090A56C8}.Release|x86.Build.0 = Release|Win32
|
||||||
{B26C07ED-1749-4C40-A9F2-F9486B133F2F}.Debug|x64.ActiveCfg = Debug|x64
|
|
||||||
{B26C07ED-1749-4C40-A9F2-F9486B133F2F}.Debug|x64.Build.0 = Debug|x64
|
|
||||||
{B26C07ED-1749-4C40-A9F2-F9486B133F2F}.Debug|x86.ActiveCfg = Debug|Win32
|
|
||||||
{B26C07ED-1749-4C40-A9F2-F9486B133F2F}.Debug|x86.Build.0 = Debug|Win32
|
|
||||||
{B26C07ED-1749-4C40-A9F2-F9486B133F2F}.Release|x64.ActiveCfg = Release|x64
|
|
||||||
{B26C07ED-1749-4C40-A9F2-F9486B133F2F}.Release|x64.Build.0 = Release|x64
|
|
||||||
{B26C07ED-1749-4C40-A9F2-F9486B133F2F}.Release|x86.ActiveCfg = Release|Win32
|
|
||||||
{B26C07ED-1749-4C40-A9F2-F9486B133F2F}.Release|x86.Build.0 = Release|Win32
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {5ED86738-305B-4CD2-87F5-86F3C18A1DBB}
|
SolutionGuid = {940035A3-C111-4769-BB27-9285F4CDDA52}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
61
include/graph.h
Normal file
61
include/graph.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#ifndef GRAPH_H_
|
||||||
|
#define GRAPH_H_
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
#include <vector>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
namespace graph {
|
||||||
|
|
||||||
|
template<typename V>
|
||||||
|
class Graph {
|
||||||
|
public:
|
||||||
|
Graph() = default;
|
||||||
|
|
||||||
|
// Add vertex v
|
||||||
|
void insert(const V& v);
|
||||||
|
|
||||||
|
// Add edge between v and u
|
||||||
|
void insert(const V& v, const V& u);
|
||||||
|
|
||||||
|
// Delete vertex v
|
||||||
|
void erase(const V& v);
|
||||||
|
|
||||||
|
// Delete edge between v and u
|
||||||
|
void erase(const V& v, const V& u);
|
||||||
|
|
||||||
|
// Return true if v and u are connected
|
||||||
|
bool connected(const V& v, const V& u);
|
||||||
|
private:
|
||||||
|
std::map<V, std::set<V>> adjacency;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename V>
|
||||||
|
inline void Graph<V>::insert(const V& v) {
|
||||||
|
adjacency[v];
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename V>
|
||||||
|
inline void Graph<V>::insert(const V& v, const V& u) {
|
||||||
|
adjacency[v].insert(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename V>
|
||||||
|
inline void Graph<V>::erase(const V& v) {
|
||||||
|
adjacency.erase(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename V>
|
||||||
|
inline void Graph<V>::erase(const V& v, const V& u) {
|
||||||
|
adjacency[v].erase(u);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename V>
|
||||||
|
inline bool Graph<V>::connected(const V& v, const V& u) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace graph
|
||||||
|
|
||||||
|
#endif
|
||||||
26
test/graph_test.cc
Normal file
26
test/graph_test.cc
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include <doctest/doctest.h>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include "include/graph.h"
|
||||||
|
|
||||||
|
TEST_SUITE("Testing Graph.") {
|
||||||
|
using namespace graph;
|
||||||
|
|
||||||
|
TEST_CASE("Insert vertices/edges.") {
|
||||||
|
Graph<std::uint16_t> G;
|
||||||
|
|
||||||
|
G.insert(1, 2);
|
||||||
|
G.insert(1, 4);
|
||||||
|
G.insert(1, 6);
|
||||||
|
G.insert(2, 4);
|
||||||
|
G.insert(2, 5);
|
||||||
|
G.insert(3, 4);
|
||||||
|
G.insert(3, 6);
|
||||||
|
G.insert(4, 6);
|
||||||
|
G.insert(5, 6);
|
||||||
|
|
||||||
|
// CHECK_EQ(G.connected(1, 5), true);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
2
test/main.cc
Normal file
2
test/main.cc
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||||
|
#include <doctest/doctest.h>
|
||||||
Reference in New Issue
Block a user