-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNode.cpp
More file actions
33 lines (24 loc) · 681 Bytes
/
Node.cpp
File metadata and controls
33 lines (24 loc) · 681 Bytes
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
//
// Created by Arthur on 4/9/21.
//
#include "Node.hpp"
namespace solution {
Node::Node(uint64_t start) : start(start) {}
std::shared_ptr<Node> Node::AddNode(wchar_t symbol, uint64_t starts) {
// if exists return already existing
if (next.find(symbol) != next.end()) {
return next.find(symbol)->second;
}
// else create new Node
std::shared_ptr<Node> new_node(std::make_shared<Node>(starts));
next[symbol] = new_node;
new_node->current = symbol;
return new_node;
}
std::shared_ptr<Node> Node::Find(wchar_t symbol) {
if (next.find(symbol) == next.end()) {
return nullptr;
}
return next.find(symbol)->second;
}
}