overflowdb.OdbIndexManager Maven / Gradle / Ivy
package overflowdb;
import org.h2.mvstore.MVMap;
import overflowdb.storage.OdbStorage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.LongStream;
public final class OdbIndexManager {
private final OdbGraph graph;
// TODO use concurrent but memory efficient map
protected Map>> indexes = new ConcurrentHashMap<>();
protected Map dirtyFlags = new ConcurrentHashMap<>();
public OdbIndexManager(OdbGraph graph) {
this.graph = graph;
}
/**
* Create an index for specified node property.
* Whenever an element has the specified key mutated, the index is updated.
* When the index is created, all existing elements are indexed to ensure that they are captured by the index.
*/
public final void createNodePropertyIndex(final String propertyName) {
checkPropertyName(propertyName);
if (indexes.containsKey(propertyName))
return;
dirtyFlags.put(propertyName, true);
graph.nodes.iterator().forEachRemaining(node -> {
Object value = node.property2(propertyName);
if (value != null) {
put(propertyName, value, (NodeRef) node);
}
});
}
public boolean isIndexed(final String propertyName) {
return indexes.containsKey(propertyName);
}
private void checkPropertyName(String propertyName) {
if (propertyName == null || propertyName.isEmpty())
throw new IllegalArgumentException("Illegal property name: " + propertyName);
}
public final void loadNodePropertyIndex(final String propertyName, Map
© 2015 - 2024 Weber Informatics LLC | Privacy Policy