-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
COLLECTIONS-844 - allow counting Bloom filters with cell size other than Integer.SIZE #406
Changes from 9 commits
eccfd03
837a8ff
7a9f9c2
afd0057
ec6360c
e6807e0
8a9b193
66d45ba
1ea112e
27e4119
f7e4be0
06051a5
257d8a9
1c6a3f1
0e404bd
8c0c182
94e5581
25143a5
e5a2b45
a197d2e
12ae0e3
aa8f214
0df5351
f1e159b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these changes are not related to this PR. Please revert. They can be considered separately. By chaining predicates using |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,9 +27,9 @@ | |
* @since 4.5 | ||
*/ | ||
public final class IndexFilter { | ||
|
||
// do not instantiate. | ||
private IndexFilter() {} | ||
private final IntPredicate tracker; | ||
private final int size; | ||
private final IntPredicate consumer; | ||
|
||
/** | ||
* Creates an instance optimized for the specified shape. | ||
|
@@ -38,20 +38,44 @@ private IndexFilter() {} | |
* @return an IndexFilter optimized for the specified shape. | ||
*/ | ||
public static IntPredicate create(final Shape shape, final IntPredicate consumer) { | ||
int size = shape.getNumberOfBits(); | ||
IntPredicate result = number -> { | ||
if (number >= size) { | ||
throw new IndexOutOfBoundsException(String.format("number too large %d >= %d", number, size)); | ||
} | ||
return true; | ||
}; | ||
return new IndexFilter(shape, consumer)::test; | ||
} | ||
|
||
/** | ||
* Creates an instance optimized for the specified shape. | ||
* @param shape The shape that is being generated. | ||
* @param consumer The consumer to accept the values. | ||
*/ | ||
private IndexFilter(final Shape shape, final IntPredicate consumer) { | ||
this.size = shape.getNumberOfBits(); | ||
this.consumer = consumer; | ||
if (BitMap.numberOfBitMaps(shape.getNumberOfBits()) * Long.BYTES < (long) shape.getNumberOfHashFunctions() | ||
* Integer.BYTES) { | ||
result = result.and(new BitMapTracker(shape).negate()); | ||
this.tracker = new BitMapTracker(shape); | ||
} else { | ||
result = result.and(new ArrayTracker(shape).negate()); | ||
this.tracker = new ArrayTracker(shape); | ||
} | ||
} | ||
|
||
/** | ||
* Test if the number should be processed by the {@code consumer}. | ||
* | ||
* <p>If the number has <em>not</em> been seen before it is passed to the {@code consumer} and the result returned. | ||
* If the number has been seen before the {@code consumer} is not called and {@code true} returned.</p> | ||
* | ||
* <p><em>If the input is not in the range [0,size) an IndexOutOfBoundsException exception is thrown.</em></p> | ||
* | ||
* @param number the number to check. | ||
* @return {@code true} if processing should continue, {@code false} otherwise. | ||
*/ | ||
public boolean test(final int number) { | ||
if (number >= size) { | ||
throw new IndexOutOfBoundsException(String.format("number too large %d >= %d", number, size)); | ||
} | ||
if (tracker.test(number)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You reverted the IndexFilter file but left this change. I think the statements are identical. Since the plan is to replace this with a separate change to the IndexFilter then can you revert this too. The IndexFilter should be unchanged by this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change fixes code coverage check. In the original case there are 4 branches, one of which can not be tested. In this case there are only 3 and the code coverage report shows 100% coverage for the Bloomfilter code. |
||
return consumer.test(number); | ||
} | ||
return result.or(consumer); | ||
return true; | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.commons.collections4.bloomfilter; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* Provides functions to assist in IndexProducer creation and manipulation. | ||
* @see IndexProducer | ||
*/ | ||
public class IndexUtils { | ||
Claudenw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* The maximum array size for the methods in this class. | ||
*/ | ||
public static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8; | ||
Claudenw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// do not instantiate | ||
private IndexUtils() {} | ||
|
||
/** | ||
* Ensure the array can add an element at the specified index. | ||
* @param array the array to check. | ||
* @param index the index to add at. | ||
* @return the array or a newly allocated copy of the array. | ||
*/ | ||
static int[] ensureCapacityForAdd(int[] array, int index) { | ||
if (index >= array.length) { | ||
return Arrays.copyOf(array, (int) Math.min(IndexUtils.MAX_ARRAY_SIZE, Math.max( array.length * 2L, index+1))); | ||
Claudenw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return array; | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file has lost the git history from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Every action I tried left github with delete and new. Local git showed renamed during commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file has lost the git history from
BitCountProducer
. It is showing as a new file and the old interface as deleted.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be an issue with github display local git showed that it was renamed during commit.