@Override
  public void save(@NotNull DataOutput stream, Map<Key, Value> data) throws IOException {
    final int size = data.size();
    DataInputOutputUtil.writeINT(stream, size);
    if (size == 0) return;

    final Collection<Key>[] keysForNullValue = new Collection[]{null};
    Map<Value, Collection<Key>> keysPerValue = null;

    //TODO RC: why store Map<Key,Value> in 'inverted' form, as Map<Value, Collection<Key>> here?
    if (myValuesAreNullAlways) {
      keysForNullValue[0] = data.keySet();
    }
    else {
      keysPerValue = new HashMap<>();
      Map<Value, Collection<Key>> finalKeysPerValue = keysPerValue;
      data.forEach((key, value) -> {
        Collection<Key> keys = value != null ? finalKeysPerValue.get(value) : keysForNullValue[0];
        if (keys == null) {
          keys = new SmartList<>();
          if (value != null) {
            finalKeysPerValue.put(value, keys);
          }
          else {
            keysForNullValue[0] = keys;
          }
        }
        keys.add(key);
      });
    }

    if (keysForNullValue[0] != null) {
      myValueExternalizer.save(stream, null);
      myKeysExternalizer.save(stream, keysForNullValue[0]);
    }

    if (keysPerValue != null) {
      for (Value value : keysPerValue.keySet()) {
        myValueExternalizer.save(stream, value);
        myKeysExternalizer.save(stream, keysPerValue.get(value));
      }
    }
  }
@Override
  public void save(@NotNull DataOutput stream, Map<Key, Value> data)