Package org.apache.lucene.util

Examples of org.apache.lucene.util.OpenBitSet


  // query must be positive
  protected DocSet getDocSetNC(Query query, DocSet filter, TermDocsState tdState) throws IOException {
    int smallSetSize = maxDoc()>>6;
    int largestPossible = tdState.tenum.docFreq();
    int[] docs = new int[Math.min(smallSetSize, largestPossible)];
    OpenBitSet obs = null;
    int upto=0;
    int numBits = 0;

    if (tdState.tdocs == null) {
      tdState.tdocs = reader.termDocs();
    }

    tdState.tdocs.seek(tdState.tenum);

    int[] arr = new int[Math.min(largestPossible, 256)];
    int[] freq = new int[arr.length];

    for(;;) {
      int num = tdState.tdocs.read(arr, freq);
      if (num==0) break;
      if (upto + num > docs.length) {
        if (obs == null) obs = new OpenBitSet(maxDoc());
        for (int i = 0; i<num; i++) {
          obs.fastSet(arr[i]);
        }
        numBits += num;
      } else {
        System.arraycopy(arr, 0, docs, upto, num);
        upto += num;
      }
    }

    if (obs != null) {
      for (int i=0; i<upto; i++) {
        obs.fastSet(docs[i]);
      }
      numBits += upto;
      return new BitDocSet(obs, numBits);
    }
View Full Code Here


  * Converts a filter into a DocSet.
  * This method is not cache-aware and no caches are checked.
  */
  public DocSet convertFilter(Filter lfilter) throws IOException {
    DocIdSet docSet = lfilter.getDocIdSet(this.reader);
    OpenBitSet obs = new OpenBitSet();
    DocIdSetIterator it = docSet.iterator();
    int doc;
    while((doc = it.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
      obs.fastSet(doc);
    }
    return new BitDocSet(obs);
  }
View Full Code Here

  public final static ScoredDocIDs getComplementSet(final ScoredDocIDs docids, final IndexReader reader)
  throws IOException {
    final int maxDoc = reader.maxDoc();

    DocIdSet docIdSet = docids.getDocIDs();
    final OpenBitSet complement;
    if (docIdSet instanceof OpenBitSet) {
      // That is the most common case, if ScoredDocIdsCollector was used.
      complement = (OpenBitSet) ((OpenBitSet) docIdSet).clone();
    } else {
      complement = new OpenBitSetDISI(docIdSet.iterator(), maxDoc);
    }

    complement.flip(0, maxDoc);

    // Remove all Deletions from the complement set
    clearDeleted(reader, complement);

    return createScoredDocIds(complement, maxDoc);
View Full Code Here

  static BitDocSet bds;
  static HashDocSet hds;
  static int[] ids; // not unique

  static void generate(int maxSize, int bitsToSet) {
    bs = new OpenBitSet(maxSize);
    ids = new int[bitsToSet];
    int count=0;
    if (maxSize>0) {
      for (int i=0; i<bitsToSet; i++) {
        int id=rand.nextInt(maxSize);
View Full Code Here

    long start = System.currentTimeMillis();

    if ("test".equals(test)) {
      for (int it=0; it<iter; it++) {
        generate(randSize ? rand.nextInt(bitSetSize) : bitSetSize, numBitsSet);
        OpenBitSet bs1=bs;
        BitDocSet bds1=bds;
        HashDocSet hds1=hds;
        generate(randSize ? rand.nextInt(bitSetSize) : bitSetSize, numBitsSet);

        OpenBitSet res = ((OpenBitSet)bs1.clone());
        res.and(bs);
        int icount = (int)res.cardinality();

        test(bds1.intersection(bds).size() == icount);
        test(bds1.intersectionSize(bds) == icount);
        if (bds1.intersection(hds).size() != icount) {
          DocSet ds = bds1.intersection(hds);
          System.out.println("STOP");
        }

        test(bds1.intersection(hds).size() == icount);
        test(bds1.intersectionSize(hds) == icount);
        test(hds1.intersection(bds).size() == icount);
        test(hds1.intersectionSize(bds) == icount);
        test(hds1.intersection(hds).size() == icount);
        test(hds1.intersectionSize(hds) == icount);

        ret += icount;
      }
    }

    String type=null;
    String oper=null;

    if (test.endsWith("B")) { type="B"; }
    if (test.endsWith("H")) { type="H"; }
    if (test.endsWith("M")) { type="M"; }
    if (test.startsWith("intersect")) oper="intersect";
    if (test.startsWith("intersectSize")) oper="intersectSize";
    if (test.startsWith("intersectAndSize")) oper="intersectSize";


    if (oper!=null) {
      for (int it=0; it<iter; it++) {
        int idx1 = rand.nextInt(numSets);
        int idx2 = rand.nextInt(numSets);
        DocSet a=null,b=null;

        if (type=="B") {
          a=bset[idx1]; b=bset[idx2];
        } else if (type=="H") {
          a=hset[idx1]; b=bset[idx2];
        } else if (type=="M") {
          if (idx1 < idx2) {
            a=bset[idx1];
            b=hset[idx2];
          } else {
            a=hset[idx1];
            b=bset[idx2];
          }
        }

        if (oper=="intersect") {
          DocSet res = a.intersection(b);
          ret += res.memSize();
        } else if (oper=="intersectSize") {
          ret += a.intersectionSize(b);
        } else if (oper=="intersectAndSize") {
          DocSet res = a.intersection(b);
          ret += res.size();
        }
      }
    }

View Full Code Here

public class TestDocSet extends TestCase {
  Random rand = new Random();
  float loadfactor;

  public OpenBitSet getRandomSet(int sz, int bitsToSet) {
    OpenBitSet bs = new OpenBitSet(sz);
    if (sz==0) return bs;
    for (int i=0; i<bitsToSet; i++) {
      bs.fastSet(rand.nextInt(sz));
    }
    return bs;
  }
View Full Code Here

  }

  protected void doSingle(int maxSize) {
    int sz = rand.nextInt(maxSize+1);
    int sz2 = rand.nextInt(maxSize);
    OpenBitSet bs1 = getRandomSet(sz, rand.nextInt(sz+1));
    OpenBitSet bs2 = getRandomSet(sz, rand.nextInt(sz2+1));

    DocSet a1 = new BitDocSet(bs1);
    DocSet a2 = new BitDocSet(bs2);
    DocSet b1 = getDocSet(bs1);
    DocSet b2 = getDocSet(bs2);

    checkEqual(bs1,b1);
    checkEqual(bs2,b2);

    iter(a1,b1);
    iter(a2,b2);

    OpenBitSet a_and = (OpenBitSet) bs1.clone(); a_and.and(bs2);
    OpenBitSet a_or = (OpenBitSet) bs1.clone(); a_or.or(bs2);
    // OpenBitSet a_xor = (OpenBitSet)bs1.clone(); a_xor.xor(bs2);
    OpenBitSet a_andn = (OpenBitSet) bs1.clone(); a_andn.andNot(bs2);

    checkEqual(a_and, b1.intersection(b2));
    checkEqual(a_or, b1.union(b2));
    checkEqual(a_andn, b1.andNot(b2));

    assertEquals(a_and.cardinality(), b1.intersectionSize(b2));
    assertEquals(a_or.cardinality(), b1.unionSize(b2));
    assertEquals(a_andn.cardinality(), b1.andNotSize(b2));
  }
View Full Code Here

    doMany(130, 10000);
    // doMany(130, 1000000);
  }

  public DocSet getRandomDocSet(int n, int maxDoc) {
    OpenBitSet obs = new OpenBitSet(maxDoc);
    int[] a = new int[n];
    for (int i=0; i<n; i++) {
      for(;;) {
        int idx = rand.nextInt(maxDoc);
        if (obs.getAndSet(idx)) continue;
        a[i]=idx;
        break;
      }
    }
View Full Code Here

      }
    }
  }

  public void doFilterTest(SolrIndexReader reader) throws IOException {
    OpenBitSet bs = getRandomSet(reader.maxDoc(), rand.nextInt(reader.maxDoc()+1));
    DocSet a = new BitDocSet(bs);
    DocSet b = getIntDocSet(bs);

    Filter fa = a.getTopFilter();
    Filter fb = b.getTopFilter();
View Full Code Here

    BitSet[] sets = new BitSet[numSets];
    OpenBitSet[] osets = new OpenBitSet[numSets];

    for (int i=0; i<numSets; i++) {
      sets[i] = new BitSet(bitSetSize);
      osets[i] = new OpenBitSet(bitSetSize);
      randomSets(bitSetSize, numBitsSet, sets[i], osets[i]);
    }

    BitSet bs = new BitSet(bitSetSize);
    OpenBitSet obs = new OpenBitSet(bitSetSize);
    randomSets(bitSetSize, numBitsSet, bs, obs);



    int ret=0;

    long start = System.currentTimeMillis();

    if ("union".equals(test)) {
      for (int it=0; it<iter; it++) {
        for (int i=0; i<numSets; i++) {
          if (impl=="open") {
            OpenBitSet other=osets[i];
            obs.union(other);
          } else {
            BitSet other=sets[i];
            bs.or(other);
          }
        }
      }
    }

    if ("cardinality".equals(test)) {
      for (int it=0; it<iter; it++) {
        for (int i=0; i<numSets; i++) {
          if (impl=="open") {
            ret += osets[i].cardinality();
          } else {
            ret += sets[i].cardinality();
          }
        }
      }
    }

    if ("get".equals(test)) {
      for (int it=0; it<iter; it++) {
        for (int i=0; i<numSets; i++) {
          if (impl=="open") {
            OpenBitSet oset = osets[i];
            for (int k=0; k<bitSetSize; k++) if (oset.fastGet(k)) ret++;
          } else {
            BitSet bset = sets[i];
            for (int k=0; k<bitSetSize; k++) if (bset.get(k)) ret++;
          }
        }
      }
    }

    if ("icount".equals(test)) {
      for (int it=0; it<iter; it++) {
        for (int i=0; i<numSets-1; i++) {
          if (impl=="open") {
            OpenBitSet a=osets[i];
            OpenBitSet b=osets[i+1];
            ret += OpenBitSet.intersectionCount(a,b);
          } else {
            BitSet a=sets[i];
            BitSet b=sets[i+1];
            BitSet newset = (BitSet)a.clone();
            newset.and(b);
            ret += newset.cardinality();
          }
        }
      }
    }

    if ("clone".equals(test)) {
      for (int it=0; it<iter; it++) {
        for (int i=0; i<numSets; i++) {
          if (impl=="open") {
            osets[i] = (OpenBitSet)osets[i].clone();
          } else {
            sets[i] = (BitSet)sets[i].clone();
          }
        }
      }
    }

    if ("nextSetBit".equals(test)) {
      for (int it=0; it<iter; it++) {
        for (int i=0; i<numSets; i++) {
          if (impl=="open") {
            final OpenBitSet set = osets[i];
            for(int next=set.nextSetBit(0); next>=0; next=set.nextSetBit(next+1)) {
              ret += next;
            }
          } else {
            final BitSet set = sets[i];
            for(int next=set.nextSetBit(0); next>=0; next=set.nextSetBit(next+1)) {
              ret += next;
            }
          }
        }
      }
    }


    if ("iterator".equals(test)) {
      for (int it=0; it<iter; it++) {
        for (int i=0; i<numSets; i++) {
          if (impl=="open") {
            final OpenBitSet set = osets[i];
            final OpenBitSetIterator iterator = new OpenBitSetIterator(set);
            for(int next=iterator.nextDoc(); next>=0; next=iterator.nextDoc()) {
              ret += next;
            }
          } else {
            final BitSet set = sets[i];
            for(int next=set.nextSetBit(0); next>=0; next=set.nextSetBit(next+1)) {
              ret += next;
            }
          }
        }
      }
View Full Code Here

TOP

Related Classes of org.apache.lucene.util.OpenBitSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.