faster HashDocSet.unionSize

git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@413394 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2006-06-11 01:15:47 +00:00
parent e63135a59f
commit 2f9eb801ba
2 changed files with 32 additions and 2 deletions

View File

@ -30,8 +30,9 @@ Optimizations
2. BitDocSet.intersectionSize(HashDocSet) no longer generates an intermediate
set
3. OpenBitSet completed, replaces BitSet as the implementation for BitDocSet.
Iteration is faster, and BitDocSet.intersectionSize(BitDocSet)
Iteration is faster, and BitDocSet.intersectionSize(BitDocSet) and unionSize
is between 3 and 4 times faster. (yonik, SOLR-15)
4. much faster unionSize when one of the sets is a HashDocSet: O(smaller_set_size)
Bug Fixes
1. Fixed delete-by-id for field types who's indexed form is different

View File

@ -212,7 +212,7 @@ public final class HashDocSet extends DocSetBase {
return (tablesize<<2) + 20;
}
@Override
public DocSet intersection(DocSet other) {
if (other instanceof HashDocSet) {
// set "a" to the smallest doc set for the most efficient
@ -245,6 +245,7 @@ public final class HashDocSet extends DocSetBase {
}
@Override
public int intersectionSize(DocSet other) {
if (other instanceof HashDocSet) {
// set "a" to the smallest doc set for the most efficient
@ -273,5 +274,33 @@ public final class HashDocSet extends DocSetBase {
}
@Override
public int unionSize(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=b.size();
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=other.size();
for (int i=0; i<table.length; i++) {
int id=table[i];
if (id >= 0 && !other.exists(id)) {
resultCount++;
}
}
return resultCount;
}
}
}