Insert an element in the filter. elem may be a COutPoint or bytes
(self, elem)
| 118 | __bit_mask = bytearray([0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80]) |
| 119 | |
| 120 | def insert(self, elem): |
| 121 | """Insert an element in the filter. |
| 122 | |
| 123 | elem may be a COutPoint or bytes |
| 124 | """ |
| 125 | if isinstance(elem, bitcoin.core.COutPoint): |
| 126 | elem = elem.serialize() |
| 127 | |
| 128 | if len(self.vData) == 1 and self.vData[0] == 0xff: |
| 129 | return |
| 130 | |
| 131 | for i in range(0, self.nHashFuncs): |
| 132 | nIndex = self.bloom_hash(i, elem) |
| 133 | # Sets bit nIndex of vData |
| 134 | self.vData[nIndex >> 3] |= self.__bit_mask[7 & nIndex] |
| 135 | |
| 136 | def contains(self, elem): |
| 137 | """Test if the filter contains an element |