Skip to main content

deduplicated

Function deduplicated 

Source
fn deduplicated(
    entries: impl Iterator<Item = (Value, Value)>,
) -> Vec<(Value, Value)>
Expand description

The entries of a map to be written, with no key twice: the first entry for a key is kept in its place and the rest are dropped.

Callers pass entries that are already normalised, because normalisation can create a collision — Float(1.0) and Integer(1) are two keys in a store and one key in a file, as are a byte string and the same bytes under tag 64 — so a check that ran first would miss it.

First wins, not last. Every read in this file goes through find, which returns the first entry for a key, so keeping the first is what makes the entry a caller is shown the entry that survives a rewrite; keeping the last would hand back one value and file another. It also makes the rewrite a fixed point rather than something a value can drift across.

Quadratic, and deliberately: these are the keys of one map, the comparison is a Value equality rather than a hash of an arbitrary tree, and Value is not Hash at all — a CBOR value may be a float.