@Override public boolean get(int index) { return docSet.exists(index); }
@Override public boolean get(int index) { return docSet.exists(index); }
public boolean exists(int docid) { return docSet.exists(docid); }
@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); }
if (other.exists(docs[i])) icount++;
@Override public DocSet intersection(DocSet other) { if (!(other instanceof SortedIntDocSet)) { int icount = 0; int arr[] = new int[docs.length]; for (int i=0; i<docs.length; i++) { int doc = docs[i]; if (other.exists(doc)) arr[icount++] = doc; } return new SortedIntDocSet(arr,icount); } int[] otherDocs = ((SortedIntDocSet)other).docs; int maxsz = Math.min(docs.length, otherDocs.length); int[] arr = new int[maxsz]; int sz = intersection(docs, docs.length, otherDocs, otherDocs.length, arr); return new SortedIntDocSet(arr,sz); }
@Override public DocSet andNot(DocSet other) { if (other.size()==0) return this; if (!(other instanceof SortedIntDocSet)) { int count = 0; int arr[] = new int[docs.length]; for (int i=0; i<docs.length; i++) { int doc = docs[i]; if (!other.exists(doc)) arr[count++] = doc; } return new SortedIntDocSet(arr,count); } int[] otherDocs = ((SortedIntDocSet)other).docs; int[] arr = new int[docs.length]; int sz = andNot(docs, docs.length, otherDocs, otherDocs.length, arr); return new SortedIntDocSet(arr,sz); }
@Override public int intersectionSize(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 resultCount=0; for (int i=0; i<a.table.length; i++) { int id=a.table[i]; if (id >= 0 && b.exists(id)) { resultCount++; } } return resultCount; } else { int resultCount=0; for (int i=0; i<table.length; i++) { int id=table[i]; if (id >= 0 && other.exists(id)) { resultCount++; } } return resultCount; } }
@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); } }
c=0; while (td.next()) { if (docs.exists(td.doc())) c++;