/** * A faster version of size() when there are lots of subtypes * The cache must be already set up * * Guess by adding the sizes of up to the first 3 type/subtypes, * then add 1 more for each subtype in addition. * * @return a guess at the size, done quickly */ int guessedSize() { final ArrayList<FSLeafIndexImpl<? extends T>> localIc = this.cachedSubFsLeafIndexes; final int len = localIc.size(); final int lim = Math.min(3, len); int size = 0; for (int i = 0; i < lim; i++) { size += localIc.get(i).size(); } size += len - lim; return size; }
boolean has1OrMoreEntries() { createIndexIteratorCache(); // does nothing if already created final ArrayList<FSLeafIndexImpl<? extends T>> localIc = this.cachedSubFsLeafIndexes; final int len = localIc.size(); for (int i = 0; i < len; i++) { if (localIc.get(i).size() > 0) { return true; }; } return false; }
/** * * @return the sum of the sizes of the indexes of the type + all subtypes */ int size() { int size = 0; createIndexIteratorCache(); // does nothing if already created final ArrayList<FSLeafIndexImpl<? extends T>> localIc = this.cachedSubFsLeafIndexes; final int len = localIc.size(); for (int i = 0; i < len; i++) { size += localIc.get(i).size(); } return size; }
public int getIndexSize(Type type) { final int typeCode = ((TypeImpl) type).getCode(); final ArrayList<IndexIteratorCachePair<? extends FeatureStructure>> indexVector = this.indexArray[typeCode]; if (indexVector.size() == 0) { // No index for this type exists. return 0; } int numFSs = indexVector.get(0).fsLeafIndex.size(); final Vector<Type> typeVector = this.sii.tsi.getDirectlySubsumedTypes(type); final int max = typeVector.size(); for (int i = 0; i < max; i++) { numFSs += getIndexSize(typeVector.get(i)); } return numFSs; }
private ComparableIntPointerIterator[] initPointerIterator() { // Note to maintainers: Make sure the iterator cache exists on all paths calling this final ArrayList<?> cachedSubIndexes = iicp.cachedSubFsLeafIndexes; final int length = cachedSubIndexes.size(); final ArrayList<ComparableIntPointerIterator> pia = new ArrayList<ComparableIntPointerIterator>(cachedSubIndexes.size()); // put all non-empty leaf iterators into the iteration, and if all are empty, put the last one in // (to avoid handling 0 as a special case) for (int i = 0; i < length; i++) { final FSLeafIndexImpl<?> leafIndex = (FSLeafIndexImpl<?>) cachedSubIndexes.get(i); if ((leafIndex.size() > 0) || ((i == length -1) && // this logic puts in the last one if all are empty (0 == pia.size()))) { pia.add(leafIndex.pointerIterator( this.iteratorComparator, FSIndexRepositoryImpl.this.detectIllegalIndexUpdates, ((TypeImpl) leafIndex.getType()).getCode())); } } ComparableIntPointerIterator[] piaa = new ComparableIntPointerIterator[pia.size()]; return pia.toArray(piaa); }