Java Code Examples for gnu.trove.TIntArrayList#getQuick()
The following examples show how to use
gnu.trove.TIntArrayList#getQuick() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DuplicatesIndex.java From consulo with Apache License 2.0 | 6 votes |
@Override public void save(@Nonnull DataOutput out, TIntArrayList list) throws IOException { if (list.size() == 2) { DataInputOutputUtil.writeINT(out, list.getQuick(0)); DataInputOutputUtil.writeINT(out, list.getQuick(1)); } else { DataInputOutputUtil.writeINT(out, -list.size()); int prev = 0; for (int i = 0, len = list.size(); i < len; i+=2) { int value = list.getQuick(i); DataInputOutputUtil.writeINT(out, value - prev); prev = value; DataInputOutputUtil.writeINT(out, list.getQuick(i + 1)); } } }
Example 2
Source File: TroveContentDB.java From jatecs with GNU General Public License v3.0 | 5 votes |
public int getDocumentLength(int document) { if (_documentLenghts.containsKey(document)) return _documentLenghts.get(document); else { if (document < _documentsFrequencies.size()) { TIntArrayList frequencies = _documentsFrequencies.get(document); int length = 0; for (int i = 0; i < frequencies.size(); ++i) length += frequencies.getQuick(i); _documentLenghts.put(document, length); return length; } else return 0; } }
Example 3
Source File: TroveContentFullDB.java From jatecs with GNU General Public License v3.0 | 5 votes |
public int getDocumentLength(int document) { if (_documentLenghts.containsKey(document)) return _documentLenghts.get(document); else { if (document < _documentsFrequencies.size()) { TIntArrayList frequencies = _documentsFrequencies.get(document); int length = 0; for (int i = 0; i < frequencies.size(); ++i) length += frequencies.getQuick(i); _documentLenghts.put(document, length); return length; } else return 0; } }
Example 4
Source File: URLUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull public static String unescapePercentSequences(@Nonnull String s) { if (s.indexOf('%') == -1) { return s; } StringBuilder decoded = new StringBuilder(); final int len = s.length(); int i = 0; while (i < len) { char c = s.charAt(i); if (c == '%') { TIntArrayList bytes = new TIntArrayList(); while (i + 2 < len && s.charAt(i) == '%') { final int d1 = decode(s.charAt(i + 1)); final int d2 = decode(s.charAt(i + 2)); if (d1 != -1 && d2 != -1) { bytes.add(((d1 & 0xf) << 4 | d2 & 0xf)); i += 3; } else { break; } } if (!bytes.isEmpty()) { final byte[] bytesArray = new byte[bytes.size()]; for (int j = 0; j < bytes.size(); j++) { bytesArray[j] = (byte)bytes.getQuick(j); } decoded.append(new String(bytesArray, CharsetToolkit.UTF8_CHARSET)); continue; } } decoded.append(c); i++; } return decoded.toString(); }
Example 5
Source File: TroveContentDB.java From jatecs with GNU General Public License v3.0 | 4 votes |
public void removeFeatures(IIntIterator removedFeatures) { for (int i = 0; i < _documentsFeatures.size(); ++i) { TIntArrayList feats = _documentsFeatures.get(i); TIntArrayList freqs = _documentsFrequencies.get(i); int j = 0; int shift = 0; int feat; int rem; if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); while (true) { if (feat == rem) { feats.remove(j); freqs.remove(j); if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); ++shift; } else break; } else if (feat > rem) { if (removedFeatures.hasNext()) { rem = removedFeatures.next(); ++shift; } else break; } else { feats.setQuick(j, feat - shift); ++j; if (j < feats.size()) feat = feats.getQuick(j); else break; } } ++shift; } while (j < feats.size()) { feats.setQuick(j, feats.getQuick(j) - shift); ++j; } removedFeatures.begin(); } _documentLenghts.clear(); _featureDocumentsCount.clear(); }
Example 6
Source File: TroveClassificationILDB.java From jatecs with GNU General Public License v3.0 | 4 votes |
public void removeDocuments(IIntIterator removedDocuments) { for (int i = 0; i < _categoriesDocuments.size(); ++i) { TIntArrayList docs = _categoriesDocuments.get(i); Vector<Boolean> docsPrimary = _categoriesDocumentsPrimary.get(i); int j = 0; int shift = 0; int doc; int rem; if (j < docs.size() && removedDocuments.hasNext()) { doc = docs.getQuick(j); rem = removedDocuments.next(); while (true) { if (doc == rem) { docs.remove(j); docsPrimary.remove(j); if (j < docs.size() && removedDocuments.hasNext()) { doc = docs.getQuick(j); rem = removedDocuments.next(); ++shift; } else break; } else if (doc > rem) { if (removedDocuments.hasNext()) { rem = removedDocuments.next(); ++shift; } else break; } else { docs.setQuick(j, doc - shift); ++j; if (j < docs.size()) doc = docs.getQuick(j); else break; } } ++shift; } while (j < docs.size()) { docs.setQuick(j, docs.getQuick(j) - shift); ++j; } removedDocuments.begin(); } }
Example 7
Source File: TroveWeightingDB.java From jatecs with GNU General Public License v3.0 | 4 votes |
public void removeFeatures(IIntIterator removedFeatures) { for (int i = 0; i < _documentsWeights.size(); ++i) { TIntDoubleHashMap weigs = _documentsWeights.get(i); TIntArrayList feats = new TIntArrayList(weigs.size()); TDoubleArrayList weigths = new TDoubleArrayList(weigs.size()); TIntDoubleIterator wit = weigs.iterator(); while (wit.hasNext()) { wit.advance(); feats.add(wit.key()); weigths.add(wit.value()); } int j = 0; int shift = 0; int feat; int rem; if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); while (true) { if (feat == rem) { feats.remove(j); weigths.remove(j); if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); ++shift; } else break; } else if (feat > rem) { if (removedFeatures.hasNext()) { rem = removedFeatures.next(); ++shift; } else break; } else { feats.setQuick(j, feat - shift); ++j; if (j < feats.size()) feat = feats.getQuick(j); else break; } } ++shift; } while (j < feats.size()) { feats.setQuick(j, feats.getQuick(j) - shift); ++j; } weigs.clear(); for (j = 0; j < feats.size(); ++j) weigs.put(feats.getQuick(j), weigths.getQuick(j)); removedFeatures.begin(); } }
Example 8
Source File: TroveDomainDB.java From jatecs with GNU General Public License v3.0 | 4 votes |
public void removeFeatures(IIntIterator removedFeatures) { for (int i = 0; i < _categoriesFeatures.size(); ++i) { TIntArrayList feats = _categoriesFeatures.get(i); int j = 0; int shift = 0; int feat; int rem; if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); while (true) { if (feat == rem) { feats.remove(j); if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); ++shift; } else break; } else if (feat > rem) { if (removedFeatures.hasNext()) { rem = removedFeatures.next(); ++shift; } else break; } else { feats.setQuick(j, feat - shift); ++j; if (j < feats.size()) feat = feats.getQuick(j); else break; } } } while (j < feats.size()) { feats.setQuick(j, feats.getQuick(j) - shift); ++j; } removedFeatures.begin(); } }
Example 9
Source File: TroveContentILDB.java From jatecs with GNU General Public License v3.0 | 4 votes |
public void removeDocuments(IIntIterator removedDocuments) { for (int i = 0; i < _featuresDocuments.size(); ++i) { TIntArrayList docs = _featuresDocuments.get(i); TIntArrayList freqs = _featuresFrequencies.get(i); int j = 0; int shift = 0; int doc; int rem; if (j < docs.size() && removedDocuments.hasNext()) { doc = docs.getQuick(j); rem = removedDocuments.next(); while (true) { if (doc == rem) { docs.remove(j); freqs.remove(j); if (j < docs.size() && removedDocuments.hasNext()) { doc = docs.getQuick(j); rem = removedDocuments.next(); ++shift; } else break; } else if (doc > rem) { if (removedDocuments.hasNext()) { rem = removedDocuments.next(); ++shift; } else break; } else { docs.setQuick(j, doc - shift); ++j; if (j < docs.size()) doc = docs.getQuick(j); else break; } } ++shift; } while (j < docs.size()) { docs.setQuick(j, docs.getQuick(j) - shift); ++j; } removedDocuments.begin(); } removedDocuments.begin(); while (removedDocuments.hasNext()) { int document = removedDocuments.next(); _documentFeaturesCount.remove(document); _documentLenghts.remove(document); } }
Example 10
Source File: TroveContentFullDB.java From jatecs with GNU General Public License v3.0 | 4 votes |
public void removeFeatures(IIntIterator removedFeatures) { int shift = 0; while (removedFeatures.hasNext()) { int feature = removedFeatures.next() - shift; _featuresDocuments.remove(feature); _featuresFrequencies.remove(feature); ++shift; } removedFeatures.begin(); for (int i = 0; i < _documentsFeatures.size(); ++i) { TIntArrayList feats = _documentsFeatures.get(i); TIntArrayList freqs = _documentsFrequencies.get(i); int j = 0; shift = 0; int feat; int rem; if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); while (true) { if (feat == rem) { feats.remove(j); freqs.remove(j); if (j < feats.size() && removedFeatures.hasNext()) { feat = feats.getQuick(j); rem = removedFeatures.next(); ++shift; } else break; } else if (feat > rem) { if (removedFeatures.hasNext()) { rem = removedFeatures.next(); ++shift; } else break; } else { feats.setQuick(j, feat - shift); ++j; if (j < feats.size()) feat = feats.getQuick(j); else break; } } ++shift; } while (j < feats.size()) { feats.setQuick(j, feats.getQuick(j) - shift); ++j; } removedFeatures.begin(); } _documentLenghts.clear(); }
Example 11
Source File: Incremental.java From jatecs with GNU General Public License v3.0 | 4 votes |
protected TIntDoubleHashMap nextMicroTable(ContingencyTableSet oldEvaluation, ContingencyTableSet newEvaluation) { if (oldEvaluation != null && newEvaluation != null && !oldEvaluation.equals(newEvaluation)) { ContingencyTable newContingency = newEvaluation.getGlobalContingencyTable(); ContingencyTable oldContingency = oldEvaluation.getGlobalContingencyTable(); TIntArrayList increment = new TIntArrayList(4); increment.setQuick(0, newContingency.tp() - oldContingency.tp()); increment.setQuick(1, newContingency.tn() - oldContingency.tn()); increment.setQuick(2, newContingency.fp() - oldContingency.fp()); increment.setQuick(3, newContingency.fn() - oldContingency.fn()); if (increment.getQuick(0) != 0 || increment.getQuick(1) != 0 || increment.getQuick(2) != 0 || increment.getQuick(3) != 0) { for (int j = 0; j < 4; j++) { globalContingencies[j] += increment.getQuick(j); // if (globalContingencies[j] < 0.0) { // globalContingencies[j] = 0.0; // } } double currGainFP = gain.FP(globalContingencies); double currGainFN = gain.FN(globalContingencies); //FIXME iter only on the not seen documents for (int docId = 0; docId < testSize; docId++) { if (microAlreadySeen.contains(docId)) { continue; } Iterator<Entry<Short, ClassifierRangeWithScore>> iterator = classification.getDocumentScoresAsSet(docId).iterator(); while (iterator.hasNext()) { Entry<Short, ClassifierRangeWithScore> next = iterator.next(); int catId = catMap.get(next.getKey()); ClassifierRangeWithScore value = next.getValue(); // the current gain has to be set to allow an update of the utilities if (value.score > value.border) { microUtilities[docId][catId] = currGainFP * probabilities[docId][catId]; } else if (value.score < value.border) { microUtilities[docId][catId] = currGainFN * probabilities[docId][catId]; } else { //microUtilities[docId][catId] = 1.0 * probabilities[docId][catId]; } } } } } microRankTable.clear(); //FIXME iter only on the not seen documents for (int docId = 0; docId < testSize; docId++) { if (!microAlreadySeen.contains(docId)) { double sum = 0.0; for (int i = 0; i < microUtilities[docId].length; i++) { sum += microUtilities[docId][i]; } microRankTable.put(docId, sum); } } microRank = null; return microRankTable; }
Example 12
Source File: DuplicatesInspectionBase.java From consulo with Apache License 2.0 | 4 votes |
@Override public boolean process(@Nonnull VirtualFile file, TIntArrayList list) { for(int i = 0, len = list.size(); i < len; i+=2) { ProgressManager.checkCanceled(); if (list.getQuick(i + 1) != myHash2) continue; int offset = list.getQuick(i); if (myFileIndex.isInSourceContent(virtualFile)) { if (!myFileIndex.isInSourceContent(file)) return true; if (!TestSourcesFilter.isTestSources(virtualFile, project) && TestSourcesFilter.isTestSources(file, project)) return true; if (mySkipGeneratedCode) { if (!myFileWithinGeneratedCode && GeneratedSourcesFilter.isGeneratedSourceByAnyFilter(file, project)) return true; } } else if (myFileIndex.isInSourceContent(file)) { return true; } final int startOffset = getStartOffset(myNode); final int endOffset = getEndOffset(myNode); if (file.equals(virtualFile) && offset >= startOffset && offset < endOffset) continue; PsiElement target = getPsi(myNode); TextRange rangeInElement = getRangeInElement(myNode); Integer fragmentStartOffsetInteger = startOffset; SortedMap<Integer,TextRange> map = reportedRanges.subMap(fragmentStartOffsetInteger, endOffset); int newFragmentSize = !map.isEmpty() ? 0:1; Iterator<Integer> iterator = map.keySet().iterator(); while(iterator.hasNext()) { Integer next = iterator.next(); iterator.remove(); reportedFiles.remove(next); reportedOffsetInOtherFiles.remove(next); reportedPsi.remove(next); newFragmentSize += fragmentSize.remove(next); } reportedRanges.put(fragmentStartOffsetInteger, rangeInElement); reportedFiles.put(fragmentStartOffsetInteger, file); reportedOffsetInOtherFiles.put(fragmentStartOffsetInteger, offset); reportedPsi.put(fragmentStartOffsetInteger, target); fragmentSize.put(fragmentStartOffsetInteger, newFragmentSize); if (newFragmentSize >= MIN_FRAGMENT_SIZE || isLightProfile()) { fragmentHash.put(fragmentStartOffsetInteger, (myHash & 0xFFFFFFFFL) | ((long)myHash2 << 32)); } return false; } return true; }