Apache Lucene open-source search software
faster HashDocSet.unionSize
Yonik Seeley2f9eb801bac2
diff --git a/CHANGES.txt b/CHANGES.txtindex b667825c293..fcc89de12c7 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -30,8 +30,9 @@ Optimizations2. BitDocSet.intersectionSize(HashDocSet) no longer generates an intermediateset3. OpenBitSet completed, replaces BitSet as the implementation for BitDocSet.- Iteration is faster, and BitDocSet.intersectionSize(BitDocSet)+ Iteration is faster, and BitDocSet.intersectionSize(BitDocSet) and unionSizeis 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 Fixes1. Fixed delete-by-id for field types who's indexed form is differentdiff --git a/src/java/org/apache/solr/search/HashDocSet.java b/src/java/org/apache/solr/search/HashDocSet.javaindex 14991d72cee..97962bd3b37 100644--- a/src/java/org/apache/solr/search/HashDocSet.java+++ b/src/java/org/apache/solr/search/HashDocSet.java@@ -212,7 +212,7 @@ public final class HashDocSet extends DocSetBase {return (tablesize<<2) + 20;}-+ @Overridepublic 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 {}+ @Overridepublic 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;+ }+ }+}