mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
split ForwardIndex into 2 objects: ForwardIndex - a binary data storage, ForwardIndexAccessor - decoder of indexed binary data
This commit is contained in:
@@ -24,6 +24,7 @@ import com.intellij.openapi.util.ThrowableComputable;
|
||||
import com.intellij.openapi.util.io.BufferExposingByteArrayOutputStream;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
import com.intellij.util.indexing.*;
|
||||
import com.intellij.util.indexing.impl.forward.ForwardIndexAccessor;
|
||||
import com.intellij.util.io.DataExternalizer;
|
||||
import com.intellij.util.io.DataOutputStream;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -74,6 +75,13 @@ public abstract class MapReduceIndex<Key,Value, Input> implements InvertedIndex<
|
||||
}
|
||||
});
|
||||
|
||||
protected MapReduceIndex(@NotNull IndexExtension<Key, Value, Input> extension,
|
||||
@NotNull IndexStorage<Key, Value> storage,
|
||||
@Nullable com.intellij.util.indexing.impl.forward.ForwardIndex forwardIndex,
|
||||
@Nullable ForwardIndexAccessor<Key, Value, Input> forwardIndexAccessor) {
|
||||
this(extension, storage, forwardIndex == null && forwardIndexAccessor == null ? null : wrapWithOldForwardIndex(forwardIndex, forwardIndexAccessor));
|
||||
}
|
||||
|
||||
protected MapReduceIndex(@NotNull IndexExtension<Key, Value, Input> extension,
|
||||
@NotNull IndexStorage<Key, Value> storage,
|
||||
@Nullable ForwardIndex<Key, Value> forwardIndex) {
|
||||
@@ -355,5 +363,39 @@ public abstract class MapReduceIndex<Key,Value, Input> implements InvertedIndex<
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static <Key, Value, Input> ForwardIndex<Key, Value> wrapWithOldForwardIndex(com.intellij.util.indexing.impl.forward.ForwardIndex forwardIndex,
|
||||
ForwardIndexAccessor<Key, Value, Input> forwardIndexAccessor) {
|
||||
LOG.assertTrue(forwardIndex != null);
|
||||
LOG.assertTrue(forwardIndexAccessor != null);
|
||||
return new ForwardIndex<Key, Value>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public InputDataDiffBuilder<Key, Value> getDiffBuilder(int inputId) throws IOException {
|
||||
return forwardIndexAccessor.getDiffBuilder(inputId, forwardIndex.get(inputId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putInputData(int inputId, @NotNull Map<Key, Value> data) throws IOException {
|
||||
forwardIndex.put(inputId, forwardIndexAccessor.serializeIndexedData(data, null));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
forwardIndex.force();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() throws IOException {
|
||||
forwardIndex.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
forwardIndex.close();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// Copyright 2000-2019 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.impl.forward;
|
||||
|
||||
import com.intellij.openapi.util.io.ByteArraySequence;
|
||||
import com.intellij.util.io.KeyValueStore;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Represents key-value storage held by <a href="https://en.wikipedia.org/wiki/Search_engine_indexing#The_forward_index">forward index data structure</>.
|
||||
*/
|
||||
@ApiStatus.Experimental
|
||||
public interface ForwardIndex extends KeyValueStore<Integer, ByteArraySequence> {
|
||||
@Nullable
|
||||
@Override
|
||||
ByteArraySequence get(@NotNull Integer key) throws IOException;
|
||||
|
||||
@Override
|
||||
void put(@NotNull Integer key, @Nullable ByteArraySequence value) throws IOException;
|
||||
|
||||
void clear() throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright 2000-2019 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.impl.forward;
|
||||
|
||||
import com.intellij.openapi.util.io.ByteArraySequence;
|
||||
import com.intellij.util.indexing.impl.InputDataDiffBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ForwardIndexAccessor<Key, Value, Input> {
|
||||
/**
|
||||
* Creates a diff builder for given inputId.
|
||||
*/
|
||||
@NotNull
|
||||
InputDataDiffBuilder<Key, Value> getDiffBuilder(int inputId, @Nullable ByteArraySequence sequence) throws IOException;
|
||||
|
||||
/**
|
||||
* Serialize indexed data to forward index format.
|
||||
*/
|
||||
@Nullable
|
||||
ByteArraySequence serializeIndexedData(@Nullable Map<Key, Value> data, @Nullable Input content) throws IOException;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// Copyright 2000-2019 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.io;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public interface KeyValueStore<K, V> extends Closeable {
|
||||
V get(K key) throws IOException;
|
||||
|
||||
void put(K key, V value) throws IOException;
|
||||
|
||||
void force();
|
||||
}
|
||||
@@ -3,28 +3,17 @@ package com.intellij.util.io;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
*/
|
||||
public interface PersistentMap<K, V> extends Closeable {
|
||||
|
||||
V get(K key) throws IOException;
|
||||
|
||||
void put(K key, V value) throws IOException;
|
||||
|
||||
public interface PersistentMap<K, V> extends KeyValueStore<K, V> {
|
||||
boolean processKeys(@NotNull Processor<? super K> processor) throws IOException;
|
||||
|
||||
boolean isClosed();
|
||||
|
||||
boolean isDirty();
|
||||
|
||||
void force();
|
||||
|
||||
@Override
|
||||
void close() throws IOException;
|
||||
|
||||
void markDirty() throws IOException;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user