static <K, V, M extends PersistentMapBase<? super K, ? super V>> M canonicalize(
    final @NotNull PersistentMapBase<K, V> originalMap,
    final @NotNull /* @OutParam */ M targetCanonicalMap,
    final @NotNull Function<? super List<K>, ? extends List<K>> stableKeysSorter,
    final @NotNull Function<? super V, ? extends V> valueCanonicalizer
  ) throws IOException {
    final List<K> keys = new ArrayList<>();
    originalMap.processExistingKeys(k -> {
      keys.add(k);
      return true;
    });

    final List<? extends K> sortedKeys = stableKeysSorter.apply(keys);
    for (K key : sortedKeys) {
      final V value = originalMap.get(key);
      final V canonicalizedValue = valueCanonicalizer.apply(value);
      targetCanonicalMap.put(key, canonicalizedValue);
    }
    return targetCanonicalMap;
  }
static <K, V, M extends PersistentMapBase<? super K, ? super V>> M canonicalize(
    final @NotNull PersistentMapBase<K, V> originalMap,
    final @NotNull /* @OutParam */ M targetCanonicalMap,
    final @NotNull Function<? super List<K>, ? extends List<K>> stableKeysSorter,
    final @NotNull Function<? super V, ? extends V> valueCanonicalizer
  )