/** * Performs a binary search for <tt>value</tt> in the entire list. * Note that you <b>must</b> {@link #sort sort} the list before * doing a search. * * @param value the value to search for * @return the absolute offset in the list of the value, or its * negative insertion point into the sorted list. */ public int binarySearch(int value) { return binarySearch(value, 0, _pos); }
/** * Le contenu de ce modele doit etre trie. * * @param _intValue l'indice a rechercher * @return true si contenu */ protected boolean binaryContains(final int _intValue) { return list_.binarySearch(_intValue) >= 0; }
protected int binarySearch(final int _idxToTest) { return list_.binarySearch(_idxToTest); }
public boolean hasCategoryFeature(short category, int feature) { if (_hasLocalRepresentation) return _categoriesFeatures.get(category).binarySearch(feature) < 0; else return true; }
public boolean hasDocumentFeature(int document, int feature) { return _documentsFeatures.get(document).binarySearch(feature) >= 0; }
public boolean hasDocumentCategory(int document, short category) { if (category < _categoriesDocuments.size()) return (_categoriesDocuments.get(category).binarySearch(document)) >= 0; else return false; }
public boolean hasDocumentFeature(int document, int feature) { if (feature < _featuresDocuments.size()) return _featuresDocuments.get(feature).binarySearch(document) >= 0; else return false; }
public boolean isPrimaryCategory(int document, short category) { if (category < _categoriesDocumentsPrimary.size()) { int pos = _categoriesDocuments.get(category).binarySearch(document); if (pos < 0) return false; else return _categoriesDocumentsPrimary.get(category).get(pos); } else return false; } }
public int getDocumentFeatureFrequency(int document, int feature) { if (document < _documentsFeatures.size()) { int pos = _documentsFeatures.get(document).binarySearch(feature); if (pos >= 0) return _documentsFrequencies.get(document).getQuick(pos); else return 0; } else return 0; }
public int getFreq(int docid) { int index = pl_doc.binarySearch(docid); if (index >= 0) { return pl_freq.get(index); } return -1; }
public boolean hasDocumentFeature(int document, int feature) { try { return _documentsFeatures.get(document).binarySearch(feature) >= 0; } catch (ArrayIndexOutOfBoundsException e) { _documentsFeatures.add(new TIntArrayList()); return false; } }
public int getDocumentFeatureFrequency(int document, int feature) { if (feature < _featuresDocuments.size()) { int pos = _featuresDocuments.get(feature).binarySearch(document); if (pos >= 0) return _featuresFrequencies.get(feature).getQuick(pos); else return 0; } else return 0; }
public int getDocumentFeatureFrequency(int document, int feature) { if (document < _documentsFeatures.size()) { int pos = _documentsFeatures.get(document).binarySearch(feature); if (pos >= 0) return _documentsFrequencies.get(document).getQuick(pos); else return 0; } else return 0; }
protected void addCategoryHierarchicaly(int document, short category, boolean primary) { TIntArrayList docs = _classificationDB._categoriesDocuments.get(category); Vector<Boolean> docsPrimary = _classificationDB._categoriesDocumentsPrimary.get(category); int pos = docs.binarySearch(document); if (pos < 0) { docs.insert(-pos - 1, document); docsPrimary.insertElementAt(primary, -pos - 1); } else { if (primary) { docsPrimary.set(pos, true); } } IShortIterator parents = _classificationDB.getCategoryDB().getParentCategories(category); while (parents.hasNext()) addCategoryHierarchicaly(document, parents.next(), primary); }
public void removeCategoryFeatures(short category, IIntIterator removedFeatures) { TIntArrayList feats = _categoriesFeatures.get(category); while (removedFeatures.hasNext()) { int feature = removedFeatures.next(); if (feats.binarySearch(feature) < 0) feats.add(feature); } feats.sort(); _hasLocalRepresentation = _hasLocalRepresentation || feats.size() > 0; }
protected void addCategoryHierarchicaly(int document, short category, boolean primary) { TShortArrayList cats = _classificationDB._documentsCategories.get(document); Vector<Boolean> catsPrimary = _classificationDB._documentsCatsPrimary.get(document); int pos = cats.binarySearch(category); if (pos < 0) { cats.insert(-pos - 1, category); catsPrimary.insertElementAt(primary, -pos - 1); } else { if (primary) { catsPrimary.set(pos, true); } } TIntArrayList docs = _classificationDB._categoriesDocuments.get(category); pos = docs.binarySearch(document); if (pos < 0) { docs.insert(-pos - 1, document); } IShortIterator parents = _classificationDB.getCategoryDB().getParentCategories(category); while (parents.hasNext()) addCategoryHierarchicaly(document, parents.next(), primary); }
/** Returns true iff we did not already have a posting for this document */ public boolean addOrUpdateFreq(int docid, int freq) { int index = pl_doc.binarySearch(docid); if (index >= 0) { pl_freq.setQuick(index, freq + pl_freq.get(index)); return false; } else { pl_doc.insert( -(index +1), docid); pl_freq.insert( -(index +1), freq); return true; } }
public void setDocumentFeatureFrequency(int document, int feature, int frequency) { if (document >= 0) { int size = _contentDB._documentsFeatures.size(); if (document >= size) { for (int i = size; i <= document; ++i) { _contentDB._documentsFeatures.add(new TIntArrayList()); _contentDB._documentsFrequencies.add(new TIntArrayList()); } } if (feature >= 0) { TIntArrayList feats = _contentDB._documentsFeatures.get(document); TIntArrayList freqs = _contentDB._documentsFrequencies.get(document); int pos = feats.binarySearch(feature); if (pos < 0 && frequency > 0) { pos = -pos - 1; feats.insert(pos, feature); freqs.insert(pos, frequency); } else { if (frequency > 0) { freqs.setQuick(pos, frequency); } else { feats.remove(pos); freqs.remove(pos); } } } } }
public void setDocumentFeatureFrequency(int document, int feature, int frequency) { if (feature >= 0) { int size = _contentDB._featuresDocuments.size(); if (feature >= size) { for (int i = size; i <= feature; ++i) { _contentDB._featuresDocuments.add(new TIntArrayList()); _contentDB._featuresFrequencies.add(new TIntArrayList()); } } if (document >= 0) { TIntArrayList docs = _contentDB._featuresDocuments.get(feature); TIntArrayList freqs = _contentDB._featuresFrequencies .get(feature); int pos = docs.binarySearch(document); if (pos < 0 && frequency > 0) { pos = -pos - 1; docs.insert(pos, document); freqs.insert(pos, frequency); } else { if (frequency > 0) { freqs.setQuick(pos, frequency); } else { docs.remove(pos); freqs.remove(pos); } } } } }
public int getDocumentLength(int document) { if (_documentLenghts.containsKey(document)) return _documentLenghts.get(document); else { IIntIterator featIt = _featuresDB.getFeatures(); int length = 0; while (featIt.hasNext()) { int feature = featIt.next(); int pos = _featuresDocuments.get(feature) .binarySearch(document); if (pos >= 0) length += _featuresFrequencies.get(feature).getQuick(pos); } _documentLenghts.put(document, length); return length; } }