-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatabase.cpp
More file actions
66 lines (56 loc) · 1.63 KB
/
Copy pathdatabase.cpp
File metadata and controls
66 lines (56 loc) · 1.63 KB
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
/**
* \file database.cpp
*
* \authors Mackenzie Kong-Sivert
*
* \brief Implements the Database class.
*/
#include "database.hpp"
using namespace std;
void Database::removeNode(Node& n)
{
//size_t key = hash_fn(n.primaryKey);
hashTable_.erase(n.primaryKey);
}
void Database::addNode(Node n)
{
//size_t key = hash_fn(n.primaryKey);
//unordered_map<std::string,Node>::iterator insertItr = hashTable_.find(n.primaryKey);
hashTable_.insert(std::make_pair(n.primaryKey,n));
}
std::list<Node> Database::getNodeWithRelationship(Node& n, std::string tag)
{
//size_t key = hash_fn(n.primaryKey);
Node thisNode = hashTable_.find(n.primaryKey)->second;
list<Node::relation_type> relList = thisNode.relationships;
for(list<Node::relation_type>::iterator listItr = relList.begin(); listItr != relList.end(); ++listItr)
{
if (listItr->tag == tag)
{
// create a list of Nodes
auto shipList = listItr->relationshipInstances;
std::list<Node> nodeList;
for ( auto i = shipList.begin(); i != shipList.end(); ++i) {
nodeList.push_back(*(i->second.other));
}
return nodeList;
}
}
// maybe find a less sketchy thing to do if what we're looking for
// is not in the list?
std::list<Node> emptyList;
return emptyList;
}
string Database::getRelationship(Node& n1, Node* n2)
{
//size_t key = hash_fn(n1.primaryKey);
Node node1 = hashTable_.find(n1.primaryKey)->second;
return node1.getRelationship(n2).other->primaryKey;
}
void Database::addType(string typeName)
{
}
Node Node::getNodeFromPrimaryKey(std::string tag) {
Node n = this.hashTable_.find(tag);
return n;
}