def _indexfile(filename): """Create bitmap with locations of non-empty lines.""" result = RoaringBitmap() offset = 0 with open(filename, 'rb') as tmp: for line in tmp: if not line.isspace(): result.add(offset) offset += len(line) result.add(offset) return result.freeze()
def test_discard(self, single): for name, data in single: ref = set() rb = RoaringBitmap() for n in sorted(data): ref.add(n) rb.add(n) for n in sorted(data): ref.discard(n) rb.discard(n) rb._checkconsistency() assert len(ref) == 0, name assert len(rb) == 0, name assert rb == ref, name
def test_add(self, single): for name, data in single: ref = set() rb = RoaringBitmap() for n in sorted(data): ref.add(n) rb.add(n) assert rb == ref, name with pytest.raises(OverflowError): rb.add(-1) rb.add(1 << 32) rb.add(0) rb.add((1 << 32) - 1) rb._checkconsistency()
def test_discard(self, single): for data in single: ref = set() rb = RoaringBitmap() for n in sorted(data): ref.add(n) rb.add(n) for n in sorted(data): ref.discard(n) rb.discard(n) assert len(ref) == 0 assert len(rb) == 0 assert set(ref) == set(rb) assert rb == ref
def test_add(self, single): for data in single: ref = set() rb = RoaringBitmap() for n in sorted(data): ref.add(n) rb.add(n) assert set(ref) == set(rb) assert rb == ref with pytest.raises(OverflowError): rb.add(-1) rb.add(1 << 32) rb.add(0) rb.add((1 << 32) - 1)
def test_issue28(self): rbm = RoaringBitmap() rbm.add(3995084765) r = rbm.clamp(0, 8388607) assert len(r) == 0
# special case for speed chunkmap = bytemap else: for c in range(0, max_possible_chunk + 1): chunk_start = c * args.chunk_size chunk_stop = (c + 1) * args.chunk_size #chunkrange = range(chunk_start, chunk_stop) #z1 = len(bytemap.clamp(chunk_start, chunk_stop)) == 0 #fastest #z2 = bytemap.intersection_len(chunkrange) == 0 #z3 = bytemap.isdisjoint(chunkrange) #assert(z1 == z2 and z2 == z3) #chunkificator = chunkificators[c] #if not bytemap.isdisjoint(chunkificator): overlap = bytemap.clamp(chunk_start, chunk_stop) if len(overlap) != 0: chunksb.add(c) chunkmap = chunksb.freeze() chunked_bytes = len(chunkmap) * args.chunk_size chunked_executed_ratio = chunked_bytes // executed_bytes highlighter: str = "" if chunked_executed_ratio > 1: highlighter = "\t\t" + "!" * (chunked_executed_ratio - 1) #represent_contract(bytemap, chunkmap) if chunked_bytes < executed_bytes: # sanity check logging.info( f"Contract {codehash} in block {block} executes {executed_bytes} but merklizes to {chunked_bytes}" ) highlighter = "\t\t" + "??????" represent_contract(bytemap, chunkmap) chunk_waste = (1 - executed_bytes / chunked_bytes) * 100