| 520 | |
| 521 | |
| 522 | def build_compression_dawg(ucdata): |
| 523 | d = Dawg() |
| 524 | ucdata.sort() |
| 525 | for name, value in ucdata: |
| 526 | d.insert(name, value) |
| 527 | packed, pos_to_code, reversedict = d.finish() |
| 528 | print("size of dawg [KiB]", round(len(packed) / 1024, 2)) |
| 529 | # check that lookup and inverse_lookup work correctly on the input data |
| 530 | for name, value in ucdata: |
| 531 | assert lookup(packed, pos_to_code, name.encode('ascii')) == value |
| 532 | assert inverse_lookup(packed, reversedict, value) == name.encode('ascii') |
| 533 | return packed, pos_to_code |