Search in sources :

Example 1 with ChangeBufferingList

use of com.intellij.util.indexing.containers.ChangeBufferingList in project intellij-community by JetBrains.

the class ValueContainerImpl method readFrom.

public void readFrom(DataInputStream stream, DataExternalizer<Value> externalizer) throws IOException {
    FileId2ValueMapping<Value> mapping = null;
    while (stream.available() > 0) {
        final int valueCount = DataInputOutputUtil.readINT(stream);
        if (valueCount < 0) {
            // ChangeTrackingValueContainer marked inputId as invalidated, see ChangeTrackingValueContainer.saveTo
            final int inputId = -valueCount;
            if (mapping == null && size() > NUMBER_OF_VALUES_THRESHOLD) {
                // avoid O(NumberOfValues)
                mapping = new FileId2ValueMapping<Value>(this);
            }
            boolean doCompact;
            if (mapping != null) {
                doCompact = mapping.removeFileId(inputId);
            } else {
                removeAssociatedValue(inputId);
                doCompact = true;
            }
            if (doCompact)
                setNeedsCompacting(true);
        } else {
            for (int valueIdx = 0; valueIdx < valueCount; valueIdx++) {
                final Value value = externalizer.read(stream);
                int idCountOrSingleValue = DataInputOutputUtil.readINT(stream);
                if (idCountOrSingleValue > 0) {
                    addValue(idCountOrSingleValue, value);
                    if (mapping != null)
                        mapping.associateFileIdToValue(idCountOrSingleValue, value);
                } else {
                    idCountOrSingleValue = -idCountOrSingleValue;
                    ChangeBufferingList changeBufferingList = ensureFileSetCapacityForValue(value, idCountOrSingleValue);
                    int prev = 0;
                    for (int i = 0; i < idCountOrSingleValue; i++) {
                        final int id = DataInputOutputUtil.readINT(stream);
                        if (changeBufferingList != null)
                            changeBufferingList.add(prev + id);
                        else
                            addValue(prev + id, value);
                        if (mapping != null)
                            mapping.associateFileIdToValue(prev + id, value);
                        prev += id;
                    }
                }
            }
        }
    }
}
Also used : ChangeBufferingList(com.intellij.util.indexing.containers.ChangeBufferingList)

Example 2 with ChangeBufferingList

use of com.intellij.util.indexing.containers.ChangeBufferingList in project intellij-community by JetBrains.

the class ValueContainerImpl method removeValue.

private void removeValue(int inputId, Object fileSet, Value value) {
    if (fileSet == null) {
        return;
    }
    if (fileSet instanceof ChangeBufferingList) {
        final ChangeBufferingList changesList = (ChangeBufferingList) fileSet;
        changesList.remove(inputId);
        if (!changesList.isEmpty())
            return;
    } else if (fileSet instanceof Integer) {
        if (((Integer) fileSet).intValue() != inputId) {
            return;
        }
    }
    if (!(myInputIdMapping instanceof THashMap)) {
        myInputIdMapping = null;
        myInputIdMappingValue = null;
    } else {
        THashMap<Value, Object> mapping = (THashMap<Value, Object>) myInputIdMapping;
        mapping.remove(value);
        if (mapping.size() == 1) {
            myInputIdMapping = mapping.keySet().iterator().next();
            myInputIdMappingValue = mapping.get((Value) myInputIdMapping);
        }
    }
}
Also used : ChangeBufferingList(com.intellij.util.indexing.containers.ChangeBufferingList) THashMap(gnu.trove.THashMap)

Example 3 with ChangeBufferingList

use of com.intellij.util.indexing.containers.ChangeBufferingList in project intellij-community by JetBrains.

the class ValueContainerImpl method ensureFileSetCapacityForValue.

@Nullable
private ChangeBufferingList ensureFileSetCapacityForValue(Value value, int count) {
    if (count <= 1)
        return null;
    Object fileSetObject = getFileSetObject(value);
    if (fileSetObject != null) {
        if (fileSetObject instanceof Integer) {
            ChangeBufferingList list = new ChangeBufferingList(count + 1);
            list.add(((Integer) fileSetObject).intValue());
            resetFileSetForValue(value, list);
            return list;
        } else if (fileSetObject instanceof ChangeBufferingList) {
            ChangeBufferingList list = (ChangeBufferingList) fileSetObject;
            list.ensureCapacity(count);
            return list;
        }
        return null;
    }
    final ChangeBufferingList fileSet = new ChangeBufferingList(count);
    attachFileSetForNewValue(value, fileSet);
    return fileSet;
}
Also used : ChangeBufferingList(com.intellij.util.indexing.containers.ChangeBufferingList) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ChangeBufferingList

use of com.intellij.util.indexing.containers.ChangeBufferingList in project intellij-community by JetBrains.

the class ValueContainerImpl method saveTo.

@Override
public void saveTo(DataOutput out, DataExternalizer<Value> externalizer) throws IOException {
    DataInputOutputUtil.writeINT(out, size());
    for (final InvertedIndexValueIterator<Value> valueIterator = getValueIterator(); valueIterator.hasNext(); ) {
        final Value value = valueIterator.next();
        externalizer.save(out, value);
        Object fileSetObject = valueIterator.getFileSetObject();
        if (fileSetObject instanceof Integer) {
            // most common 90% case during index building
            DataInputOutputUtil.writeINT(out, (Integer) fileSetObject);
        } else {
            // serialize positive file ids with delta encoding
            ChangeBufferingList originalInput = (ChangeBufferingList) fileSetObject;
            IntIdsIterator intIterator = originalInput.sortedIntIterator();
            if (DebugAssertions.DEBUG)
                DebugAssertions.assertTrue(intIterator.hasAscendingOrder());
            if (intIterator.size() == 1) {
                DataInputOutputUtil.writeINT(out, intIterator.next());
            } else {
                DataInputOutputUtil.writeINT(out, -intIterator.size());
                IdSet checkSet = originalInput.getCheckSet();
                if (checkSet != null && checkSet.size() != intIterator.size()) {
                    // debug code
                    int a = 1;
                    assert false;
                }
                int prev = 0;
                while (intIterator.hasNext()) {
                    int fileId = intIterator.next();
                    if (checkSet != null && !checkSet.contains(fileId)) {
                        // debug code
                        int a = 1;
                        assert false;
                    }
                    DataInputOutputUtil.writeINT(out, fileId - prev);
                    prev = fileId;
                }
            }
        }
    }
}
Also used : ChangeBufferingList(com.intellij.util.indexing.containers.ChangeBufferingList) IntIdsIterator(com.intellij.util.indexing.containers.IntIdsIterator) IdSet(com.intellij.util.indexing.containers.IdSet)

Aggregations

ChangeBufferingList (com.intellij.util.indexing.containers.ChangeBufferingList)4 IdSet (com.intellij.util.indexing.containers.IdSet)1 IntIdsIterator (com.intellij.util.indexing.containers.IntIdsIterator)1 THashMap (gnu.trove.THashMap)1 Nullable (org.jetbrains.annotations.Nullable)1