-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy16nums
77 lines (66 loc) · 1.71 KB
/
my16nums
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
/////////////////////80位数////////////////////////////////////////////////////////////
struct my16nums{
unsigned long low64;
unsigned int high16;
int leave;
my16nums(int p); //p代表通道数,
my16nums operator+(const my16nums &other) const; //表示通道之间的与操作
vector<int> validtunnelarray(); //输出当前所有可用的通道
void usedtunnel(int k); //占用第k个通道
bool checktunnel(int k); //判断第k个通道是否被使用
};
my16nums:: my16nums(int p){
low64=0,high16=0,leave=p;
for(int ii=0;ii<p||ii<64;ii++){
low64 = low64|(1<<ii);
}
for(int ii=0;ii<(p-64);ii++){
high16 = high16|(1<<ii);
}
}
my16nums my16nums::operator+(const my16nums &other) const{
my16nums ans(0);
ans.low64 = this->low64 & other.low64;
ans.high16 = this->high16 & other.high16;
return ans;
}
vector<int> my16nums::validtunnelarray(){
vector<int> ans;
int index = 0;
unsigned long a = this->low64;
while(a){
if(a&1){
ans.push_back(index);
}
index++;
a = a>>1;
}
index = 64;
unsigned int b = this->high16;
while(b){
if(b&1){
ans.push_back(index);
}
index++;
b = b>>1;
}
return ans;
}
void my16nums::usedtunnel(int k){
if(k<64){
this->low64 = this->low64 & (~(1<<k));
}
else{
this->high16 = this->high16 & (~(1<<(k-64)));
}
leave--;
}
bool my16nums::checktunnel(int k){
if(k<64){
return (this->low64 & (1<<k));
}
else{
return (this->high16 & (1<<(k-64)));
}
}
///////////////////////////////////////////////////my16nums/////////////////////////////