// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util.indexing.memory;

import com.intellij.openapi.util.io.ByteArraySequence;
import com.intellij.util.indexing.impl.forward.ForwardIndex;
import gnu.trove.TIntObjectHashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;

public final class InMemoryForwardIndex implements ForwardIndex {
  private final TIntObjectHashMap<byte[]> myMap = new TIntObjectHashMap<>();

  @Override
  public synchronized @Nullable ByteArraySequence get(@NotNull Integer key) throws IOException {
    byte[] bytes = myMap.get(key);
    return bytes == null ? null : new ByteArraySequence(bytes);
  }

  @Override
  public synchronized void put(@NotNull Integer key, @Nullable ByteArraySequence value) {
    if (value == null) {
      myMap.remove(key);
    } else {
      myMap.put(key, value.toBytes());
    }
  }

  @Override
  public void force() {

  }

  @Override
  public synchronized void clear() {
    myMap.clear();
  }

  @Override
  public void close() {

  }
}

@@ -202,41 +202,152 @@
 lij.
-openapi.util.io.ByteArraySequence
+concurrency.ConcurrentCollectionFactory;%0Aimport com.intellij.openapi.util.io.ByteArraySequence;%0Aimport com.intellij.util.containers.IntObjectMap
 ;%0Aim
@@ -409,44 +409,8 @@
 ex;%0A
-import gnu.trove.TIntObjectHashMap;%0A
 impo
@@ -602,17 +602,16 @@
 e final 
-T
 IntObjec
@@ -607,28 +607,24 @@
 al IntObject
-Hash
 Map%3Cbyte%5B%5D%3E 
@@ -635,13 +635,52 @@
 p = 
-new T
+ConcurrentCollectionFactory.createConcurrent
 IntO
@@ -688,17 +688,11 @@
 ject
-Hash
 Map
-%3C%3E
 ();%0A
@@ -713,29 +713,16 @@
  public 
-synchronized 
 @Nullabl
@@ -909,37 +909,24 @@
 de%0A  public 
-synchronized 
 void put(@No
@@ -1036,16 +1036,20 @@
 );%0A    %7D
+%0A   
  else %7B%0A
@@ -1133,19 +1133,16 @@
 orce() %7B
-%0A%0A 
  %7D%0A%0A  @O
@@ -1162,21 +1162,8 @@
 lic 
-synchronized 
 void
@@ -1232,16 +1232,13 @@
 lose() %7B
-%0A%0A 
  %7D%0A%7D%0A

use concurrent hash map in InMemoryForwardIndex