Search in sources :

Example 81 with BitSet

use of java.util.BitSet in project carbondata by apache.

the class BitSetGroup method and.

public void and(BitSetGroup group) {
    int i = 0;
    for (BitSet bitSet : bitSets) {
        BitSet otherSet = group.getBitSet(i);
        if (bitSet != null && otherSet != null) {
            bitSet.and(otherSet);
        } else {
            bitSets[i] = null;
        }
        i++;
    }
}
Also used : BitSet(java.util.BitSet)

Example 82 with BitSet

use of java.util.BitSet in project carbondata by apache.

the class BitSetGroup method or.

public void or(BitSetGroup group) {
    int i = 0;
    for (BitSet bitSet : bitSets) {
        BitSet otherSet = group.getBitSet(i);
        if (bitSet != null && otherSet != null) {
            bitSet.or(otherSet);
        }
        // if it is null and other set is not null then replace it.
        if (bitSet == null && otherSet != null) {
            bitSets[i] = otherSet;
        }
        i++;
    }
}
Also used : BitSet(java.util.BitSet)

Example 83 with BitSet

use of java.util.BitSet in project lucene-solr by apache.

the class BaseGeoPointTestCase method doRandomDistanceTest.

private void doRandomDistanceTest(int numDocs, int numQueries) throws IOException {
    Directory dir = newDirectory();
    IndexWriterConfig iwc = newIndexWriterConfig();
    // Else seeds may not reproduce:
    iwc.setMergeScheduler(new SerialMergeScheduler());
    int pointsInLeaf = 2 + random().nextInt(4);
    iwc.setCodec(new FilterCodec("Lucene70", TestUtil.getDefaultCodec()) {

        @Override
        public PointsFormat pointsFormat() {
            return new PointsFormat() {

                @Override
                public PointsWriter fieldsWriter(SegmentWriteState writeState) throws IOException {
                    return new Lucene60PointsWriter(writeState, pointsInLeaf, BKDWriter.DEFAULT_MAX_MB_SORT_IN_HEAP);
                }

                @Override
                public PointsReader fieldsReader(SegmentReadState readState) throws IOException {
                    return new Lucene60PointsReader(readState);
                }
            };
        }
    });
    RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
    for (int i = 0; i < numDocs; i++) {
        double latRaw = nextLatitude();
        double lonRaw = nextLongitude();
        // pre-normalize up front, so we can just use quantized value for testing and do simple exact comparisons
        double lat = quantizeLat(latRaw);
        double lon = quantizeLon(lonRaw);
        Document doc = new Document();
        addPointToDoc("field", doc, lat, lon);
        doc.add(new StoredField("lat", lat));
        doc.add(new StoredField("lon", lon));
        writer.addDocument(doc);
    }
    IndexReader reader = writer.getReader();
    IndexSearcher searcher = newSearcher(reader);
    for (int i = 0; i < numQueries; i++) {
        double lat = nextLatitude();
        double lon = nextLongitude();
        double radius = 50000000D * random().nextDouble();
        BitSet expected = new BitSet();
        for (int doc = 0; doc < reader.maxDoc(); doc++) {
            double docLatitude = reader.document(doc).getField("lat").numericValue().doubleValue();
            double docLongitude = reader.document(doc).getField("lon").numericValue().doubleValue();
            double distance = SloppyMath.haversinMeters(lat, lon, docLatitude, docLongitude);
            if (distance <= radius) {
                expected.set(doc);
            }
        }
        TopDocs topDocs = searcher.search(newDistanceQuery("field", lat, lon, radius), reader.maxDoc(), Sort.INDEXORDER);
        BitSet actual = new BitSet();
        for (ScoreDoc doc : topDocs.scoreDocs) {
            actual.set(doc.doc);
        }
        try {
            assertEquals(expected, actual);
        } catch (AssertionError e) {
            System.out.println("center: (" + lat + "," + lon + "), radius=" + radius);
            for (int doc = 0; doc < reader.maxDoc(); doc++) {
                double docLatitude = reader.document(doc).getField("lat").numericValue().doubleValue();
                double docLongitude = reader.document(doc).getField("lon").numericValue().doubleValue();
                double distance = SloppyMath.haversinMeters(lat, lon, docLatitude, docLongitude);
                System.out.println("" + doc + ": (" + docLatitude + "," + docLongitude + "), distance=" + distance);
            }
            throw e;
        }
    }
    reader.close();
    writer.close();
    dir.close();
}
Also used : Lucene60PointsWriter(org.apache.lucene.codecs.lucene60.Lucene60PointsWriter) PointsWriter(org.apache.lucene.codecs.PointsWriter) IndexSearcher(org.apache.lucene.search.IndexSearcher) Lucene60PointsReader(org.apache.lucene.codecs.lucene60.Lucene60PointsReader) SegmentReadState(org.apache.lucene.index.SegmentReadState) FixedBitSet(org.apache.lucene.util.FixedBitSet) BitSet(java.util.BitSet) IOException(java.io.IOException) Document(org.apache.lucene.document.Document) FilterCodec(org.apache.lucene.codecs.FilterCodec) ScoreDoc(org.apache.lucene.search.ScoreDoc) SerialMergeScheduler(org.apache.lucene.index.SerialMergeScheduler) TopDocs(org.apache.lucene.search.TopDocs) StoredField(org.apache.lucene.document.StoredField) PointsFormat(org.apache.lucene.codecs.PointsFormat) PointsReader(org.apache.lucene.codecs.PointsReader) Lucene60PointsReader(org.apache.lucene.codecs.lucene60.Lucene60PointsReader) IndexReader(org.apache.lucene.index.IndexReader) SegmentWriteState(org.apache.lucene.index.SegmentWriteState) Lucene60PointsWriter(org.apache.lucene.codecs.lucene60.Lucene60PointsWriter) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Example 84 with BitSet

