about summary refs log tree commit diff stats
path: root/src/network_set.cpp
blob: 2a9e12c835be2277b9eeb9c03a266b6b7bb063ed (plain) (blame)
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
#include "network_set.h"

void NetworkSet::Clear() {
  network_by_item_.clear();
}

void NetworkSet::AddLink(int id1, int id2) {
  if (id2 > id1) {
    // Make sure id1 < id2
    std::swap(id1, id2);
  }

  if (!network_by_item_.count(id1)) {
    network_by_item_[id1] = {};
  }
  if (!network_by_item_.count(id2)) {
    network_by_item_[id2] = {};
  }

  network_by_item_[id1].insert({id1, id2});
  network_by_item_[id2].insert({id1, id2});
}

void NetworkSet::AddLinkToNetwork(int network_id, int id1, int id2) {
  if (id2 > id1) {
    // Make sure id1 < id2
    std::swap(id1, id2);
  }

  if (!network_by_item_.count(network_id)) {
    network_by_item_[network_id] = {};
  }

  network_by_item_[network_id].insert({id1, id2});
}

bool NetworkSet::IsItemInNetwork(int id) const {
  return network_by_item_.count(id);
}

const std::set<std::pair<int, int>>& NetworkSet::GetNetworkGraph(int id) const {
  return network_by_item_.at(id);
}