summaryrefslogtreecommitdiff
path: root/extractor/matchings_trie.cc
blob: 7fb7a5299a08a3341486251652fa0f54e7c12c14 (plain)
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
#include "matchings_trie.h"

namespace extractor {

MatchingsTrie::MatchingsTrie() {
  root = make_shared<TrieNode>();
}

MatchingsTrie::~MatchingsTrie() {
  DeleteTree(root);
}

shared_ptr<TrieNode> MatchingsTrie::GetRoot() const {
  return root;
}

void MatchingsTrie::DeleteTree(shared_ptr<TrieNode> root) {
  if (root != NULL) {
    for (auto child: root->children) {
      DeleteTree(child.second);
    }
    if (root->suffix_link != NULL) {
      root->suffix_link.reset();
    }
    root.reset();
  }
}

} // namespace extractor