-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcnotcounter.cpp
49 lines (40 loc) · 867 Bytes
/
cnotcounter.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
#include <cnotcounter.h>
cnotcounter::cnotcounter()
{
numberCnot = 0;
}
int cnotcounter::getCnotPart(int val)
{
if(val > cnotcounter::startCnotNumber)
{
int type = val%2;
type += (type == 0 ? TGT : 0);
return type;
}
return -1;
}
bool cnotcounter::isCnot(int val)
{
bool is = (getCnotPart(val) != -1);
return is;
}
int cnotcounter::getNextCnotNumber()
{
//this will be the number of the control
int ret = startCnotNumber + 2*numberCnot + 1;
//all the targets of a CNOT will have the same number(id) 10000+2*numberCnot + 2;
numberCnot++;
return ret;
}
bool cnotcounter::sameCnot(int ctrlval, int targetval)
{
return (ctrlval + 1 == targetval);
}
bool cnotcounter::isControl(int value)
{
return isCnot(value) && (getCnotPart(value) == CTRL);
}
bool cnotcounter::isTarget(int value)
{
return isCnot(value) && (getCnotPart(value) == TGT);
}