[GitHub] [commons-collections] aherbert commented on a diff in pull request #317: moved IndexFilter to its own file.
aherbert commented on code in PR #317: URL: https://github.com/apache/commons-collections/pull/317#discussion_r914529367 ## src/main/java/org/apache/commons/collections4/bloomfilter/IndexFilter.java: ## @@ -0,0 +1,134 @@ +/* + * 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.function.IntPredicate; + +/** + * A convenience class for Hasher implementations to filter out duplicate indices. + * + * If the index is negative the behavior is not defined. + * + * This is conceptually a unique filter implemented as a {@code IntPredicate}. + * @since 4.5 + */ +public final class IndexFilter implements IntPredicate { +private final IntPredicate tracker; +private final int size; +private final IntPredicate consumer; + +/** + * Creates an instance optimized for the specified shape. + * @param shape The shape that is being generated. + * @param consumer The consumer to accept the values. + * @return an IndexFilter optimized for the specified shape. + */ +public static IndexFilter create(Shape shape, IntPredicate consumer) { Review Comment: I do not think this matters. The current choice is an optimisation is based on memory usage. It could be changed in the future, for example based on a JMH benchmark test for performance. All that matters is that the test code exercises all paths and the returned predicate functions as expected. -- 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: issues-unsubscr...@commons.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[GitHub] [commons-collections] aherbert commented on a diff in pull request #317: moved IndexFilter to its own file.
aherbert commented on code in PR #317: URL: https://github.com/apache/commons-collections/pull/317#discussion_r914478848 ## src/main/java/org/apache/commons/collections4/bloomfilter/IndexFilter.java: ## @@ -0,0 +1,134 @@ +/* + * 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.function.IntPredicate; + +/** + * A convenience class for Hasher implementations to filter out duplicate indices. + * + * If the index is negative the behavior is not defined. + * + * This is conceptually a unique filter implemented as a {@code IntPredicate}. + * @since 4.5 + */ +public final class IndexFilter implements IntPredicate { +private final IntPredicate tracker; +private final int size; +private final IntPredicate consumer; + +/** + * Creates an instance optimized for the specified shape. + * @param shape The shape that is being generated. + * @param consumer The consumer to accept the values. + * @return an IndexFilter optimized for the specified shape. + */ +public static IndexFilter create(Shape shape, IntPredicate consumer) { Review Comment: I do not think this needs to return an IndexFilter. It is more flexible for the implementation to return an `IntPredicate`: ```Java public final class IndexFilter /* not required - implements IntPredicate */ { public static IntPredicate create(Shape shape, IntPredicate consumer) { return new IndexFilter(shape, consumer)::test; } ``` All the documentation from the `test` method can be moved to the static constructor method. -- 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: issues-unsubscr...@commons.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org