This repository has been archived by the owner on Apr 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph-list.h
157 lines (130 loc) · 3.46 KB
/
graph-list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#pragma once
#include <iostream>
#include <fstream>
#include <vector>
// #include <map>
// #include "graph.h"
// #include "hash-map.cpp"
using namespace std;
// struct LinkedEdgeList {
// };
template<typename K>
struct Edge
{
K object;
int weight;
};
// int main() {
// Edge<string> e;
// e.object = "hi";
// e.weight = 1;
// e.object = "he";
// cout << e.object << endl;
// return 0;
// }
// Should try and keep a record of the number of
// subjects and objects first that way we can
// initialise the array
// template<typename _NodeKind>
// struct Graph
// {
// // Technically should handle case of tring to add a different
// // weight to the same object but I don't think that is necessary
// // here
// void addEdge(_NodeKind subject, _NodeKind object, int weight)
// {
// int s = this->nameToId(subject);
// Edge<int> edge;
// edge.object = this->nameToId(object);
// edge.weight = weight;
// if (graph.hasKey(s))
// {
// graph.get(s).push_back(edge)
// }
// else
// {
// graph.add(s, {edge})
// };
// edgeCount++;
// };
// void removeEdge(string subject, string object)
// {
// int s = this->nameToId(subject);
// int o = this->nameToId(subject);
// if (graph.hasKey(s))
// {
// vector<Edge<int>> *edges = graph.get(s);
// vector<Edge<int>> edgesCopy = edges;
// edges->clear();
// for (Edge<int> edge : edgesCopy)
// {
// if (edge.object != o)
// {
// edges->push_back(edge);
// }
// else
// {
// edgeCount--;
// }
// };
// // If node is now isolated we can
// // remove it from the linked list
// if (edges->size() == 0)
// {
// graph.remove(s);
// };
// };
// };
// int edgeCount()
// {
// return edgeCount;
// };
// int nodeCount()
// {
// return named.size();
// };
// int getEdges
// // graph.get(nameToId(subject)).push_back()
// // graph.add(nameToId(subject), {
// // object : nameToId(object);
// // weight : weight;
// // })
// private:
// // Important assumption is that we only
// // ever want to to queries starting
// // at the 's'.
// Map<int, vector<Edge<int>>> graph = {};
// Map<_NodeKind, int> named = {};
// int edgeCount = 0;
// // graph.
// // need to map subject to tuple with
// // [predicate, object][]
// // Converts beteen name of entry
// // and row/col of matrix
// // vector<array<string | vector<int>, 2>> named = {};
// int nameToId(string name)
// {
// int i = 0;
// // TODO: CHECK/FIX
// while (i++ < named.size())
// {
// if (name == named[i])
// {
// return i;
// };
// }
// // Name does not yet exist on matrix
// named.push_back(name);
// return i;
// };
// // Implemented like this so it is easier to update
// string idToName(int id)
// {
// return named[id];
// };
// };
// int t() {
// // Graph<string> myGraph;
// // graph.addEdge("hello", "goodbye", 3)
// return 0;
// };