-
Notifications
You must be signed in to change notification settings - Fork 1
/
gate_set.cpp
88 lines (83 loc) · 1.52 KB
/
gate_set.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include "gate_set.h"
using namespace std;
gate_set::gate_set()
{
}
void gate_set::insert(gate_cpdf * g)
{
//Loop through the whole set, if not found, put in
int size = gates.size();
for(int i = 0; i < size; ++i)
{
if(gates[i] == g)
{
return;
}
}
gates.push_back(g);
}
gate_set gate_set::gs_union( gate_set * gs)
{
//Really cheap any slow - sorry world
//Create a new gate set and insert values from both
gate_set rv;
int self_size = gates.size();
for(int i = 0; i < self_size; ++i)
{
rv.insert(gates[i]);
}
int param_size = gs->gates.size();
for(int i = 0; i < param_size; ++i)
{
rv.insert(gs->gates[i]);
}
return rv;
}
int gate_set::get_index(gate_cpdf * g)
{
//Loop through and find gate
int self_size = gates.size();
for(int i = 0; i < self_size; ++i)
{
if(gates[i] == g)
{
return i;
}
}
return -1;
}
gate_set gate_set::intersect( gate_set * gs)
{
//Loop through self
//If self exists in other then it is part of intersection
//Really slow too.
gate_set rv;
int self_size = gates.size();
for(int i = 0; i < self_size; ++i)
{
//Found it in other
if(gs->get_index(gates[i]) > -1)
{
rv.insert(gates[i]);
}
}
return rv;
}
gate_set gate_set::difference( gate_set * gs)
{
//Loop through self
//If self does not exist in other then it is part of difference
//Really slow too.
gate_set rv;
int self_size = gates.size();
for(int i = 0; i < self_size; ++i)
{
//Not found in other
if(gs->get_index(gates[i]) == -1)
{
rv.insert(gates[i]);
}
}
return rv;
}