/** * Creates the document collapse result based on the uncollapsed docset and the collapsed docset. * * @return he document collapse result */ protected DocumentCollapseResult createDocumentCollapseResult() { long startTime = System.currentTimeMillis(); DocSet result = (docbufBitSet != null) ? new BitDocSet(docbufBitSet) : new HashDocSet(docbuf, 0, docbufSize); timeCreateDocSet = System.currentTimeMillis() - startTime; debugDocSetInfo = result.getClass().getSimpleName() + "(" + docbufSize + ")"; return new DocumentCollapseResult(result, uncollapsedDocSet); }
@Override public DocSet andNot(DocSet other) { int[] result = new int[size()]; int resultCount=0; for (int i=0; i<table.length; i++) { int id=table[i]; if (id >= 0 && !other.exists(id)) { result[resultCount++]=id; } } return new HashDocSet(result,0,resultCount); }
@Override public int intersectionSize(DocSet other) { if (other instanceof SortedIntDocSet || other instanceof HashDocSet) { return other.intersectionSize(this); } HashDocSet h = new HashDocSet(docs,offset,len); return h.intersectionSize(other); } }
@Override public DocSet intersection(DocSet other) { if (other instanceof SortedIntDocSet || other instanceof HashDocSet) { return other.intersection(this); } HashDocSet h = new HashDocSet(docs,offset,len); return h.intersection(other); }
@Override public DocSet intersection(DocSet other) { if (other instanceof HashDocSet) { // set "a" to the smallest doc set for the most efficient // intersection. final HashDocSet a = size()<=other.size() ? this : (HashDocSet)other; final HashDocSet b = size()<=other.size() ? (HashDocSet)other : this; int[] result = new int[a.size()]; int resultCount=0; for (int i=0; i<a.table.length; i++) { int id=a.table[i]; if (id >= 0 && b.exists(id)) { result[resultCount++]=id; } } return new HashDocSet(result,0,resultCount); } else { int[] result = new int[size()]; int resultCount=0; for (int i=0; i<table.length; i++) { int id=table[i]; if (id >= 0 && other.exists(id)) { result[resultCount++]=id; } } return new HashDocSet(result,0,resultCount); } }
@Override public DocSet union(DocSet other) { if (other instanceof HashDocSet) { // set "a" to the smallest doc set final HashDocSet a = size()<=other.size() ? this : (HashDocSet)other; final HashDocSet b = size()<=other.size() ? (HashDocSet)other : this; int[] result = new int[a.size()+b.size()]; int resultCount=0; // iterate over the largest table first, adding w/o checking. for (int i=0; i<b.table.length; i++) { int id=b.table[i]; if (id>=0) result[resultCount++]=id; } // now iterate over smaller set, adding all not already in larger set. for (int i=0; i<a.table.length; i++) { int id=a.table[i]; if (id>=0 && !b.exists(id)) result[resultCount++]=id; } return new HashDocSet(result,0,resultCount); } else { return other.union(this); } }