public List<CallingLocation> getAllLocations(final MethodNameAndQualifier methodNameAndQualifier) { try { final List<CallingLocation> result = new ArrayList<CallingLocation>(); myIndex.getData(methodNameAndQualifier).forEach(new ValueContainer.ContainerAction<List<CallingLocation>>() { @Override public boolean perform(final int id, final List<CallingLocation> values) { result.addAll(values); return true; } }); return result; } catch (StorageException e) { throw new RuntimeException(e); } }
public Multiset<MethodIncompleteSignature> getLocationsAsParam(final MethodNameAndQualifier methodNameAndQualifier) { final Multiset<MethodIncompleteSignature> result = HashMultiset.create(); try { myIndex.getData(methodNameAndQualifier).forEach(new ValueContainer.ContainerAction<List<CallingLocation>>() { @Override public boolean perform(final int id, final List<CallingLocation> values) { for (final CallingLocation value : values) { if (value.getVariableType().equals(VariableType.METHOD_PARAMETER)) { result.add(value.getMethodIncompleteSignature()); } } return true; } }); } catch (StorageException e) { throw new RuntimeException(e); } return result; }
protected Set<String> getSupers(final String classQName) { try { final ValueContainer<Set<String>> valueContainer = myIndex.getData(classQName); final Ref<Set<String>> setRef = Ref.create(); valueContainer.forEach(new ValueContainer.ContainerAction<Set<String>>() { @Override public boolean perform(final int id, final Set<String> value) { setRef.set(value); return false; } }); final Set<String> supers = setRef.get(); if (supers == null) { return Collections.emptySet(); } return supers; } catch (StorageException e) { throw new RuntimeException(e); } }
protected Set<String> getMethodsNames(final String classQName) { final Ref<Set<String>> methodsRef = Ref.create(); try { myIndex.getData(classQName).forEach(new ValueContainer.ContainerAction<Set<String>>() { @Override public boolean perform(final int id, final Set<String> value) { methodsRef.set(value); return true; } }); final Set<String> methods = methodsRef.get(); return methods == null ? Collections.<String>emptySet() : methods; } catch (StorageException e) { throw new RuntimeException(e); } }
public TreeSet<UsageIndexValue> getValues(final K key) { try { final ValueContainer<Multiset<MethodIncompleteSignature>> valueContainer = myIndex.getData(key); final Multiset<MethodIncompleteSignature> rawValues = HashMultiset.create(); valueContainer.forEach(new ValueContainer.ContainerAction<Multiset<MethodIncompleteSignature>>() { @Override public boolean perform(final int id, final Multiset<MethodIncompleteSignature> values) { for (final Multiset.Entry<MethodIncompleteSignature> entry : values.entrySet()) { rawValues.add(entry.getElement(), entry.getCount()); } return true; } }); return rawValuesToValues(rawValues); } catch (StorageException e) { throw new RuntimeException(); } }
@NotNull public List<Integer> getTwinInfo(final String typeQName) { try { final ValueContainer<List<Integer>> valueContainer = myIndex.getData(typeQName); final List<Integer> result = new ArrayList<Integer>(valueContainer.size()); valueContainer.forEach(new ValueContainer.ContainerAction<List<Integer>>() { @Override public boolean perform(final int id, final List<Integer> value) { result.addAll(value); return true; } }); return result; } catch (StorageException e) { throw new RuntimeException(e); } }
public IdBitSet(RandomAccessIntContainer set, int additionalCount) { this(calcMax(set), additionalCount); ValueContainer.IntIterator iterator = set.intIterator(); while(iterator.hasNext()) { add(iterator.next()); } }
private static int[] calcMax(RandomAccessIntContainer set) { int min = Integer.MAX_VALUE; int max = Integer.MIN_VALUE; ValueContainer.IntIterator iterator = set.intIterator(); while(iterator.hasNext()) { int next = iterator.next(); min = Math.min(min, next); max = Math.max(max, next); } return new int[] {min, max}; }
@Override public ValueContainer.IntPredicate intPredicate() { return new ValueContainer.IntPredicate() { @Override public boolean contains(int id) { return IdBitSet.this.contains(id); } }; }
@Override public ValueContainer.IntPredicate intPredicate() { return new ValueContainer.IntPredicate() { @Override public boolean contains(int id) { return SortedIdSet.this.contains(id); } }; }
@Override public ValueContainer.IntPredicate intPredicate() { return new ValueContainer.IntPredicate() { @Override public boolean contains(int id) { return IdSet.this.contains(id); } }; }
public static ValueContainer.IntIterator getTransientIterator(ValueContainer.IntIterator intIterator) { final ValueContainer.IntIterator intIteratorConed = intIterator.createCopyInInitialState(); int max = 0, min = Integer.MAX_VALUE; while(intIterator.hasNext()) { int nextInt = intIterator.next(); max = Math.max(max, nextInt); min = Math.min(min, nextInt); } assert min > 0; final int offset = (min >> INT_BITS_SHIFT) << INT_BITS_SHIFT; final int bitsLength = ((max - offset) >> INT_BITS_SHIFT) + 1; final int[] bits = ourSpareBuffer.getBuffer(bitsLength); for(int i = 0; i < bitsLength; ++i) bits[i] = 0; intIterator = intIteratorConed; int size = 0; while(intIterator.hasNext()) { final int id = intIterator.next() - offset; bits[id >> INT_BITS_SHIFT] |= (1 << (id)); ++size; } return new SortedFileIdSetIterator(bits, bitsLength, offset, size); }
private void mergeChangesRemovingDupes() { // duplicated ids can be present for some index due to cancellation of indexing for next index int[] currentChanges = changes; ValueContainer.IntIterator sorted = SortedFileIdSetIterator.getTransientIterator(new ChangesIterator(currentChanges, length)); int lastIndex = 0; while(sorted.hasNext()) { currentChanges[lastIndex++] = sorted.next(); } length = (short)lastIndex; mayHaveDupes = false; }
public ValueContainer.IntPredicate intPredicate() { final ValueContainer.IntPredicate predicate = getRandomAccessContainer().intPredicate(); if (checkSet != null) { return new ValueContainer.IntPredicate() { @Override public boolean contains(int id) { boolean answer = predicate.contains(id); DebugAssertions.assertTrue(answer == checkSet.contains(id)); return answer; } }; } return predicate; }
public ValueContainer.IntIterator intIterator() { RandomAccessIntContainer intContainer = randomAccessContainer; if (intContainer == null && !hasRemovals) { int[] currentChanges = changes; if (currentChanges != null) { if (mayHaveDupes) { synchronized (currentChanges) { if (mayHaveDupes) mergeChangesRemovingDupes(); } } return new ChangesIterator(currentChanges, length); } } return getRandomAccessContainer().intIterator(); }
public ValueContainer.IntIterator rawIntIterator() { RandomAccessIntContainer intContainer = randomAccessContainer; if (intContainer == null && !hasRemovals) { return new ChangesIterator(changes, length); // dupes are possible } return getRandomAccessContainer().intIterator(); }
private void removingDupesAndSort() { // duplicated ids can be present for some index due to cancellation of indexing for next index final int[] currentChanges = changes; final int intLength = length; if (intLength < 250) { // Plain sorting in Arrays works without allocations for small number of elements (see DualPivotQuicksort.QUICKSORT_THRESHOLD) Arrays.sort(currentChanges, 0, intLength); boolean hasDupes = false; for(int i = 0, max = intLength - 1; i < max; ++i) { if (currentChanges[i] == currentChanges[i + 1]) { hasDupes = true; break; } } if (hasDupes) { int ptr = 0; for(int i = 1; i < intLength; ++i) { if (currentChanges[i] != currentChanges[ptr]) { currentChanges[++ptr] = currentChanges[i]; } } length = (short)(ptr + 1); } } else { ValueContainer.IntIterator sorted = SortedFileIdSetIterator.getTransientIterator(new ChangesIterator(currentChanges, length, false)); int lastIndex = 0; while (sorted.hasNext()) { currentChanges[lastIndex++] = sorted.next(); } length = (short)lastIndex; } mayHaveDupes = false; }
private static @Nonnull ValueContainer.IntIterator getIntIteratorOutOfFileSetObject(@Nullable Object input) { if (input == null) return EMPTY_ITERATOR; if (input instanceof Integer){ return new SingleValueIterator(((Integer)input).intValue()); } else { return ((ChangeBufferingList)input).intIterator(); } }
FileId2ValueMapping(ValueContainerImpl<Value> _valueContainer) { id2ValueMap = new TIntObjectHashMap<Value>(); valueContainer = _valueContainer; TIntArrayList removedFileIdList = null; List<Value> removedValueList = null; for (final ValueContainer.ValueIterator<Value> valueIterator = _valueContainer.getValueIterator(); valueIterator.hasNext();) { final Value value = valueIterator.next(); for (final ValueContainer.IntIterator intIterator = valueIterator.getInputIdsIterator(); intIterator.hasNext();) { int id = intIterator.next(); Value previousValue = id2ValueMap.put(id, value); if (previousValue != null) { // delay removal of duplicated id -> value mapping since it will affect valueIterator we are using if (removedFileIdList == null) { removedFileIdList = new TIntArrayList(); removedValueList = new SmartList<Value>(); } removedFileIdList.add(id); removedValueList.add(previousValue); } } } if (removedFileIdList != null) { for(int i = 0, size = removedFileIdList.size(); i < size; ++i) { valueContainer.removeValue(removedFileIdList.get(i), removedValueList.get(i)); } } }
@Override public ValueContainer.IntIterator intIterator() { return new Iterator(); }
@Override public ValueContainer.IntIterator createCopyInInitialState() { return new Iterator(); }
@Override public ValueContainer.IntIterator intIterator() { return new IntSetIterator(); }
@Override public ValueContainer.IntIterator createCopyInInitialState() { return new IntSetIterator(); }
@Override public ValueContainer.IntIterator createCopyInInitialState() { return new SortedFileIdSetIterator(myBits, myBitsLength, myOffset, mySize); }
@Override public ValueContainer.IntIterator createCopyInInitialState() { return new ChangesIterator(changes, length); }
@Nonnull @Override public ValueContainer.ValueIterator<Value> getValueIterator() { return getMergedData().getValueIterator(); }
@Nonnull @Override public ValueContainer.IntIterator getInputIdsIterator() { throw new IllegalStateException(); }
@Nonnull ValueContainer<Value> read(Key key) throws StorageException;
@Override @Nonnull ValueContainer.IntPredicate getValueAssociationPredicate();
protected void initMapAndCache() throws IOException { final ValueContainerMap<Key, Value> map; PersistentHashMapValueStorage.CreationTimeOptions.EXCEPTIONAL_IO_CANCELLATION.set(new PersistentHashMapValueStorage.ExceptionalIOCancellationCallback() { @Override public void checkCancellation() { checkCanceled(); } }); PersistentHashMapValueStorage.CreationTimeOptions.COMPACT_CHUNKS_WITH_VALUE_DESERIALIZATION.set(Boolean.TRUE); try { map = new ValueContainerMap<Key, Value>(getStorageFile(), myKeyDescriptor, myDataExternalizer, myKeyIsUniqueForIndexedFile); } finally { PersistentHashMapValueStorage.CreationTimeOptions.EXCEPTIONAL_IO_CANCELLATION.set(null); PersistentHashMapValueStorage.CreationTimeOptions.COMPACT_CHUNKS_WITH_VALUE_DESERIALIZATION.set(null); } myCache = new SLRUCache<Key, ChangeTrackingValueContainer<Value>>(myCacheSize, (int)(Math.ceil(myCacheSize * 0.25)) /* 25% from the main cache size*/) { @Override @Nonnull public ChangeTrackingValueContainer<Value> createValue(final Key key) { return new ChangeTrackingValueContainer<Value>(new ChangeTrackingValueContainer.Initializer<Value>() { @Nonnull @Override public Object getLock() { return map.getDataAccessLock(); } @Nullable @Override public ValueContainer<Value> compute() { ValueContainer<Value> value; try { value = map.get(key); if (value == null) { value = new ValueContainerImpl<Value>(); } } catch (IOException e) { throw new RuntimeException(e); } return value; } }); } @Override protected void onDropFromCache(final Key key, @Nonnull final ChangeTrackingValueContainer<Value> valueContainer) { if (valueContainer.isDirty()) { try { map.put(key, valueContainer); } catch (IOException e) { throw new RuntimeException(e); } } } }; myMap = map; }
ValueContainer.IntIterator intIterator();
ValueContainer.IntPredicate intPredicate();