-
Notifications
You must be signed in to change notification settings - Fork 176
chore: convert indexers to internal iteration #2041
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull request overview
This pull request converts the indexer's external iteration pattern (using UniqueRandomSequence.pick() and remove()) to an internal iteration pattern using the standard Java Iterator interface. This refactoring prepares the codebase for implementing complex filtering required by the containingAnyOf() functionality.
Changes:
- Replaced
UniqueRandomSequenceinterface and its implementations withUniqueRandomIteratorimplementing the standardIteratorinterface - Updated all indexers to provide
randomIterator()methods instead of requiring external access patterns - Moved iterator implementations from
neighborhood.stream.enumerating.commontobavet.common.indexpackage - Simplified the API by removing
ElementAccessorabstraction layers (ListBasedElementAccessorandIndexerBasedElementAccessor)
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| DefaultUniqueRandomSequenceTest.java | Deleted - replaced with reduced test coverage in DefaultUniqueRandomIteratorTest.java |
| SelectionProbabilityTest.java | Moved to bavet.common.index package and updated to use new iterator API |
| FilteredUniqueRandomIteratorTest.java | Moved and renamed from FilteredUniqueRandomSequenceTest.java, updated for iterator pattern |
| DefaultUniqueRandomIteratorTest.java | New test file with basic iterator tests, significantly reduced coverage compared to original |
| UniLeftDatasetInstance.java | Updated parameter name from rightSequenceStoreIndex to rightIteratorStoreIndex |
| UniLeftDataset.java | Updated parameter name to match instance class |
| LeftTerminalUniEnumeratingStream.java | Refactored to inline store index reservations |
| ListBasedElementAccessor.java | Deleted - no longer needed with direct iterator access |
| IndexerBasedElementAccessor.java | Deleted - no longer needed with direct iterator access |
| FilteredUniqueRandomSequence.java | Deleted - replaced by FilteredUniqueRandomIterator |
| AbstractRightDatasetInstance.java | Changed from building sequences to returning iterators directly |
| AbstractLeftDatasetInstance.java | Simplified by removing UnwrappingIterator and using direct iterator access |
| BiRandomMoveIterator.java | Updated to use iterator pattern instead of sequence pattern |
| UniqueRandomIterator.java | New interface replacing UniqueRandomSequence, implementing standard Iterator |
| RandomAccessIndexerBackend.java | Added randomIterator methods returning new iterator types |
| LinkedListIndexerBackend.java | Added randomIterator methods that throw UnsupportedOperationException |
| Indexer.java | Added randomIterator method signatures to interface |
| FilteredUniqueRandomIterator.java | New implementation of filtered random iteration using Iterator pattern |
| EqualIndexer.java | Implemented randomIterator methods delegating to downstream indexers |
| DefaultUniqueRandomIterator.java | New implementation replacing DefaultUniqueRandomSequence with Iterator pattern |
| ContainingIndexer.java | Implemented randomIterator methods delegating to downstream indexers |
| ContainingAnyOfIndexer.java | Added randomIterator methods throwing UnsupportedOperationException |
| ContainedInIndexer.java | Implemented randomIterator methods with iterator function abstraction |
| ComparisonIndexer.java | Implemented randomIterator methods with support for single and multiple indexers |
Comments suppressed due to low confidence (1)
core/src/main/java/ai/timefold/solver/core/impl/bavet/common/index/UniqueRandomIterator.java:55
- The javadoc for the
remove()method is misleading. It states "Removes a random element in the underlying list which has not already been removed." However, this is standard Iterator.remove() behavior - it removes the element that was most recently returned bynext(), not a random element. The documentation should clarify that it removes the last element returned bynext(), consistent with the standard Iterator contract.
...st/java/ai/timefold/solver/core/impl/bavet/common/index/DefaultUniqueRandomIteratorTest.java
Outdated
Show resolved
Hide resolved
...st/java/ai/timefold/solver/core/impl/bavet/common/index/DefaultUniqueRandomIteratorTest.java
Show resolved
Hide resolved
core/src/main/java/ai/timefold/solver/core/impl/bavet/common/index/ContainingAnyOfIndexer.java
Outdated
Show resolved
Hide resolved
|


This will allow complex filtering that will be necessary to make
containingAnyOf()work.