diff options
Diffstat (limited to 'src/network_set.cpp')
-rw-r--r-- | src/network_set.cpp | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/network_set.cpp b/src/network_set.cpp index 6d2a098..45911e3 100644 --- a/src/network_set.cpp +++ b/src/network_set.cpp | |||
@@ -4,9 +4,8 @@ void NetworkSet::Clear() { | |||
4 | network_by_item_.clear(); | 4 | network_by_item_.clear(); |
5 | } | 5 | } |
6 | 6 | ||
7 | void NetworkSet::AddLink(int id1, int id2) { | 7 | void NetworkSet::AddLink(int id1, int id2, bool two_way) { |
8 | if (id2 > id1) { | 8 | if (two_way && id2 > id1) { |
9 | // Make sure id1 < id2 | ||
10 | std::swap(id1, id2); | 9 | std::swap(id1, id2); |
11 | } | 10 | } |
12 | 11 | ||
@@ -17,14 +16,37 @@ void NetworkSet::AddLink(int id1, int id2) { | |||
17 | network_by_item_[id2] = {}; | 16 | network_by_item_[id2] = {}; |
18 | } | 17 | } |
19 | 18 | ||
20 | network_by_item_[id1].insert({id1, id2}); | 19 | NetworkNode node = {id1, id2, two_way}; |
21 | network_by_item_[id2].insert({id1, id2}); | 20 | |
21 | network_by_item_[id1].insert(node); | ||
22 | network_by_item_[id2].insert(node); | ||
23 | } | ||
24 | |||
25 | void NetworkSet::AddLinkToNetwork(int network_id, int id1, int id2, bool two_way) { | ||
26 | if (two_way && id2 > id1) { | ||
27 | std::swap(id1, id2); | ||
28 | } | ||
29 | |||
30 | if (!network_by_item_.count(network_id)) { | ||
31 | network_by_item_[network_id] = {}; | ||
32 | } | ||
33 | |||
34 | NetworkNode node = {id1, id2, two_way}; | ||
35 | |||
36 | network_by_item_[network_id].insert(node); | ||
22 | } | 37 | } |
23 | 38 | ||
24 | bool NetworkSet::IsItemInNetwork(int id) const { | 39 | bool NetworkSet::IsItemInNetwork(int id) const { |
25 | return network_by_item_.count(id); | 40 | return network_by_item_.count(id); |
26 | } | 41 | } |
27 | 42 | ||
28 | const std::set<std::pair<int, int>>& NetworkSet::GetNetworkGraph(int id) const { | 43 | const std::set<NetworkNode>& NetworkSet::GetNetworkGraph(int id) const { |
29 | return network_by_item_.at(id); | 44 | return network_by_item_.at(id); |
30 | } | 45 | } |
46 | |||
47 | bool NetworkNode::operator<(const NetworkNode& rhs) const { | ||
48 | if (entry != rhs.entry) return entry < rhs.entry; | ||
49 | if (exit != rhs.exit) return exit < rhs.exit; | ||
50 | if (two_way != rhs.two_way) return two_way < rhs.two_way; | ||
51 | return false; | ||
52 | } | ||