forked from hyperledger/indy-plenum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitmask_helper.py
48 lines (48 loc) · 1.43 KB
/
bitmask_helper.py
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
# from typing import List
#
# from bitarray import bitarray
#
# from common.exceptions import LogicError
#
#
# class BitmaskHelper:
#
# @staticmethod
# def pack_discarded_mask(value):
# discarded_mask = bitarray()
# discarded_mask.pack(bytes.fromhex(value))
# return discarded_mask
#
# @staticmethod
# def unpack_discarded_mask(discarded_mask):
# return discarded_mask.unpack().hex()
#
# @staticmethod
# def get_valid_reqs(reqIdrs, mask: bitarray):
# return [b for a, b in zip(mask.tolist(), reqIdrs) if not a]
#
# @staticmethod
# def get_invalid_reqs(reqIdrs, mask: bitarray):
# return [b for a, b in zip(mask.tolist(), reqIdrs) if a]
#
# @staticmethod
# def get_valid_count(mask: bitarray, len_reqIdr=0):
# if mask.length() == 0:
# return len_reqIdr
# return mask.count(0)
#
# @staticmethod
# def get_invalid_count(mask: bitarray):
# return mask.count(1)
#
# @staticmethod
# def drop_discarded_mask():
# return bitarray()
#
# @staticmethod
# def apply_bitmask_to_list(reqIdrs: List, mask: bitarray):
# if mask.length() == 0:
# return reqIdrs, []
# if len(reqIdrs) != mask.length():
# raise LogicError("Length of reqIdr list and bitmask is not the same")
# return BitmaskHelper.get_valid_reqs(reqIdrs, mask), BitmaskHelper.get_invalid_reqs(reqIdrs, mask)