<commit_before>/**
 * Copyright 2006 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.solr.search.test;

import org.apache.solr.search.BitDocSet;
import org.apache.solr.search.HashDocSet;
import org.apache.solr.search.DocSet;
import org.apache.solr.util.OpenBitSet;

import java.util.Random;
import java.util.BitSet;

/**
 * @author yonik
 */
public class TestDocSet {

  // use test instead of assert since asserts may be turned off
  public static void test(boolean condition) {
      if (!condition) {
        throw new RuntimeException("test requestHandler: assertion failed!");
      }
  }

  static Random rand = new Random();


  static OpenBitSet bs;
  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);
        if (!bs.get(id)) {
          bs.fastSet(id);
          ids[count++]=id;
        }
      }
    }
    bds = new BitDocSet(bs,bitsToSet);
    hds = new HashDocSet(ids,0,count);
  }



  public static void main(String[] args) {
    String bsSize=args[0];
    boolean randSize=false;

    if (bsSize.endsWith("-")) {
      bsSize=bsSize.substring(0,bsSize.length()-1);
      randSize=true;
    }

    int bitSetSize = Integer.parseInt(bsSize);
    int numSets = Integer.parseInt(args[1]);
    int numBitsSet = Integer.parseInt(args[2]);
    String test = args[3].intern();
    int iter = Integer.parseInt(args[4]);

    int ret=0;

    OpenBitSet[] sets = new OpenBitSet[numSets];
    DocSet[] bset = new DocSet[numSets];
    DocSet[] hset = new DocSet[numSets];
    BitSet scratch=new BitSet();

    for (int i=0; i<numSets; i++) {
      generate(randSize ? rand.nextInt(bitSetSize) : bitSetSize, numBitsSet);
      sets[i] = bs;
      bset[i] = bds;
      hset[i] = hds;
    }

    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();
        }
      }
    }



    long end = System.currentTimeMillis();
    System.out.println("TIME="+(end-start));

    // System.out.println("ret="+ret + " scratchsize="+scratch.size());
    System.out.println("ret="+ret);
  }



}
<commit_msg>fix class name after svn mv<commit_after>/**
 * Copyright 2006 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.solr.search.test;

import org.apache.solr.search.BitDocSet;
import org.apache.solr.search.HashDocSet;
import org.apache.solr.search.DocSet;
import org.apache.solr.util.OpenBitSet;

import java.util.Random;
import java.util.BitSet;

/**
 * @author yonik
 */
public class DocSetPerf {

  // use test instead of assert since asserts may be turned off
  public static void test(boolean condition) {
      if (!condition) {
        throw new RuntimeException("test requestHandler: assertion failed!");
      }
  }

  static Random rand = new Random();


  static OpenBitSet bs;
  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);
        if (!bs.get(id)) {
          bs.fastSet(id);
          ids[count++]=id;
        }
      }
    }
    bds = new BitDocSet(bs,bitsToSet);
    hds = new HashDocSet(ids,0,count);
  }



  public static void main(String[] args) {
    String bsSize=args[0];
    boolean randSize=false;

    if (bsSize.endsWith("-")) {
      bsSize=bsSize.substring(0,bsSize.length()-1);
      randSize=true;
    }

    int bitSetSize = Integer.parseInt(bsSize);
    int numSets = Integer.parseInt(args[1]);
    int numBitsSet = Integer.parseInt(args[2]);
    String test = args[3].intern();
    int iter = Integer.parseInt(args[4]);

    int ret=0;

    OpenBitSet[] sets = new OpenBitSet[numSets];
    DocSet[] bset = new DocSet[numSets];
    DocSet[] hset = new DocSet[numSets];
    BitSet scratch=new BitSet();

    for (int i=0; i<numSets; i++) {
      generate(randSize ? rand.nextInt(bitSetSize) : bitSetSize, numBitsSet);
      sets[i] = bs;
      bset[i] = bds;
      hset[i] = hds;
    }

    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();
        }
      }
    }



    long end = System.currentTimeMillis();
    System.out.println("TIME="+(end-start));

    // System.out.println("ret="+ret + " scratchsize="+scratch.size());
    System.out.println("ret="+ret);
  }



}

{'fraction_non_alphanumeric': 0.14599406528189912, 'fraction_numerical': 0.009693372898120672, 'mean_word_length': 2.6318247126436782, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5758251', 'n_tokens_mistral': 3431, 'n_tokens_neox': 3366, 'n_words': 765}