aherbert commented on code in PR #406:
URL:
https://github.com/apache/commons-collections/pull/406#discussion_r1278317579
##########
src/main/java/org/apache/commons/collections4/bloomfilter/IndexProducer.java:
##########
@@ -117,11 +118,64 @@ public boolean test(long word) {
* @return An int array of the data.
*/
default int[] asIndexArray() {
- final BitSet result = new BitSet();
+ class Indices {
+ private int[] data = new int[32];
+ private int size;
+
+ boolean add(final int index) {
+ if (size == data.length) {
+ // This will throw an out-of-memory error if there are too
many bits.
+ // Since bits are addressed using 32-bit signed integer
indices
+ // the maximum length should be ~2^31 / 2^6 = ~2^25.
Review Comment:
This is wrong. You are not using the int[] as a bitmap. You are using it to
store indices. So you can get out of memory. However at some point you will not
be able to return the array if it needs more than the max capacity of an array.
A larger limit is:
```java
data = Arrays.copyOf(data, (int) Math.min(MAX_ARRAY_SIZE, size * 2L);
```
with MAX_ARRAY_SIZE something big. Previous versions of the JDK
java.util.ArrayList use Integer.MAX_VALUE - 8.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]