Skip to content

data/parsetrigrams.cpp: ensure the output is deterministic

Sergei Trofimovich requested to merge trofi/sonnet:master into master

Noticed non-deterministic binary contents when built sonnet on NixOS. There rebuild test found out that parsetrigrams generates non-deterministic output of trigrams from run to run.

This happens because parsetrigrams uses QHash traversal order to store key/value pairs in resources section of lib/libKF5SonnetCore.so.5.85.0 output binary.

The change uses QMap to serialize trigrams and keeps QHash to deserialize them (both QMap and QHash have compatible serialization format:

[ u32(elem_count) | <key><value> <key><value>... ]

Tested the change to produce deterministic output.

Merge request reports