| 64 | self.clustered = True |
| 65 | |
| 66 | def write_tile(self, tileid, data): |
| 67 | if len(self.tile_entries) > 0 and tileid < self.tile_entries[-1].tile_id: |
| 68 | self.clustered = False |
| 69 | |
| 70 | hsh = hash(data) |
| 71 | if hsh in self.hash_to_offset: |
| 72 | last = self.tile_entries[-1] |
| 73 | found = self.hash_to_offset[hsh] |
| 74 | if tileid == last.tile_id + last.run_length and last.offset == found: |
| 75 | self.tile_entries[-1].run_length += 1 |
| 76 | else: |
| 77 | self.tile_entries.append(Entry(tileid, found, len(data), 1)) |
| 78 | else: |
| 79 | self.tile_f.write(data) |
| 80 | self.tile_entries.append(Entry(tileid, self.offset, len(data), 1)) |
| 81 | self.hash_to_offset[hsh] = self.offset |
| 82 | self.offset += len(data) |
| 83 | |
| 84 | self.addressed_tiles += 1 |
| 85 | |
| 86 | def finalize(self, header, metadata): |
| 87 | header["addressed_tiles_count"] = self.addressed_tiles |