use of java.util.BitSet in project lucene-solr by apache.

the class ReplicaAssigner method permutations.

/**
   * get all permutations for the int[] whose items are 0..level
   */
public static Iterator<int[]> permutations(final int level) {
    return new Iterator<int[]>() {

        int i = 0;

        int[] next;

        @Override
        public boolean hasNext() {
            AtomicReference<int[]> nthval = new AtomicReference<>();
            permute(0, new int[level], new BitSet(level), nthval, i, new AtomicInteger());
            i++;
            next = nthval.get();
            return next != null;
        }

        @Override
        public int[] next() {
            return next;
        }
    };
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Iterator(java.util.Iterator) BitSet(java.util.BitSet) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 85 with BitSet

use of java.util.BitSet in project lucene-solr by apache.

the class TestBytesRefHash method testCompact.

/**
   * Test method for {@link org.apache.lucene.util.BytesRefHash#compact()}.
   */
@Test
public void testCompact() {
    BytesRefBuilder ref = new BytesRefBuilder();
    int num = atLeast(2);
    for (int j = 0; j < num; j++) {
        int numEntries = 0;
        final int size = 797;
        BitSet bits = new BitSet(size);
        for (int i = 0; i < size; i++) {
            String str;
            do {
                str = TestUtil.randomRealisticUnicodeString(random(), 1000);
            } while (str.length() == 0);
            ref.copyChars(str);
            final int key = hash.add(ref.get());
            if (key < 0) {
                assertTrue(bits.get((-key) - 1));
            } else {
                assertFalse(bits.get(key));
                bits.set(key);
                numEntries++;
            }
        }
        assertEquals(hash.size(), bits.cardinality());
        assertEquals(numEntries, bits.cardinality());
        assertEquals(numEntries, hash.size());
        int[] compact = hash.compact();
        assertTrue(numEntries < compact.length);
        for (int i = 0; i < numEntries; i++) {
            bits.set(compact[i], false);
        }
        assertEquals(0, bits.cardinality());
        hash.clear();
        assertEquals(0, hash.size());
        hash.reinit();
    }
}
Also used : BitSet(java.util.BitSet) Test(org.junit.Test)

Aggregations

BitSet (java.util.BitSet)2037 Test (org.junit.Test)294 ArrayList (java.util.ArrayList)224 List (java.util.List)83 HashMap (java.util.HashMap)76 Map (java.util.Map)70 IOException (java.io.IOException)60 HashSet (java.util.HashSet)52 Test (org.junit.jupiter.api.Test)47 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)45 Random (java.util.Random)42 Configuration (org.apache.hadoop.conf.Configuration)40 Path (org.apache.hadoop.fs.Path)39 ValidReadTxnList (org.apache.hadoop.hive.common.ValidReadTxnList)33 BlockNode (jadx.core.dex.nodes.BlockNode)29 File (java.io.File)27 LinkedList (java.util.LinkedList)27 RexNode (org.apache.calcite.rex.RexNode)27 ByteBuffer (java.nio.ByteBuffer)25 ValidReaderWriteIdList (org.apache.hadoop.hive.common.ValidReaderWriteIdList)25