|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BitVector | Line # 36 | 28 | 10 | 100% |
1.0
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (24) | |||
| Result | |||
|
0.925
|
org.apache.lucene.util.TestBitVector.testWriteRead
org.apache.lucene.util.TestBitVector.testWriteRead
|
1 PASS | |
|
0.925
|
org.apache.lucene.index.TestIndexWriterMergePolicy.testMergeDocCount0
org.apache.lucene.index.TestIndexWriterMergePolicy.testMergeDocCount0
|
1 PASS | |
|
0.925
|
org.apache.lucene.search.TestMultiSearcher.testEmptyIndex
org.apache.lucene.search.TestMultiSearcher.testEmptyIndex
|
1 PASS | |
|
0.925
|
org.apache.lucene.index.TestIndexModifier.testIndex
org.apache.lucene.index.TestIndexModifier.testIndex
|
1 PASS | |
|
0.925
|
org.apache.lucene.index.TestIndexWriter.testDocCount
org.apache.lucene.index.TestIndexWriter.testDocCount
|
1 PASS | |
|
0.925
|
org.apache.lucene.index.TestAddIndexesNoOptimize.testMergeAfterCopy
org.apache.lucene.index.TestAddIndexesNoOptimize.testMergeAfterCopy
|
1 PASS | |
|
0.925
|
org.apache.lucene.index.TestAddIndexesNoOptimize.testMoreMerges
org.apache.lucene.index.TestAddIndexesNoOptimize.testMoreMerges
|
1 PASS | |
|
0.925
|
org.apache.lucene.search.TestMultiSearcher.testEmptyIndex
org.apache.lucene.search.TestMultiSearcher.testEmptyIndex
|
1 PASS | |
|
0.925
|
org.apache.lucene.index.TestIndexModifier.testIndexWithThreads
org.apache.lucene.index.TestIndexModifier.testIndexWithThreads
|
1 PASS | |
|
0.9
|
org.apache.lucene.index.TestIndexReader.testDeleteReaderWriterConflictOptimized
org.apache.lucene.index.TestIndexReader.testDeleteReaderWriterConflictOptimized
|
1 PASS | |
|
0.9
|
org.apache.lucene.index.TestIndexReader.testDeleteReaderReaderConflictUnoptimized
org.apache.lucene.index.TestIndexReader.testDeleteReaderReaderConflictUnoptimized
|
1 PASS | |
|
0.9
|
org.apache.lucene.index.TestIndexReader.testDeleteReaderWriterConflictUnoptimized
org.apache.lucene.index.TestIndexReader.testDeleteReaderWriterConflictUnoptimized
|
1 PASS | |
|
0.9
|
org.apache.lucene.index.TestIndexReader.testDeleteReaderReaderConflictOptimized
org.apache.lucene.index.TestIndexReader.testDeleteReaderReaderConflictOptimized
|
1 PASS | |
|
0.9
|
org.apache.lucene.index.TestIndexReader.testBasicDelete
org.apache.lucene.index.TestIndexReader.testBasicDelete
|
1 PASS | |
|
0.7
|
org.apache.lucene.search.TestMatchAllDocsQuery.testQuery
org.apache.lucene.search.TestMatchAllDocsQuery.testQuery
|
1 PASS | |
|
0.675
|
org.apache.lucene.document.TestBinaryDocument.testBinaryFieldInIndex
org.apache.lucene.document.TestBinaryDocument.testBinaryFieldInIndex
|
1 PASS | |
|
0.65
|
org.apache.lucene.index.TestIndexReader.testLock
org.apache.lucene.index.TestIndexReader.testLock
|
1 PASS | |
|
0.625
|
org.apache.lucene.util.TestBitVector.testCount
org.apache.lucene.util.TestBitVector.testCount
|
1 PASS | |
|
0.475
|
org.apache.lucene.index.TestSegmentReader.testDelete
org.apache.lucene.index.TestSegmentReader.testDelete
|
1 PASS | |
|
0.425
|
org.apache.lucene.index.TestMultiReader.testUndeleteAll
org.apache.lucene.index.TestMultiReader.testUndeleteAll
|
1 PASS | |
|
0.325
|
org.apache.lucene.util.TestBitVector.testClear
org.apache.lucene.util.TestBitVector.testClear
|
1 PASS | |
|
0.25
|
org.apache.lucene.util.TestBitVector.testGetSet
org.apache.lucene.util.TestBitVector.testGetSet
|
1 PASS | |
|
0.15
|
org.apache.lucene.index.TestIndexReader.testUndeleteAll
org.apache.lucene.index.TestIndexReader.testUndeleteAll
|
1 PASS | |
|
0.125
|
org.apache.lucene.util.TestBitVector.testConstructSize
org.apache.lucene.util.TestBitVector.testConstructSize
|
1 PASS | |
| 1 | package org.apache.lucene.util; | |
| 2 | ||
| 3 | /** | |
| 4 | * Copyright 2004 The Apache Software Foundation | |
| 5 | * | |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 7 | * you may not use this file except in compliance with the License. | |
| 8 | * You may obtain a copy of the License at | |
| 9 | * | |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 11 | * | |
| 12 | * Unless required by applicable law or agreed to in writing, software | |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 15 | * See the License for the specific language governing permissions and | |
| 16 | * limitations under the License. | |
| 17 | */ | |
| 18 | ||
| 19 | import java.io.IOException; | |
| 20 | ||
| 21 | import org.apache.lucene.store.Directory; | |
| 22 | import org.apache.lucene.store.IndexInput; | |
| 23 | import org.apache.lucene.store.IndexOutput; | |
| 24 | ||
| 25 | /** Optimized implementation of a vector of bits. This is more-or-less like | |
| 26 | java.util.BitSet, but also includes the following: | |
| 27 | <ul> | |
| 28 | <li>a count() method, which efficiently computes the number of one bits;</li> | |
| 29 | <li>optimized read from and write to disk;</li> | |
| 30 | <li>inlinable get() method;</li> | |
| 31 | </ul> | |
| 32 | ||
| 33 | @author Doug Cutting | |
| 34 | @version $Id: BitVector.java 150536 2004-09-28 18:15:52Z cutting $ | |
| 35 | */ | |
| 36 | public final class BitVector { | |
| 37 | ||
| 38 | private byte[] bits; | |
| 39 | private int size; | |
| 40 | private int count = -1; | |
| 41 | ||
| 42 | /** Constructs a vector capable of holding <code>n</code> bits. */ | |
| 43 | 837 |
public BitVector(int n) { |
| 44 | 837 | size = n; |
| 45 | 837 | bits = new byte[(size >> 3) + 1]; |
| 46 | } | |
| 47 | ||
| 48 | /** Sets the value of <code>bit</code> to one. */ | |
| 49 | 7982 |
public final void set(int bit) { |
| 50 | 7982 | bits[bit >> 3] |= 1 << (bit & 7); |
| 51 | 7982 | count = -1; |
| 52 | } | |
| 53 | ||
| 54 | /** Sets the value of <code>bit</code> to zero. */ | |
| 55 | 2256 |
public final void clear(int bit) { |
| 56 | 2256 | bits[bit >> 3] &= ~(1 << (bit & 7)); |
| 57 | 2256 | count = -1; |
| 58 | } | |
| 59 | ||
| 60 | /** Returns <code>true</code> if <code>bit</code> is one and | |
| 61 | <code>false</code> if it is zero. */ | |
| 62 | 2098140 |
public final boolean get(int bit) { |
| 63 | 2098140 | return (bits[bit >> 3] & (1 << (bit & 7))) != 0; |
| 64 | } | |
| 65 | ||
| 66 | /** Returns the number of bits in this vector. This is also one greater than | |
| 67 | the number of the largest valid bit number. */ | |
| 68 | 1019369 |
public final int size() { |
| 69 | 1019369 | return size; |
| 70 | } | |
| 71 | ||
| 72 | /** Returns the total number of one bits in this vector. This is efficiently | |
| 73 | computed and cached, so that, if the vector is not changed, no | |
| 74 | recomputation is done for repeated calls. */ | |
| 75 | 10825 |
public final int count() { |
| 76 | // if the vector has been modified | |
| 77 | 10825 | if (count == -1) { |
| 78 | 5511 | int c = 0; |
| 79 | 5511 | int end = bits.length; |
| 80 | 517505 | for (int i = 0; i < end; i++) |
| 81 | 511994 | c += BYTE_COUNTS[bits[i] & 0xFF]; // sum bits per byte |
| 82 | 5511 | count = c; |
| 83 | } | |
| 84 | 10825 | return count; |
| 85 | } | |
| 86 | ||
| 87 | private static final byte[] BYTE_COUNTS = { // table of bits/byte | |
| 88 | 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, | |
| 89 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, | |
| 90 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, | |
| 91 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | |
| 92 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, | |
| 93 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | |
| 94 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | |
| 95 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, | |
| 96 | 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, | |
| 97 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | |
| 98 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | |
| 99 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, | |
| 100 | 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | |
| 101 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, | |
| 102 | 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, | |
| 103 | 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 | |
| 104 | }; | |
| 105 | ||
| 106 | ||
| 107 | /** Writes this vector to the file <code>name</code> in Directory | |
| 108 | <code>d</code>, in a format that can be read by the constructor {@link | |
| 109 | #BitVector(Directory, String)}. */ | |
| 110 | 2113 |
public final void write(Directory d, String name) throws IOException { |
| 111 | 2113 | IndexOutput output = d.createOutput(name); |
| 112 | 2113 | try { |
| 113 | 2113 | output.writeInt(size()); // write size |
| 114 | 2113 | output.writeInt(count()); // write count |
| 115 | 2113 | output.writeBytes(bits, bits.length); // write bits |
| 116 | } finally { | |
| 117 | 2113 | output.close(); |
| 118 | } | |
| 119 | } | |
| 120 | ||
| 121 | /** Constructs a bit vector from the file <code>name</code> in Directory | |
| 122 | <code>d</code>, as written by the {@link #write} method. | |
| 123 | ||