-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify.py
More file actions
51 lines (38 loc) · 1.4 KB
/
Copy pathverify.py
File metadata and controls
51 lines (38 loc) · 1.4 KB
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
import copy
import random
import utils
def judge_single_node(array_list, i, n, t):
mask = (1 << t) - 1
others = 0
for j in range(n):
if j == i:
continue
others = others | array_list[j]
return (array_list[i] & mask) & (~others & mask) > 0
class Verify(object):
def __init__(self, n, t, sampling_num):
self.n = n
self.t = t
self.samplingNum = sampling_num
def judge(self, array_list, count_map):
for i in range(len(array_list)):
if judge_single_node(array_list, i, self.n, self.t):
count_map[i] = count_map[i] + 1
def sampling_verify(self, array_list, count_map, sampling_num):
temp = copy.deepcopy(array_list)
for i in range(len(array_list)):
count_map[i] = 0
for i in range(sampling_num):
for j in range(len(array_list)):
offset = random.randint(0, self.t)
temp[j] = utils.rotate_right(temp[j], offset, self.t)
self.judge(temp, count_map)
count = 0
for (k,v) in count_map.items():
count += v
return count / (len(array_list) * sampling_num)
def format_and_verify_sampling(self, array_list):
count_map = dict()
result = self.sampling_verify(array_list, count_map, self.samplingNum)
# print("抽样可靠率: %.6f" % result)
return result