private static <K, V> void fillValueHashToIdMap(@NotNull AppendOnlyLog valuesLog,
                                                  @NotNull EqualityPolicy<? super K> keyEquality,
                                                  @NotNull EntryExternalizer<K, V> entryExternalizer,
                                                  @NotNull DurableIntToMultiIntMap keyHashToEntryOffsetMap) throws IOException {
    //MAYBE RC: keyHashToEntryOffsetMap could be filled async -- to not delay initialization? (see DurableStringEnumerator)

    valuesLog.forEachRecord((logId, entryBuffer) -> {
      Entry<K, V> entry = entryExternalizer.read(entryBuffer);
      K key = entry.key();

      //RC: below is basically DurableMapOverAppendOnlyLog.put() method, slightly stripped

      int adjustedHash = HashUtils.adjustHash(keyEquality.getHashCode(key));
      int storedId = convertLogIdToStoredId(logId);

      int foundRecordId = keyHashToEntryOffsetMap.lookup(
        adjustedHash,
        candidateRecordId -> {
          long logRecordId = convertStoredIdToLogId(candidateRecordId);
          Entry<K, V> entryWithSameKey = valuesLog.read(
            logRecordId,
            _entryBuffer -> entryExternalizer.readIfKeyMatch(_entryBuffer, key)
          );
          if (entryWithSameKey == null) {
            return false; // [record.key != key] => hash collision => look further
          }
          //record with key exists, but with different value
          return true;
        }
      );
      //Don't check _value_ equality here, because
      // a) there should be no duplicated (key,value) entries in the log -- we shouldn't have added such entries
      // b) even if duplicated entries do exist -- lets keep ref to the last one of duplicates in the map, nothing wrong in it

      boolean keyRecordExists = (foundRecordId != DurableIntToMultiIntMap.NO_VALUE);
      if (keyRecordExists) {
        keyHashToEntryOffsetMap.replace(adjustedHash, foundRecordId, storedId);
      }
      else {
        keyHashToEntryOffsetMap.put(adjustedHash, storedId);
      }

      return true;
    });
  }
private static <K, V> void fillValueHashToIdMap(@NotNull AppendOnlyLog valuesLog,
                                                  @NotNull EqualityPolicy<? super K> keyEquality,
                                                  @NotNull EntryExternalizer<K, V> entryExternalizer,
                                                  @NotNull DurableIntToMultiIntMap keyHashToEntryOffsetMap)